- ๐ป Deployed Site
- ๐ GitHub Repository
Try your hand at playing against a computer! Battleship is a Python command line game where a human can relax and play against a computer. A definite embarrassment save from losing against a mate!
- Project Goals
- User Experience
- Technical Design
- Technologies Used
- Features
- Testing
- Bugs
- Deployment
- Credits
- Acknowledgements
- The Battleship CLI game allows users to play against a computer
- The winner is saved to a Google Sheets file
- The five most recent winners can be viewed
- Be able to enter name to play and if wins, save to Google Sheet
- Be able to read rules of game
- Be able to view 5 most recent winners
- Create a game where users can relax and take a solitory moment
- Create a game that is easy and clear to user
- Create a game that gives feedback to user during gameplay
- People of all ages who enjoy games
- As a user, I want clear options from the main menu
- As a user, I want to see an option to read the rules for the game
- As a user, I want to be able to enter my name and see the personalised game messages throughout the game
- As a user, I want my name to be recorded if I win the game so that others would be able to see that I have won
- As a user, I want move feedback throughout the game so I know what is going on at all times
- As a site owner, I want the user to be able to select from the different options in the main menu
- As a site owner, I want the name to be saved to the Google Sheets and to be able to view them in the game
- As a site owner, I want data entry to be validated to show them how to correctly format the input
Click here for instructions to use
The Battleship CLI Game is a command line version of the famous Battleship game. The user plays against the computer.
On the main menu, the user is presented with an ASCII art rendering of the name 'Battleship'. Beneath that, there is a greeting and there are different options as part of the main menu. Operation: Input numeric values and press enter key.
- Play game - enter game play
- Read rules - prints out rules of game
- View winners - prints out five most recent winners saved in Google Sheet document
- Quit - quits program
With the Play Game option, the user is first instructed to enter their name. Operation: Enter anything and it will be saved as string.
A personalised message will then appear for them to take their turn. As part of their turn, they must enter suitable coordinates. Operation: Enter x,y coordinates like 2,3 for example. Hits and misses are displayed on board. Hits are shown as 'x' whereas misses are shown as '.'. Computer goes then.
When a players win, the message is shown on the screen and the name is saved to the Google Sheet. There is then a message to go back to the main menu Operation: Click any key and enter.
With the Read Rule option, the user is presented with the rules for Battleship. They are then given an option to go back to the main menu. Operation: Click any key and enter.
With the View Winners option, the user is presented with the five most recent winners. They are then given an option to go back to the main menu. Operation: Click any key and enter.
With the Quit option, the user exits the program with a goodbye message.
Please view the below flowchat, created with Lucid
This project makes use of Object Oriented Programming and user the following as part of this:
- Classes - classes were used for the game board, shot, battleship and player. The game board and battleship were the most indepth.
- Lists and dictionaries - lists and dictionaries were used to create the game boards and also to use and manipulate the data sent over by the Google Sheets API.
- Google Sheets API - Google Sheets API was used as a database to save all the people's names who have won the game before.
- Git - Used for version control.
- Heroku - Used for hosting the website on Heroku.
- Lucid - Used to draw flowcharts.
- Google Sheets - Used to store data outside of running the game.
- Google Cloud Platform - Used to manage permissions to Google Services such as Google Sheets.
- gspread - Used to make it easier to work with Google Sheets API.
- copy - Used to create two different objects in memory. This was used to create two different game board.
- random - Used to generate computer's coordinates.
- os - Used to clear terminal.
On the main menu, the user is presented with an ASCII art rendering of the name 'Battleship'. Beneath that, there is a greeting and there are different options as part of the main menu.
This screen covers the following user stories:
- As a user, I want clear options from the main menu
- As a user, I want to see an option to read the rules for the game
- As a site owner, I want the user to be able to select from the different options in the main menu
When playing the game, the user is first instructed to enter their name. A personalised message will then appear for them to take their turn. As part of their turn, they must enter suitable coordinates. The computer will then take its turn. When a players win, the message is shown on the screen and the name is saved to the Google Sheet. There is then a message to go back to the main menu
This screen covers the following user stories:
- As a user, I want to be able to enter my name and see the personalised game messages throughout the game
- As a user, I want move feedback throughout the game so I know what is going on at all times
- As a site owner, I want data entry to be validated to show them how to correctly format the input
When the user selects on the read rules option, the user is presented with the rules for Battleship. They are then given an option to go back to the main menu.
This screen covers the following user stories:
- As a user, I want to see an option to read the rules for the game
When the user clicks on view winners, they will see the five most recent winners.
This screen covers the following user stories:
- As a user, I want my name to be recorded if I win the game so that others would be able to see that I have won
- As a site owner, I want the name to be saved to the Google Sheets and to be able to view them in the game
The Python code was validated using PEP8 Validation Service. The code passed with 0 errors and 0 warnings.
- As a user, I want clear options from the main menu
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Main Menu | Select any of the options | User is presented with different options | Works as expected |
- As a user, I want to see an option to read the rules for the game
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Read Rules | Select from Main Menu | User is presented with the rules | Works as expected |
- As a user, I want to be able to enter my name and see the personalised game messages throughout the game
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Game Play | Select from Main Menu | After name entered, they will received personalised messages | Works as expected |
- As a user, I want my name to be recorded if I win the game so that others would be able to see that I have won
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
View Winners | Select from Main Menu | User is presented with different options | Works as expected |
- As a user, I want move feedback throughout the game so I know what is going on at all times
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Game Play | Select from Main Menu | User is presented with feedback | Works as expected |
- As a site owner, I want the user to be able to select from the different options in the main menu
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Main Menu | Select any of the options | User is presented with different options | Works as expected |
- As a site owner, I want the name to be saved to the Google Sheets and to be able to view them in the game
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
View Winners | Select from Main Menu | User is presented with five different name who are recorded winners | Works as expected |
- As a site owner, I want data entry to be validated to show them how to correctly format the input
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Game Play | Select from Main Menu | User is made to enter coordinates correctly | Works as expected |
Bug | Fix |
---|---|
Winning name is not updating until programme termination and re-run | I need to find another area for the function to be called |
This application has been deployed from Github using Heroku. Here's how:
- Create an account at heroku.com
- Create a new app, add app name and your region
- Click on create app
- Go to "Settings"
- Under Config Vars, add your sensitive data (creds.json for example)
- For this project, I set buildpacks to heroku/python and heroku/nodejs and in that order.
- You must then create a Config Var called PORT. Set this to 8000.
- Go to "Deploy" and at "Deployment method", click on "Connect to Github"
- Enter your repository name and click on it when it shows below
- Choose the branch you want to buid your app from
- If desired, click on "Enable Automatic Deploys", which keeps the app up to date with your Github repository
By forking this GitHub repository you are making a copy of the original to view or make changes without affecting the original. You can do this by following these steps...
- Log into your GitHub account and find the repository.
- Click 'Fork' (last button on the top right of the repository page).
- You will then have a copy of the repository in your own GitHub account.
- Log into your GitHub account and find the repository.
- Click on the 'Code' button (next to 'Add file').
- To clone the repository using HTTPS, under clone with HTTPS, copy the link.
- Then open Git Bash.
- Change the current working directory to where you want the cloned directory to be made.
- In your IDE's terminal type 'git clone' followed by the URL you copied.
- Press Enter.
- Your local clone will now be made.
- Code Institute - for git template IDE and heroku deployment instructions.
- Google - for gspread and APIS
- The following videos were used in the making of this project:
- To my mentor Mo Shami for his guidance, motivation and great resources.