Skip to content

GDV373/Python_Battle_Ship_Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Battle Ship Game

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.

Summary

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.

  1. How to Play
  2. Features
  3. Features Left to Implement
  4. Data Model
  5. Testing
  6. Bugs
  7. Deployment
  8. Acknowledgements

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.

Existing features

  • Random board generation
    • Ships are randomly placed on the board by the computer so that the player cannot see where they are.

Screenshot of herokus error

  • 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.

Screenshot of herokus error

  • Able to reply the game without runnning the script again.

Screenshot of herokus error

  • 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.

Screenshot of herokus error

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

Screenshot of herokus error

Currently Heroku is not working propperly please follow the solution below to run the python game on a python web browser compiler

  1. copy the raw code from git link here > Click Here
  2. Open the website compiler by clicking this link > Click Here
  3. Paste the raw code into the main.py area on the left side.
  4. 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors