Question: PLEASE HELP ME...!!! #include #include // for toupper() using namespace std; // Global variables and constants // Variables to store the board pieces char p1,
PLEASE HELP ME...!!!
#include
// Global variables and constants // Variables to store the board pieces char p1, p2, p3, p4, p5, p6, p7, p8, p9,p10,p11,p12, p13,p14,p15,p16,p17,p18, p19,p20,p21,p22,p23,p24, p25,p26,p27,p28,p29,p30, p31,p32,p33,p34,p35,p36;
void displayInstructions() { cout << "Welcome to the traffic game! " << endl << " " << endl << "Move the vehicles so that the Red car (RR) can exit " << endl << "the board to the right. Each move should be of the " << endl << "of the form: CDN where: " << endl << " C is the vehicle to be moved " << endl << " D is the direction (u=up, d=down, l=left or r=right)" << endl << " N is the number of squares to move it " << endl << "For example GR2 means move the G vehicle to the right" << endl << "2 squares. Lower-case input such as gr2 is also " << endl << "accepted. Enter '-' to reset board, or 'x' to exit. " << endl; }//end displayInstructions()
//-------------------------------------------------------------------- // Display the board, using the current values in the global variables. void displayBoard( ) { // Your code should go here, to print out the values in all the // p1, p2, ... p36 variables. // ... }//end displayBoard()
//-------------------------------------------------------------------- /* Board and corresponding global variable values are: - - - - - - - - 1 | G G . . . Y | 7 | P . . B . Y | 13 | P R R B . Y > 19 | P . . B . . | 25 | O . . . T T | 31 | O . F F F . | - - - - - - - - */ int main() { // Declare your variables here // ... displayIDInfo(); // Display ID info displayInstructions(); // Display game instructions // Set the board values p1='G'; p2='G'; p3='.'; p4='.'; p5='.'; p6='Y'; p7='P'; p8='.'; p9='.';p10='B';p11='.';p12='Y'; p13='P';p14='R';p15='R';p16='B';p17='.';p18='Y'; p19='P';p20='.';p21='.';p22='B';p23='.';p24='.'; p25='O';p26='.';p27='.';p28='.';p29='T';p30='T'; p31='O';p32='.';p33='F';p34='F';p35='F';p36='.'; // Display the initial board displayBoard(); // you must fill in that function for this to work // You should add more code here, and will likely also need to create some functions. // ... cout << endl; cout << "Thank you for playing. Exiting..." << endl; return 0; }//end main()
Think about what sorts of functions are useful for this program. For instance depending on the approach you are using to solve the problem, you might want functions to do something like the following:
findMoveRow(...) would return an integer value indicating what row a vehicle letter is in. You could write something similar for columns.
moveRowRight(...) would receive a single character representing the vehicle to be moved, along with 6 parameters which are the pieces to be manipulated. These pieces should be reference parameters so that changes to them get reflected back to the calling part of the program. This could then be called with a different set of p1..p36 variables for every row. Within the moveRowRight(...) function think about how to find the right-most position for the vehicle to be moved, storing this in currentPosition. Once found, swap the board value at currentPosition with the one to the left of it. Then subtract one from currentPosition, essentially moving your reference point one position to the left. If there is an additional matching vehicle character to the left, repeat this process. Once the above moveRowRight(...) function is working it should successfully move a vehicle a single position to the right. Then use a loop to repeat it multiple times in cases where you are moving more than a single position to the right.
getPieceAt( ...) Given a number 1..36, this would return the current character stored in the corresponding p1..p36 variable.
setPieceAt(...) Given a number 1..36 and a character, this would store that character into the corresponding p1..p36 variable.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
