c++ only please. Its the game of Ricoh robots. The object of the game is to get
ID: 3700528 • Letter: C
Question
c++ only please. Its the game of Ricoh robots.
The object of the game is to get the designated numbered robot to the indicated letter position. The numbered squares are all robots. They unfortunately have no brakes, and so will continue in whatever direction they are moving until they encountar an obstacle. For each move enter the robot number and the desired direction. For instance entering 1 U would move the #1 robot up as far as it can go. The first letter of input is the robot number (1 -4), and the second letter is the direction: (L-left, U-up, R-right, D-down) Enter x to exit. Have fun! Enter ir' for random robot and goal, 'd' for default or to select: d Move robot 2 to square M 4 1Explanation / Answer
//Here is an expample of two robots x & y. You can replace x & y with 1,2,3 & 4 //Here the robot reaches one position 4. You can write the same for other positions void move_robot(int &x, int &y) { while(true) { char c=wait_for_key_typed(); int x_new=x; int y_new=y; if(c==-91) //ASCII for left arrow key x_new=x-square_side; //(move robot square left 1 space) else if(c==-89) //ASCII for right arrow key x_new=x+square_side; //(move robot square right 1 space) else if(c==-90) //ASCII for up arrow key y_new=y-square_side; //(move robot square up 1 space) else if(c==-88) //ASCII for down arrow key y_new=y+square_side; //(move move robot square down 1 space) else if (c == 'x') //exits the game hide_window(); if(m_array[(y_new/square_side)+1][(x_new/square_side)+1]!='X') // if position is not a wall do the following... { draw_robot(x_new,y_new); // calls a function that draws a square. draw_boxes(x,y,'-'); // draws white box to cover previous robot position x=x_new; y=y_new; //these update the position } if(m_array[(y_new/square_side)+1][(x_new/square_side)+1]=='4') // if position is the end position (4) do the following { move_to(window_length/2,window_width/2); set_pen_width(2); write_string("Position Reached!!!"); char repeat=wait_for_key_typed();//to run the maze again if(repeat=='r') { draw_maze(); int x=square_side*20; int y=square_side*9; move_robot(x,y); } } } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.