A remake of the popular pen and paper game Battleships in the command line. Boards are printed out using keyboard characters in a matrix. It uses the Google Sheets API to access a Google sheet and keep scores for players.
-
-
- As a First Time Visitor, I want to understand clearly the game mechanics.
- As a First Time Visitor, I want to understand the game controls.
- As a First Time Visitor, I want to be able keep track of score.
-
- As a Returning Visitor, see my previous scores and play again.
-
-
The game is entirely command line based and so the styling is restricted to the
terminal it runs on.
-
Score board
- Ability to add player name to keep track of score by means of a cloud based database.
The score board through game commandsscores
andmyscores
.
- The player enters their name and password.
- Password must match if it was a previously used name.
- A new entry is made in the Google sheets database if the name has not been used before.
- Ability to add player name to keep track of score by means of a cloud based database.
-
Choose board size and ship number
- At the beginning of the game the user is prompted to enter two numbers; The size of the board and the number of ships.
-
Coordinate based input
- Using the row and column, or X, Y the player can enter the coordinates to fire upon.
-
Play against the computer
- The player plays against the computer. Unique random coordinates are generated by the program and used to take a shot at the players board.
- The computers board is obscured so that you cannot see the ships.
-
Random ship placement
- After the board is created random coordinates are created and used to place the correct number of ships.
-
In Game Commands
- After the game starts instead of entering coordinates the player can enger 4 different commands
- "help" is used to print out the game instructions.
- "scores" is used to print out the score board.
- "myscores" is used to print out the players score history.
- "reset" is used to reset the game. The player is asked to confirm command first.
- "about" is used to learn more about the game mechanics if you are unfamiliar with Battleships.
as well as developer information.
- After the game starts instead of entering coordinates the player can enger 4 different commands
-
PvP
- A possible future feature might be to allow players to log into a
lobby and match up to play against each other.
- A possible future feature might be to allow players to log into a
-
Message Informing PLayer of New Best Win Streak
- At the end of the game if a new personal or overal best win streak is
achieved a victory message could displayed.
- At the end of the game if a new personal or overal best win streak is
-
Leagues
- Score boards could be seperated into different google sheets according to
boards size or ship number.
- Score boards could be seperated into different google sheets according to
- gspread:
- This library is used to access and update the the data in the spreadsheet.
- google-auth:
- google-auth is the Google authentication library for Python. This library
provides the ability to authenticate to Google APIs.
- google-auth is the Google authentication library for Python. This library
- copy:
- This library is used to make a deep copy of the the board matrix and not
just a reference to the location in memeory.
- This library is used to make a deep copy of the the board matrix and not
- math:
- The math library is used to implement
math.ceil()
to round up a number
in determining the game round number.
- The math library is used to implement
- time:
- time was used to create a delay between prints so that the user could see
the information as it was printed withtime.sleep(delay)
- time was used to create a delay between prints so that the user could see
- os:
- Here os was used so that it was possible to run the
clear
terminal
command from the program usingos.system()
- Here os was used so that it was possible to run the
- numpy:
- numpy was used to generate the random numbers needed for the random
coordinates and the random placement of the ships.
- numpy was used to generate the random numbers needed for the random
- pyfiglet:
- pyfiglet was used to generate the game logo graphic.
- getpass:
- getpass was used to conceal the password input by the user.
- Git
- Git was used for version control by utilizing the Gitpod terminal to commit
to Git and Push to GitHub.
- Git was used for version control by utilizing the Gitpod terminal to commit
- GitHub:
- GitHub is used to store the projects code after being pushed from Git.
- Heroku:
- Was used to host and deploy the game.
- Lucid:
- Was used to make the logic flow chart in this readme.
- Balsamiq:
- Was used to create the wireframe for the game.
- Google Sheets
- Google sheets was used as a simple database to store player
score history.
- Google sheets was used as a simple database to store player
-
- As a First Time Visitor, I want to understand clearly the game mechanics.
- When the game loads there are instructions on how to set up the game.
- When the game loads there are instructions on how to use game commands and in
particular there are 'help' and 'about' commands that give an even more detailed
discription of how to play the game. - A legend is provided through using the help command.
- As a First Time Visitor, I want to understand the game controls.
- The 'about' command will describe how the coordinates work.
- The introduction information and the 'help' command describe how to enter
coordinates. - Upon being prompted for input an example is given.
- As a First Time Visitor, I want to be able keep track of score.
- Every time a shot is fired 'Hit' or 'Miss' is printed and the
boards are labeled with whos turn it is at the top. The updated
boards are then printed and the other player takes their turn. - Each board has the number of hits taken displayed in each turn.
- At the end of the game the result is displayed and are recorded to the
database. - The user can type 'scores' at any time to see the top 5 best winning streaks
from past users.
- Every time a shot is fired 'Hit' or 'Miss' is printed and the
- As a First Time Visitor, I want to understand clearly the game mechanics.
-
- As a Returning Visitor, see my previous scores and play again.
- After setting the board size and ship number the user can log in using
their prviously set username and password and start a new game. - When the user logs in their entire score history can be accessed through
commands. - The user can type 'scores' at any time to see the top 5 best winning streaks
from past users. - The user can type 'myscores' at any time to see their score history.
- At the end of the game the results are recorded to the database.
- After setting the board size and ship number the user can log in using
- As a Returning Visitor, see my previous scores and play again.
-
Having split the code up into modules the run_game function needed to me accessible
in helpers but importing run.py into helpers caused a circular import error.- I decided to create a package with all the modules in it and only use
run.py to import and run run_game(). This gave the other functions access
to the run_game function.
- I decided to create a package with all the modules in it and only use
-
Entering zero or minus values gave unusual bugs like doind so for borad
size and ship number and then logging in the game would immediatly declare that you
lost the game and start a new one. -
Doing so during the game when entering coordinates would result in random
coordinates being fired upon.- For both of these bugs the solution was to add a check into the validate_input
function for zero or minus integers.
- For both of these bugs the solution was to add a check into the validate_input
- No remaining bugs found.
- Tested locally and on the Code Institute Heroku terminal.
- Test giving the program invalid input; strings, off board values, too many
ships for board size, board size too big, negative and zero values, no input. - Friends and family members were asked to play the game to point
out any bugs and/or user experience issues.
-
PEP8
Validations errors that were found consisted mainly of 'Trailing whitespace' errors
and 'line too long' errors and one "comparison to True should be 'if cond is True:' or 'if cond:'".White spaces were simply deleted. Line too long errors were solved mainly by
breaking up f stings and using parenthesis to enclose them, as well as editing
docstrings. The comparison error was solved by simply deleting '== True' as this
was redundant.All three files passed the PEP8 validator tests:
-
Vscode Pylint
An example of one resolved pylint error was:
"Sequence index is not an int, slice, or instance with index".This was resolved by converting the data type passed as index to type int.
All pylint errors were also resolved:
pylint
-
Local deployment was achieved with with Python from the console. The game was
developed on a Ubuntu OS and so was already installed. Steps are as follows:- Run
python3 run.py
in the terminal with root directory of the project.
- Run
-
Heroku Deployment:
- Create a new Heroku app.
- Set the build packs to
Python
andNodeJS
in that order. - Set Config Vars key value pairs for:
PORT
:8000
CREDS
:{CREDS Object}
where {CREDS Object} is from the credentials file dowoloaded from Google Cloud Platform.
- Enter
heroku login -i
command in the terminal with root directory of the project. - Enter Heroku username and password.
- Enter
git push --set-upstream https://git.heroku.com/battleships-ci-3.git main
to deploy. - Enter
git push --set-upstream https://github.com/RobTheThief/battleships-ci-3.git main
to reset upstream to github.
The live link can be found here - https://battleships-ci-3.herokuapp.com/
The Code Institute Heroku console was used to deploy the game.