Lab Instructor: Salem Othman Structures Lab 8 Lab Instructor: Salem Othman
Review Go to Dr. Mikhail Nesterenko website and read the topic: structures You need to understand: Structure Definitions Structure Variables Assigning Values to Structure Variables Passing Structures as Parameters, Returning Structures Complex Structures Structures and Arrays
Battleship Game Description 1 2 3 4 5 The field (ocean) is a square 5x5 grid. One of the coordinates of the grid is a number (from 1 to 5) And the other -- a letter (from 'a' to 'e').
Battleship Game Description: Deploy 1 2 3 4 5 Randomly place a fleet of five ships in the ocean 2,a 2,b 3,d 4,c 5,b Each ship takes up exactly one location in the ocean Multiple ships cannot be placed in the same location The ships, however, can be placed in adjacent locations.
Battleship Game Description: Fire 1 2 3 4 5 The user fires on the ships by specifying the coordinates of the shot 4,c 5,e The program reports whether each shot was a hit or a miss If the shot was a hit, the ship is sunk. The game continues until all ships are sunk. The program does not keep track of the locations of the previously fired shots.
Data structures: Location and Ship 1 x a y location mySpot; mySpot.x =1; mySpot.y=‘a’; ship loc sunk 1 x a y True
Data structures: Fleet myFleet myFleet [0] myFleet [1] myFleet [2] myFleet [3]
Functions Initialization functions that place the fleet of battleships in the ocean. Functions that display the location of the fleet. Battle functions that control the game play.