Battle boats is a turn based strategy game where players eliminate their opponents fleet of boats by ‘firing’ at a location on a grid in an attempt to sink them. The first player to sink all of their opponents’ battle boats is declared the winner.
Each player has two eight by eight grids. One grid is used for their own battle boats and the other is used to record any hits or misses placed on their opponents. At the beginning of the game, players decide where they wish to place their fleet of five battle boats.
During game play, players take it in turns to fire at a location on their opponent’s board. They do this by stating the coordinates for their target. If a player hits their opponent's boat then this is recorded as a hit. If they miss then this is recorded as a miss.
The game ends when a player's fleet of boats have been sunk. The winner is the player with boats remaining at the end of the game.
- From the main menu:
- A settings menu with formatting options:
- Display the two grids next to each other or one above the other
- Display gridlines or not
- New game
- Ask for the name
- If the game already exists ask whether to:
- Overwrite the save
- Continue the save
- Cancel and return to the main menu
- Allow the user to place ships
- Place ships randomly on the computer grid
- Start playing the game
- Continue
- Prompt for game name
- Load game and continue
- Quit
- When playing the game:
- Display both the computer and player boards
- Allow the player to navigate the board with arrow keys
- When the player presses space, they should fire at the tile the cursor is on if they have not done so already, and the computer should then play
- If there are boats longer than 1 tile, the computer should look for any partly sunk boats and fire adjacent to them
The project is split across multiple files for organisation:
- Program.cs - Main logic and sequencing
- Board.cs - Classes for managing game boards
- Mask struct: Wrapper around a long that uses each bit to represent one cell of a board
- Board class: Class that stores the state of a board including the layout of each ship and what tiles have been hit
- Input.cs - Functions and classes for managing input
- Static Input class
- IntOption function: Ask user for an option from 1 to a specified maximum
- GridInput class: Display a grid and allow the user to move around it with arrow keys
- Static Input class
- Game.cs - Global settings and attributes
- string file
- Board player, computer
- Static class Settings
- Text.cs - Text and templates that will be displayed
See code in repository
Overall, I think that the project was a success, and the overall result is a functional game that is mostly stable and intuitive.
If I was doing this again, however, I would change certain things:
- While I attempted to keep my code well organised, by the end it was somewhat messy and not structured in a consistent manner. If making the project again I would plan out the structure in more detail first before actually writing it
- I did not comment my code until it was finished so I had to do it all in one go at the end. If doing this again, I would try to write comments as I go
- Testing my code was very manual and time-consuming, another time I would set up automated testing where possible