Question: Study Floating and Docking Windows of MSVS described here (http://vega.cs.kent.edu/~mikhail/classes/csi/Labs/MSVS/features.html). As you work on the below project, demonstrate to the instructor the usage of this

Study Floating and Docking Windows of MSVS described here (http://vega.cs.kent.edu/~mikhail/classes/csi/Labs/MSVS/features.html). As you work on the below project, demonstrate to the instructor the usage of this feature.

You are to program a simplified version of the Battleship guessing game. The assignment is broken into two parts. The below game and header file description applies to both parts.

Battleship game description. 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'). Your program should randomly place a fleet of five ships in the ocean. 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. The user fires on the ships by specifying the coordinates of the shot. 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 and function description. The data structures and functions needed to implement the game are declared in this header file(http://vega.cs.kent.edu/~mikhail/classes/csi/Labs/Lab8/battleship.h). The header file defines two structures:

Location stores the number and letter coordinates of a ship or a shot;

Ship stores the coordinates of the ship in Location substructure and a boolean variable signifying whether the ship was sunk. The fleet of the deployed ships should stored in the array where each element is a structure variable of Ship. This array is first initialized and then used in the game.

The functions are separated into three groups:

Initialization functions that place the fleet of battleships in the ocean. The major function among the initialization functions is deploy() that accepts an array of ships by reference and initializes their locations. It uses the other two initialization functions: pick() and check() The pseudocode for deploy()is as follows:

 declare a variable that stores the number of the deployed ships, initially zero, this variable is to be used as an index in the array of ships loop until all ships are deployed invoke pick() to get a new random location in the ocean invoke check() to verify whether this location is occupied if this location is available then deploy the next ship at this location by storing the coordinates of this location in the ship's location, change the status of the ship to "not sunk" increment the number of the deployed ships 

Hint: To randomly assign a character coordinate (from 'a' to 'e') for the location in pick(), randomly select a number from 1 to 5 and then use a switch to select the appropriate letter.

Hint 2: The logic of initialize(), check() and deploy() is very similar to the logic of lottery number selection functions in one of the previous labs.

Functions that display the location of the fleet. After the fleet is deployed, the user is prompted if he would like to see the location of the ships (Hint: use this option for debugging). If the user selects this option then the locations of the ship (and their status: sunk or not) is printed after every shot

The printout is done using the following functions.

printShip() prints the location and status of a single ship

printFleet() prints the location and the status (sunk or not) of the whole fleet of ships. This function uses printShip(). The output of this function might look like:

b5 sunk, c3 up, a2 up, e1 sunk, e4 up

Battle functions that control the game play. After the fleet of ships is deployed, and its location is printed if desired, the game starts. The pseudocode of the game algorithm (to be implemented in main() or a dedicated function) is as follows.

 while at least one ship is operational invoke fire() to get the location of the next shot from the user invoke check() to see if this location is occupied by a ship if location is occupied then invoke sink() to sink the ship report a hit else report a miss 

Assignments

Test. Create a project titled Lab8_Test. Add the header file battleship.h(http://vega.cs.kent.edu/~mikhail/classes/csi/Labs/Lab8/battleship.h) described above to your project. Add this file testShips.cpp(http://vega.cs.kent.edu/~mikhail/classes/csi/Labs/Lab8/testShips.cpp) to your project as well. Implement the functions prototyped in battleship.h file and invoked in testShips.cpp and place these function definitions in battleship.cpp

Note that presently portions of the file are commented out. This is to encourage incremental program development. You need to implement the functions that are not commented first. Then, uncomment the second portion of code and implement those functions. Once your project works correctly with all code of testShips.cpp uncommented, submit your project.

Game. Create a project titled Lab8_Game. Use battleship.h, battleship.cpp from the test assignment above; add game.cpp that contains main() , invokes the game functions declared in battleship.h and implements the Battleship game as described in the introduction.

Make sure your programs adhere to proper programming style. Submit your projects to the subversion repository. Do not forget to verify your submission on the web.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!