This game is the single-player battleship game, we have made used of grids. Each ship occupies a number of consecutive squares on the grid, arranged either horizontally or vertically. The number of squares for each ship is determined by the type of ship. The ships cannot overlap (i.e., only one ship can occupy any given square in the grid). This grids consists of a minimumof 5 rows and maximum of 26 rows and A-Z columns of the battleship where you can destroy and sink the ships.
The game is a discovery game which players need to discover their opponents ship positions.
https://battleship-101.herokuapp.com/
- A grid size has been set to a minimum of 5 and maximum of 26
- Players can choose the grid size they want to play
- Players can also choose the number of bullets to be shot
- You can choose a row and column such as B5 to indicate where to shoot
- For every shot that hits or misses it will show up in the grid
- If all ships are unearthed before using up all bullets, you win else, you lose and it's game over!
- Define the pattern grid
- we defined a hidden grid of size 10
- we defined a guess grid of size 10
- we used a letter A-Z and numbers to form the grid
- The Create Ship Function
- from random we import randint
- we use the for loop function to create the number of our ships
- The ship row is the number [1-100]
- the ship column is the alphabet [A-Z]
- the randint randomly assigns values to the ship row and column
- the while loop function continues until the grid row and column is X
- The grid will get the values ‘X’ once the hidden pattern and guess pattern hits the same ship
- Define Print Grid
- the function print the column grid from A-J
- prints the row number ".|" symbol for each row on the grid
- Function for ship location
- this validates the row number and column
- return the function row less by 1 than the value provided and let_to_num[column]
- Function for counting ships
- the count is assigned 0
- for each row on the grid and each column in the row if the column ==’X’ the count increases by 1 and returns the count
- the function counts the number of ships hit and sunk.
- The run all function
- we called the function create_ship that creates the ship
- The print_grid (Guess_Pattern) creates the guess_pattern grid.
- if the guess_pattern == ‘-‘ then it prints “You have already guessed”.
- If the hidden patterns Hidden_Pattern[row][column] == ‘X’: then it prints ‘ Congratulations you have hit the battleship’
- If the count_hit_ships and the guess_pattern are exactly same i.e 5 then it will print “Congratulations you have sunk all the battleships”
- Once the turns value becomes zero the program will print “ Game over”.
I have manually tested this project by doing the following:
- I passed the codes through a PEP8 and confirmed there are no errors
- It gives valid input, strings and float numbers are not allowed.
- Tested in my local terminal and the Code Institute Heroku terminal
- At the point of deplomyent to Heroku, I could not connet to git connect, i was getting 'internal servive error'. However i was able to deploy through git CLI
- PEP8
- No errors were returned from pep8online.com
- run.py
- Heroku
- Steps for Deployment
- Create a new app
- Set my config vars to store my sensitive data
- Set the buildbacks to Python and NodeJS in that order
- Click on deploy
- walkthrough project
- Sample Readme from Ultimate Battleship
- https://github.com/ArjanCodes/2022-coderoast-battleship/blob/main/after.py
- https://www.tutorialspoint.com/online_python_formatter.htm
- Tutor support