MATLAB Battleship Game
-
Set Up
The set-up portion of the game asks the user whether they would like to play two-player or single-player against the computer. Then, they can click spaces on the board to place ships. It checks that all of their ships fit within the spaces on the board. The same constraints are applied to the computer’s ships while those placements are hidden from the player.
-
2 Player Mode
With 2 players, ships on both boards are hidden from view during gameplay. Each player can select any space on the board, which will turn white if it is a miss and red if it is a hit. If it is a hit, their turn repeats. When ships are sunk, the player is notified and skull emojis appear on top of the ship. When either players’ ships are completely sunk, the other player wins.
-
Single Player Mode
In single player mode, only the computer’s ships are hidden from view. The computer chooses random points until it gets a hit. At which point, it chooses spaces around the hit until it gets another hit. It uses the coordinate similarities to determine if the ship is horizontal or vertical and continues in that direction until the ship is sunk. Then it goes back to choosing random points.