BattleShip Game using Atmel Mega32
For our final project, we decided to create the classic game of Battleship that was displayed on a TV and controlled by keypad inputs. We both enjoyed playing the board game when we were young and we occasionally would do battle against each other online while at university. So we thought, why not take what we both love doing and apply it to a final project? So we set forth in creating the game of battleship, and although there were many roadblocks along the way, including running out of SRAM (grrrr), we thoroughly enjoyed creating the game of Battleship and we hope you enjoy it as well. BOMBS AWAY!!!!
1. Press the # sign to advance to the Select Level Screen
2. At this point you can choose what difficulty level you want your computer opponent to play at. After deciding on a level, press the corresponding number to move on.
3. You will see a flashing C on the grid position (0,0). This is the starting position of the carrier battleship. By pressing a 2 to move up, a 4 to move left, a 6 to move right, and an 8 to move right, you can move the starting position of the battleship around the grid as you please. After you are satisfied with the starting position of the battleship, press 1 to place the ship vertically downward or press 0 to place the ship horizontally to the right.
4. You will now see a flashing D on top of the digital representation of the carrier battleship. This is the starting position for the destroyer battleship. Of course you cant place the destroyer on top of the carrier so you can once again move the flashing D around to the grid position you desire. Continue allocating the rest of the battleships in the same way.
5. Once you have allocated the patrol boat, press the # sign to begin the game.
6. You will now be taken to the computer opponents grid. Of course right now it is blank because you cannot see where he allocated his ships but that will soon change.
7. The grid rows and columns are numbered 0 to 9. Pick a coordinate you would like to shoot at and input it onto the keypad. For example, you may want to shoot at grid position (3,8). Once you input a coordinate, an H will appear if you have hit one of his ships or an X will appear if you have missed his ship.
8. The game will then switch back to your grid and the computer will take a shot at your ships. Again, an H or X will display on your grid depending on the outcome of the shot and the game will switch back to the computers grid.
9. Once again pick a grid position to shoot at and enter it into the keypad. If you happen to sink one of the computers ships or the computer sinks one of your ships, a set of Ks will appear on the grid that indicate that the entire ship has been hit and is now sunk. When you see this, you know that you have sunk the particular ship you had been firing at and you no longer need to shoot at it.
10. Once all the ships have been sunk on one of the grids, you will be taken to a Game Over screen which informs you who won the game of battleship. You also have the option of playing again if you want another chance to beat the computer.
11. Have Fun!!!
Here are the types of ships and the number of hits required to sink each one:
|Ship||Ship Name||Number of Hits|
Logical Structure :
The details of our project are as follows. The game starts by displaying the introduction page, has some background music, the name of the game, and the designers of the game. By pressing the # key on the keypad, the player can advance to the next screen. We have some music playing in the background that is continued throughout the whole game.
On this next screen, the player is able to select the difficulty level of the game. The two levels of our game are Easy and Difficult. In easy mode, the computer opponent just fires at a random pattern throughout the game until the game is over. In difficult mode, the computer once again fires randomly but once it hits one of the players ship, we have an algorithm that will continue to fire around the hit area until the ship is sunk. This makes it much harder for the player to win the game.
After choosing the level, you are brought to a 10×10 grid. This is the players grid where he can allocate the position of his ships. In the top left hand corner there is flashing C to indicate that he is about to allocate his carrier. The player is able to move the letter C in all 4 directions until he is satisfied with the beginning position of his carrier. Once he decides on an initial starting position, he can press 0 if he wants to place the carrier horizontally along the grid or he can press 1 if he wants to place the carrier vertically on the grid. After deciding on a direction, a digital image of the carrier will be placed onto the grid and a flashing D will appear on the carrier that represents the destroyer. Once again the player can move the D around the grid to a position where he wants to place it. This continues until all the battleships have been placed on the grid. Of course we have made our game so that all ships have to fit on the grid and no ships can overlap each other during allocation. Once all the ships have been allocated on the players grid, the user hits the # sign once again to start playing the game.
The next screen is a blank 10×10 grid that belongs to the computer opponent. The word Computer is written along the right side of the grid to let the player know which grid is on the TV screen at the present time. At this point, the player is able to input the coordinates, row and then column, that he wants to shoot at with the rows and columns numbered 0-9. The players inputs into the keypad are confirmed through the LED representation of the number in binary. After entering in the coordinate, an H will appear at that grid position if the player has HIT one of the computers ships and an X will appear if you have missed the computers ships. After about 2 seconds, the screen will switch back to the players grid showing where he allocated all his ships. The computer will then take a shot at the players ships and an H or X will once again indicate hit or miss. After another 2 seconds, the screen switches back to the computer grid where the player gets another chance at hitting the computers ships. This pattern continues until either the player or the computer has sunk all of their opponents ships.
- Once someone has sunken all of their opponents ships, we go to a Game Over screen which displays who won the game of Battleship and has the distinction of being the best naval commander on the seven seaswell at least until the next game of Battleship is played. By hitting the # sign, the player will be able to go back to the introduction page to play the game again if he desires.
- Digital Design of Battleships :
In order to display a picture representation of the battleships, we had to alter the binary bitmap representation of images given to us by Professor Land. We changed some of his functions that called the bitmap and we created our own bitmap, which drew out the specific pieces for the battleships. For example, the carrier contained five pieces of the bitmap, which was made of 1s and 0s. We had to fill in the gaps between the pieces of the ship with a separate bitmap that served as filler.
For more detail: BattleShip Game
Leave a Comment
You must be logged in to post a comment.