For my third Portfolio Project submitted as part of the Code Institute's Diploma in full-stack software development course, I created a board game, commonly known as battleship, called ' Battle ship game'. This is a Python terminal please follow the deployment content to run this game as currently Heroku is not working propperly.
- To view the repository on Github Click Here.
This interactive game provides users with an easy way to 'fire cannonballs' at a computer ‘enemy’s fleet of ships’. The game is based on the well-known board game ‘Battleship’, to learn more about this game Click Here.
In this version of the classic Battleship game, one randomly located ship is generated which the player cannot see.
The player must guess the coordinates of the hidden ships by choosing a row number and a column number. The player has 3 ‘cannonballs’ or turns to take in order to ‘hit’ the hidden ships.
Missis are indicted by ‘X’ or the game ends with a you win ASCII art if you hit and win.
If the player hits the computer’s ships they win the game. If they fire all of their cannonballs and fail to do so, they lose the game.
- Random board generation
- Ships are randomly placed on the board by the computer so that the player cannot see where they are.
-
Accepts player’s input.
-
Validates coordinates input by player.
-
Tells player if they input invalid values or the same values more than once without loosing the turn.
-
Tells player how many turns or 'cannon balls' they have left.
- Able to reply the game without runnning the script again.
- Add more ship for harder difficulty
- An option for the User to decide on the size of the game board
-
Functions are used on throughout the code to avoid repetitive code as much as possible.
-
The random Method was imported to generate the ships locations on the game board.
The code was built and tested using PyCharm using it to ensure there were no errors present, such as issues with indentation or whitespaces.
One bugs were encountered in developing this project:
-
Game would not loop more than one time because of missing line. This was later added after further testing of the game in the def new_game_exit_loop(): where it needed to run again if player was to play more than 2 games.
‘Bugged’ code:
def new_game_exit_loop():
# After Game options to Restart game or exit
new_game = (str(input("Do you want to play another game? press Y for yes or N for NO "))).upper()
while new_game not in ("Y", "N"):
print("Not a Valid Input!!")
new_game = (str(input("If you want to play another game press Y for yes or N for NO "))).upper()
if new_game == "Y":
game_code()
else:
print("Thanks for playing!")
exit()
debugged code:
def new_game_exit_loop():
# After Game options to Restart game or exit
new_game = (str(input("Do you want to play another game? press Y for yes or N for NO "))).upper()
while new_game not in ("Y", "N"):
print("Not a Valid Input!!")
new_game = (str(input("If you want to play another game press Y for yes or N for NO "))).upper()
if new_game == "Y":
game_code()
else:
print("Thanks for playing!")
exit()
Heroku
Currently Heroku is not working propperly please follow the solution below to run the python game on a python web browser compiler
- copy the raw code from git link here > Click Here
- Open the website compiler by clicking this link > Click Here
- Paste the raw code into the main.py area on the left side.
- Press the Blue Run button and play the game from the right side in the Shell area.
- My mentor, Brian Macharia, for the great support and ideas while doing the project.
Click Here to return to Contents




