1 / 2

Assignment: BATTLESHIP

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….

kali
Télécharger la présentation

Assignment: BATTLESHIP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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…..

  2. 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.

More Related