20 likes | 228 Views
Assignment: BATTLESHIP. Before starting the assignment, read through the entire next slide. Then, you MUST plan your code in a Word document ( pseudocode ). Plan all of your for loops, while loops, if-and-or statements, array declarations, etc….
E N D
Assignment: BATTLESHIP • Before starting the assignment, read through the entire next slide. Then, you MUST plan your code in a Word document (pseudocode). • Plan all of your for loops, while loops, if-and-or statements, array declarations, etc…..
Create four 10-by-10 game boards – a “Ship Board” for each player (to place ships on), and a “Torpedo Board” for each player (to fire torpedoes on). Place a dash (-) in each “cell” of each board. • Start by asking each player to place his/her 3 ships: • First, display his/her Ship Board. • The Cruiser and the Destroyer are both 4 cells long; the Battleship is 5. • You must ask the player where to start placing a ship (for example, Row 3, Column 7), and then asking which direction the ship should go from there (up, down, left, or right). (this will require some serious error checking!) • Assign an uppercase C (Cruiser), D (Destroyer), or B (Battleship) to the cells where a ship is located. • Now…let the game begin. Display Player 1’s Ship Board and Torpedo Board. Let Player 1 enter the coordinates of the location he would like to fire a torpedo at. Announce whether he hits or misses. If he hits, place an X in the location of the hit (on Player 1’s Torpedo Board, AND on Player 2’s Ship Board). If he misses, place an uppercase O. • Error checking: do not allow a player to fire at a location he has already fired at; there are only 10 rows & columns; some directions are impossible. • If a player sinks a ship, announce it. (“You sunk Player 2’s Destroyer!”). • After Player 1 fires, it is Player 2’s turn. • The players take turns until one player’s ships are all sunk.