Skip to content

Humanslaughter/pp3-python

Repository files navigation

PP3 Python: Battleships

smartmockups_low19brg

Play Battleships

How to play:

  • The player enters a number between 1 to 8 for the row and a letter between A to H for the column.
  • "X" indicates a hit on the board, and a message displaying "a hit!" is shown when a ship is hit.
  • "*" indicates a miss on the board with a message displaying "missed!".
  • The game is over whenever the player or computer hits all 5 ships or there are no more turns left and the game is over.

Contents


Features

Existing Features

  • Play against a computer.
  • Random generation of ship placement for both the player and computer.
  • The ships are hidden until hit, which is indicated by an "X" on the board.
  • The board layout is 8x8 with 5 ships on each board and 30 turns.
  • You can only enter numbers between 1 and 8 as a row, only letters between A and H as a column, and you cannot leave any input fields empty. If you do, a message will display telling you the input is not valid and to enter a valid one instead.
  • Whenever the same combination of rows and columns is guessed multiple times, a message is displayed saying "You've guessed that already, try again!".
  • A scoring system that updates each time the player or computer hits a ship.
  • A result system that displays if it's a hit/miss, how many turns are left, who's the winner, or if it's a game over.
  • Option to restart or quit when the game is over.

Start 2 Skärmbild 2023-11-12 224530 Skärmbild 2023-11-12 224614 Skärmbild 2023-11-12 224522

Future Features

  • The player will be able to pick the ship's location and see the placement on the board while playing.
  • Different sizes of ships and boards, different difficulty modes (easy, medium, hard mode).
  • Add some colors to the design.
  • Multiplayer mode (player vs player).
  • Ability to quit the game during an active session.

Technologies Used

Languages

  • Python.

Testing

I have manually done these tests:

  • Passed the code through the PEP8 linter and confirmed that no problems or errors exist.
  • Added error handling on all inputs, to make sure no invalid inputs can be given without a warning.
  • Done tests in both my local terminal and the Code Institute Python terminal to ensure that each input and function works as it should. For example, when pressing enter or Q the game restarts or quits.

Validator Testing

Known Bugs & Issues

  • Sometimes it takes a second for it to load in everything at the start when you click the run program and it can seem like it has bugged out or something similar, not sure if it's something on my end or if it is the terminal itself. I mostly noticed it while using Dev Tools.
  • Sometimes when asking for a row/column and you've put those in it will yet again ask for a row and column. It doesn't happen very often and most of the time it's just one time and then it will go back to working normally again. There were one or two times when it got stuck in an endless loop asking for a row/column, but it fixed itself whenever I clicked 'run program' or refreshed the webpage.

Deployment

The project was deployed using Code Institute's Python Terminal on Heroku.

Heroku Deployment

Steps:

  1. Clone or Fork this repository pp3-python.
  2. Create and/or log in to your account on Heroku.com
  3. Click on 'Create new app' from your dashboard.
  4. Set the buildbacks to Python and NodeJS (in that exact order).
  5. Link the repository to the Heroku app.
  6. Click 'Deploy'.

How To Fork

Fork the repository:

  1. Log in/sign up to GitHub.
  2. Go to the repository for this project pp3-python.
  3. Click the 'Fork' button in the top right corner.

How To Clone

Clone the repository:

  1. Log in/sign up to GitHub.
  2. Go to the repository for this project pp3-python.
  3. Click the code button, select which one you want to clone with (HTTPS, SSH, or GitHub CLI), and copy the link shown.
  4. Open the terminal in a code editor and change the current working directory to a location of your choice to use for the cloned directory.
  5. Type 'git clone' in the terminal, paste the link that you copied in step 3 and then press enter.

Credits

Code