Battleship

Battleship is the C++ implementation of the tabletop game with the same title, which I programmed during my last semester in the BTS.

The rules of the game are identical to those of the tabletop version. I created up to four different difficulties. The easy difficulty only selects random guesses, the intermediate will remember when it hit a target and will try to adjust it's guesses accordingly, while the two last difficulties will also try to guess where the smallest possible boat would not fit and will immediately discard those options from the get-go.

The final difficulty does not display the player board, forcing the players to remember their guesses. I also took the liberty to make explosive mines which are able to trigger other mines, making the game a bit more chaotic.

Before I started coding I needed to define the code's structure. Therefore, I implemented two UML diagrams to fully describe how the code should work, this allowed me to have a clear idea and avoid having to rewrite code when stumbling into a problem.

Challenges

The hardest part of this project was creating the two last difficulties, for this I needed to implement some design patterns such as the Visitor to allow them to take a peek at the player's smallest ship as well as its current status (how damaged), and choosing how to reorganize its choices.

What I learned

I think there is two valuable lessons that I learned during this project. The importance of starting production as soon as posible and to be well prepared and structured before starting coding.

In addition, the use of design patterns in a practical matter, instead of the standard in-class excersises/theory really opened my mind and has simplified the way I program for my current projects.

Try the game yourself

Exe File

Or download the whole project

Zip File