PROGRAM DESCRIPTION: For this C++ program, you will edit your Homework 5 programming assignment to add the functionality to play a simplified version of the classic game of Stratego that will display...



PROGRAM DESCRIPTION:


For this C++ program, you will edit your Homework 5 programming assignment to add


the functionality to play a simplified version of the classic game of Stratego that will


display to the screen. Unless so indicated, all of the requirements in Homework 5 hold


in Homework 6. Note that there are some changes to this assignment!


You will take your solution from Homework 5 and edit it as follows:


1. You shall organize your program into three files:


• hw6prgm.h will hold the include directives for the necessary libraries, any


global constants, any enumerated data types, any type definitions, any


structure definitions, and the list of function prototypes (i.e., function


declarations).


• hw6main.cpp will hold the local include directive for the header file as well


as the main function
for
the program.



• hw6func.cpp will hold the local include directive for the header file as well


as all function definitions (not including main, of course) used in the program.


2. You will update the rules of the game to note what happens when equal pieces


strike. Note the rules in the SAMPLE OUTPUT.


3. Define a structure (i.e., struct) that contains information about each piece


associated with each location (i.e., square) on the game board. Specifically, this


structure should contain the following three members: (1) an enum data type


member that holds the rank (i.e., FLAG, BOMB, MARSHAL, etc.) of the piece on the


board, (2) an enum data type member that holds the color of the piece on the


board, and (3) a boolean variable that indicates whether the piece on the board is


moveable or not. You will then change the data type of the game board array to


be of this structure instead of the enum as required in Homework 5.


4. Update the function to display the game board by adding a boolean formal


parameter used to indicate whether or not to “reveal” the solution with all pieces


visible, or to display the current, active board with the computer's (i.e., BLUE)


pieces hidden, showing some generic value 'X' instead. The RED player's pieces


must, obviously, be revealed for the user to play the game. You will call this


function every time to display the updated board after each valid user move.


5. Add a boolean value-returning function to update the board after a valid move


(refer to rules about how a moveable piece can move one position up/down or


left/right on the board, but a non-moveable piece cannot be moved) so as to


return a boolean value to indicate whether or not the game is over (i.e., if the


player struck the opponent's FLAG, this function would return true; otherwise, it


would return false). You will use this boolean result to determine if the game


should continue (i.e.,
game
is not over) or not (i.e.,
game
is over). At a minimum,



you will pass the game board as well as position information of the piece that is


moving or striking to this function. You will display sufficient and meaningful





2 of 16


information about what is happening for each valid move (see SAMPLE OUTPUT


for examples of what type of information is expected).


6. Inside the main function, you will add a loop to play the game until either the


game is won (e.g., the player successfully struck the opponent's FLAG) or the


player has selected to forfeit the game by typing "QQ" to end the game (e.g., the


player no longer has any available moves). For each turn, the player will enter a


set of coordinates corresponding to the current position (i.e., row and column) of


the piece on the game board the player wants to move. If the player enters an


invalid position (e.g., outside of the game board, a non-moveable piece, an


empty square, the opponent's piece, etc.), you will provide a meaningful error


message that an invalid position was entered and continue to prompt the player


to enter the coordinates again until valid coordinates are entered. You will do


similarly for the new position of the piece by validating the new position of the


piece. If the player enters an invalid position (e.g., outside of the game board, a


diagonal move, or a move of more than one space). You may assume that the


player enters the position coordinates correctly as a letter and an integer, though


one or both values may not be in the valid range defined. Following each turn,


you will display an updated version of the board. Ultimately, the game will be


over if the player strikes the opponent's FLAG (i.e., won the game) or the player


forfeits the game by entering "QQ", in a case, for example, when the user has no


more moves left. At the end of the game, you will display a meaningful message


about whether the player won or lost the game as well as the final updated board


with the position of all the pieces revealed.


7. Instead of a static two-dimensional array as was done in Homework 5, you shall


declare and create a two-dimensional dynamic array in main to represent the 5-


by-5 board for the struct data type you declared to hold the various values that


a square can assume. Since the board array is not global, you will pass the


board array to the needed functions as a pointer (actually, as a pointer to a


pointer). You will need to make sure to return the memory for the
twodimensional

array back to the
freestore
when your program is done using it (at



the end).


8. You may use global enum types, type definitions, and structures. You may also


have a limited number of global constants, such as the size of the game board,


but the board array must be declared as a local variable that is then passed to


the related functions.

Dec 05, 2019CSCE 1030
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here