Battleships is a game of logic, with players attempting to sink each others fleet by guessing co-ordinates. This version uses a a board generated using Python lists and incorporates a logic engine to allow the computer to fire back at the user.
(Developer: Stuart Wall)
- Project Goals
- User Experience
- Technical Design
- Technologies Used
- Features
- Testing
- Bugs
- Deployment
- Credits
- Acknowledgments
The project goal is to create a logic game using Python.
The application user wants to play a logic game.
The Battleships game is played on grids on which each player's fleet of battleships are marked. The locations of the fleets are concealed from the other player. Players call shots at the other player's ships, and the objective of the game is to destroy the opposing player's fleet. The application provides a working battleships game for a single user to play against the computer.
- Younger users who like playing games.
- Users who are looking for a game to pass time on during a break.
- Older users who are looking for a logic challenge.
- To create a personal username.
- To be able to return to the game with my username and password.
- To have an immersive experience.
- To have real-time feedback when playing the game.
- To be able to play the game against a computer opponent.
- To be told when the game has been won or lost.
- To be able to easily replay the game if wanted.
-
The data stored in the Google Spreadsheet is a combination of a username and password entered by the user on the login page.
-
A new user will enter their choice of username and password which will be stored in the spreadsheet 'user_data_sheet' in the worksheet 'username'. Their password will be stored in the same spreadsheet but in the 'password' worksheet.
-
A returning user will type in their username, the function will check the 'username' worksheet for a matching value and return a welcome message if true. The user will be prompted for a password and the function will, once again, check the 'password' worksheet for a matching value. If the function returns both inputs then the user will be allowed to play the game.
-
If the returning user inputs do not match, the user will be taken to the start of the login function where they can try again or enter a new set of credentials.
- Python 3
- LucidChart
- Heroku
- Google Drive: Used as a cloud hosting platform for the spreadsheet.
- Google Spreadsheet: Used because Python does not have a built in library to store data in an external spreadsheet.
- pycodestyle: Used as a validation tool instead of pep8 online.
- gitHub
- Gitpod
- Git
- Shows a welcome message. User Stories covered: 3, 4
- Prompts a user to input a username and password.
- Returning users can have their credentials recoved from a spreadsheet. User Stories covered: 1,3
- Shows an ASCII art warship and logo. User Stories covered: 3
- Shows the generated game boards for the user and the computer. User Stories covered: 3, 4, 5
- Allows the user to input their guesses and feedsback the result.
- Shows the computer's guess. User Stories covered: 3, 4, 5
- Shows the end-of-game state to the user once a victory condition has been met.
- Allows user to retry the game or to quit the program. User Stories covered: 4, 6, 7
At the time of creation, the PEP8 online Python validation website was inoperative. To validate the code, a PEP8 validator that is built into the GitPod Workspace was used.
- Run the command 'pip3 install pycodestyle'. (Note that this extension may already be installed, in which case this command will do nothing.)
- In the workspace, press Ctrl+Shift+P (or Cmd+Shift+P on Mac).
- Type the word 'linter' into the search bar that appears.
- Click on 'Python: Select Linter' from the filtered results.
- Select 'pycodestyle' from the list.
- PEP8 errors will now be underlined in red, as well as being listed in the PROBLEMS tab beside the terminal.
There were no errors or warnings flagged in login.py. There were no errors or warnings flagged in test_login.py 15 yellow warnings were flagged in run.py. These are down to the symbol combinations used in the ASCII art and logo. These are printed direct to the console and not used in any functions.
- To create a personal username.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Welcome Screen. | Input 'Y' to set up a new profile. Enter username. | Accepts input and stores username to spreadsheet. | Working as implemented. |
- To be able to return to the game with my username and password.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Welcome Screen. | Input 'N' and type in username and password. | Accepts input and checks spreadseet for the input values. | Working as implemented. |
- To have an immersive experience.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Welcome Screen. | Input username. | Console prints message welcoming the user as Admiral. | Working as implemented. |
Main Screen. | Shows after user inputs username and password. | Console prints ASCII warship and game logo. | Working as implemented. |
Game Board. | Generates upon game start. | Generates a board similar to the board game. | Working as implemented. |
Game Inputs. | User inputs co-ordinates to fire on. | Feedback uses military terminology. | Working as implemented. |
- To have real-time feedback when playing the game.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Welcome Screen. | Input username and password. | Console feedsback messages to user. | Working as implemented. |
Game Board. | Generates at the start of the game and refreshes after every turn. | Game board is printed and updated with user and computer inputs after each turn. | Working as implemented. |
Game Inputs. | User inputs their choice of co-ordinates. Computer does the same. | Results are printed back to the user after each turn. | Working as implemented. |
- To be able to play the game against a computer opponent.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Game Board. | Generates at the start of the game and refreshes after every turn. | Game board is printed and updated with user and computer inputs after each turn. | Working as implemented. |
Game Inputs. | Computer generates a shot after the user has taken a turn. | Results are updated on the board and printed back to the user after each computer turn. | Working as implemented. |
- To be told when the game has been won or lost.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Game Inputs. | After a game over condition is met. | Game over condition is printed back to the user. | Working as implemented. |
Game Over. | After a game over condition is met. | Results are updated on the board and printed back to the user after each computer turn. | Working as implemented. |
- To be able to easily replay the game if wanted.
Feature | Action | Expected Result | Actual Result |
---|---|---|---|
Game Over. | After a game over condition is met. User inputs Y or N | Input of Y re-runs the game. Input of N exits the program. | Working as implemented. |
Bug | Fix |
---|---|
New and Old User functions activated twice. | Moved the function calls to the Login function if/elif statements. |
Missile counter decreased by two each round. | Seperated missile variable into two; one for the user and computer. |
Check Login function would not validate user input. | Changed syntax of the Login function if/elif statements. |
Use the following steps to deploy the poject to Heroku:
- Use the "pip freeze -> requiremnts.txt" command in the gitPod terminal; to save any libraries that need to be installed to the project files in Heroku.
- Login or create a Heroku account.
- Click the "New" button in the upper right corner and select "Create New App".
- Choose an app name and your region and click "Create App". Note: the app name must be unique.
- Go to the "Settings" tab, add the python build pack and then the node.js build pack. This is to ensure the project functions correctly with the Code Institute pre-installed template.
- Create a "Config VAR" with the 'CREDS' key and the enter the value of the creds.json file.
- Create a second "Config VAR" with the key of 'PORT' and value of '8000'
- Go to the "Deploy" tab and pick GitHub as a deployment method.
- Search for a repository to connect to.
- Click enable automatic deploys and then deploy branch.
- Wait for the app to build and then click on the "View" link.
You can fork the repository by following these steps:
- Go to the GitHub repository.
- Click on the Fork button in the upper right-hand corner.
You can clone the repository by following these steps:
- Go to the GitHub repository.
- Locate the Code button above the list of files and click it.
- Select if you prefer to clone using HTTPS, SSH, or Github CLI and click the copy button to copy the URL to your clipboard.
- Open Git Bash.
- Change the current working directory to the one where you want the cloned directory.
- Type git clone and paste the URL from the clipboard ($ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY).
- Press Enter to create your local clone.
- Code Institute Python lessons.
- Code Institute Love Sandwiches project.
- Knowledge Mavens https://www.youtube.com/watch?v=alJH_c9t4zw&t=673s
- Corey Schafer https://www.youtube.com/watch?v=6tNS--WetLI
I would like to take the opportunity to thank:
- My mentor Mo Shami for his feedback, advice, guidance and support.
- My beautiful wife, Megan, for her continued love and support.
- Jim, Sawyer, and the other fantasic members of Code Institute's community team.
- The great people of class June '22 for their ideas and humour.