top of page

PROJECT BATTLESHIP

Battleship is the first game I made using C++. It is a game that requires the players to shoot down all ships labelled as  'S' within 10 steps. So, players must plan and to shoot down all ships using as less turns as possible. For easier visualization the game has 2 boards, 1 is for the player only, another 1 is for stored the ships.

It is a simple game but it still has a few interesting features in the game.

1.   Randomize Orientation Of Ship

This snippet show the piece of code where the orientation of the a ship is determined.

Steps of Execution

 1. Check whether the orientation is greater or lesser than the map size or whether the position is occupied.

 2. It will go to the virtual map (where all the ships are stored) and generate the ships in vertical or horizontal orientation by randomizing an integer variable.

 

 

The snippet at the left shows the up and down movements of the player. There are left and right movements as well but for easier demo purposes I only show the up and down movements.

The logic in it would be:

The same logic applies to down, left and right movement.

If player press W (move up) {

       If the moving up does not move out of the map {

              move player up

       } else {

              dont move them

       }

       If the virtual map has ships at player's location {

              Kill the ships

       }

}

Due to the fact that, the game is a really simple game so, that's all I can show for interesting features. However, if you feel like having the source code and the executable file. Please click the "Download Game" button below.

That's all I have for this game. Hope you guys download and play the game. Stay tuned for more great games and have a great day.

2020 by Xynan Lee.

  • LinkedIn
  • Instagram - Black Circle
bottom of page