This program plays a classic game of "Battleship" where you place your five ships of varying sizes into your area of the ocean on a 10 x 10 grid. You then take turns with your opponent firing shots at a grid coordinate in an attempt to sink all five of your opponents ships before they sink yours.
Using Sound Effects
This game has the option to add sound effects to your game. Using sound effects will take a little extra preparation before you upload your game software.
If you do not plan to use sound effects then you need to make a small change in the software before uploading. Open the Battleship.ino program using the Arduino IDE. On the second tab battleship.h at approximately line 22 you will see the following define statement.
#define USE_AUDIO true
Edit that line to read false
and save and upload the program. Be sure to change the IS_PLAYER_1
value on the front page before uploading to your second device. See the "Loading Sound Effects" section of the "Assembly and Setup" page above for instructions on how to load the sound effects files onto your device.
Compile and upload the game according to the procedures outlined in the "Demonstration Games" page setting the IS_PLAYER_1
flag appropriately.
When you power on your device or press reset or upload the code initially you will see a splash screen followed by a menu that looks like the image below.
This will give you 3 options for placing your ships. The first option is the computer will randomly place all five of your ships on the board for you. The second option allows you to manually place the ships at the location and orientation that you want. The third option is for debugging and demonstration purposes. It places the ships at a fixed location and pre-sinks four of them so that you can fire just a couple of shots to end the game. Here is an animation showing how the random placement works. Notice it takes several tries of random locations to find a legal position.
Manual Ship Placement
If you choose the manual option on the opening menu, you will place each of your five ships yourself starting with the 5 square carrier, all the way down to the 2 square patrol boat. The ship will appear in a horizontal orientation at the first open square on the grid. You can press the "B" button and the ship will toggle back and forth between horizontal and vertical orientation. It will pivot around the small yellow dot which serves as your cursor. Use the joystick to position the ship where you want it and then press "Select" to place it. It will then call up the next ship until you have all 5 placed.
If you attempt to place a ship with part of it off the edge of the board or overlapping another previously placed ship it will not let you. The image below shows placement of the five slot Carrier in a horizontal or vertical position. Followed by an attempt to place the Battleship in the illegal position off the edge of the board.
Game Play
Only after you have placed your ships using either automatic or manual procedures will your device begin transmitting an offer of a game. If there is no response within a couple of seconds it will go into seeking mode seeking an invitation from the other device. As always, the offering player will press a button to initiate the coin toss and both devices will be informed of the results.
When it's your turn you will see a 10 x 10 grid with a green background. This is your "radar" screen. Using the joystick you move a yellow dot cursor around the screen and press "Select" to tell it where to fire at your enemy ships.
The game will not allow you to waste a turn by firing at the same location more than once. If your shot was a hit, the dot will turn red. If the shot missed, it will turn white.
Any time during your move you can press the "B" button to toggle the sound effects off or on. The image below shows the radar screen with the yellow cursor firing. The image on the right shows 2 misses in white and two red hits.
When it is your opponent's turn, your display will switch to a blue grid with your ships on it. This is the "sea" where your ships reside. When your opponent makes a move, if it hits one of your ships, that location will be marked with a red dot. If it's a miss, it will appear as a white dot in the sea. When all of the spots of a particular ship have been hit, the ship is sunk and it will turn completely red.
The five NeoPixels on your device indicate how many enemy ships you have sunk. Initially you have 5 green lights and they will turn red one by one when you sink an enemy ship.
When you hit a ship you will not know which ship you hit until you have completely destroyed it. It will then inform you what type of ship you sank. The images below show a submarine with 2 red hits and then after the third hit it turns completely red indicating it is sunk.
Play continues until one player loses all five ships. You can also press the "Start" button to resign your game. When the game is over you will be prompted to press "Start" to start a new game. The images below show a winning game and a game which has been forfeited as well as the restart message.
Text editor powered by tinymce.