battleship-game

Battleship Game

This is a simple implemention to play the “Battleship Game” using only python.

Try out the game here. Battleship Game

Am i Responsive

Usage

How to play?

Game Rules

Layout/Data model

The Battleship Game is a simple game played on a board with a grid of cells. The objective of the game is to guess the location of the computer’s hidden battleship and sink it before the computer sinks the player’s battleship. The game board is represented by a 2D list, where each cell can be either “O” (for empty) or “X” (for a hit). The game starts with both the player and the computer’s board initialized with all “O” cells.

During each turn, the player enters a row and column to guess the location of the computer’s battleship. If the guess matches the location of the battleship, the player wins. Otherwise, the player’s guess is marked as a hit on the board with an “X”.

After the player’s turn, the computer makes a random guess by selecting a cell on the player’s board. If the guess matches the location of the player’s battleship, the computer wins. Otherwise, the computer’s guess is marked as a hit on the board with an “X”.

The game continues until either the player or the computer sinks the other’s battleship. At the end, the game also provides an option for the player to start a new game once the current game is over.

Features and Functions

Features

Adjust size

Gameboard

Finished game options

Enter a number Enter correct row

Future Improvements

Functions

Requirements

Testing

Bugs

I had one problem at the beginning of my coding, and it was that one of my lines were too long. After some research, I found out very fast how I could break up the code-line into two lines.

error message line too long python code too long

Remaining Bugs

Validator testing

The python code was tested from a pep8, and no errors could be found! PEP8 validator

Validator pep8 check

Deployment

Heroku linking/deployment

  1. Register at Heroku.com
  2. Create new app

Step 1

  1. Insert an app name - should be an unique name.

  2. Press Create app

Step 2

  1. Navigate to settings, and press Add buildpack

Step 3

  1. Press on Python, and save. Then you add a second buildpack, Nodejs.
    • It is important that the Python is above the Nodejs!

Step 4

  1. Above the buildpack, you can find Config Vars. Press it, and enter the KEY and VALUE
    • Those should be: KEY: Port, and VALUE: 8000.

Step 5

  1. Head over to Deploy at the top of the page.
  2. Press connect to github as a deployment method.

Step 6

  1. Search for your github repo (name of the project) and press connect.

Step 7

Github deployment

Deploy the project to Github

This project is deployed on Github pages, and on Heroku. Now when you have set-up the heroku link, it will deploy on Heroku when you deploy it on github.

To deploy something on Github, you follow these steps below.

  1. Navigate to Settings when you are on the project you want to deploy.

  2. Scroll all the way down to Pages on the left side, and press.

  3. There you have a header that’s called Build and deployment, and a second header that says Branch. Select the source where you created the repo. Its often called main or master, and press save.

Github deployment 1

Github deployment 2

  1. After some minutes, refresh the webpage, and the website will be shown as live on top of the page.
    • If you get a link to your project, everything is finished, and your project is live. (The link should look like this: https://pphilippersson6.github.io/battleship-game/).

Credits

Content