Question
[Making a maze game by uisng c++] Hello! First of all, thank you for helping my stuff. Actually, I try to make a maze game
[Making a maze game by uisng c++]
Hello! First of all, thank you for helping my stuff.
Actually, I try to make a maze game in using c++.
I have some problems in my code. ["I have to keep my format that function conditions void create_maze(int &row_robot, int &column_robot ); void show_maze(int row_robot, int column_robot); bool robot_move(int &row_robot, int &column_robot); ]
1) In bool robot_move(int &row_robot, int &column_robot) function, I made a random number but it is not working as well. I will attached my coding result below. As you can see, the Random number is always same.
2) When I run it, I only want to keep only one map, but it showed lots of maps.
3) The robot("X") delete the wall("+") even I made a if condition in bool robot_move() function.
Could you help me how to deal with those issues? I will paste my code below and the result image.
#include/Users/jeonj iwan/CLionProjects/CIS25/cmake-build-debug/CIS25 RANDOM NUMBER: 3 How many moves: 0 RANDOM NUMBER: 3 How many moves: 1 RANDOM NUMBER: 3 How many moves: 2 RANDOM NUMBER: 3 How many moves: 3 RANDOM NUMBER: 3#include #include // why we need #include string????? #include #include #include using namespace std; void create_maze(int &row_robot, int &column_robot ); void show_maze(int row_robot, int column_robot); bool robot_move(int &row_robot, int &column_robot); const int SIZE = 10; enum Values {space, wall, e, robot}; Values maze[SIZE][SIZE]; int main() { int row_robot, column_robot, moving; bool temp = true; row_robot = 4, column_robot = 4; moving = -1; create_maze(row_robot, column_robot); show_maze(row_robot, column_robot); while (temp == true) { ++moving; if (maze[row_robot][column_robot] != wall) { robot_move(row_robot, column_robot); usleep(1000); show_maze(row_robot, column_robot); cout else if (maze[row_robot][column_robot] == e) { cout false; break; } } // maze[row_robot][column_robot] = robot; } void create_maze(int &row_robot, int &column_robot) { int i, j; for (i = 0; i for (j = 0; j wall; for (i = 1; i for (j = 0; j space; maze[1][0] = e; maze[7][9] = e; maze[1][9] = wall; maze[4][0] = wall; maze[4][8] = wall; maze[4][9] = wall; maze[7][0] = wall; maze[2][2] = space; maze[2][6] = space; maze[2][8] = space; maze[3][2] = space; maze[5][7] = space; maze[6][3] = space; maze[6][7] = space; maze[row_robot][column_robot] = robot; // Robot describe as 'X' } void show_maze(int row_robot, int column_robot) { int i, j; for(i = 0; i for (j = 0; j if (maze[i][j] == 0) cout else if (maze[i][j] == 1) cout else if (maze[i][j] == 2) cout else cout robot; } bool robot_move(int &row_robot, int &column_robot) { unsigned int num; srand(time(NULL)); num = rand() % 4 + 1; //cout while (1) { if (num == 1) //Move to North { if (maze[row_robot][column_robot] != wall) { if (maze[row_robot][column_robot] != e) { maze[row_robot][column_robot] = space; row_robot--; maze[row_robot][column_robot] = robot; break; } } } else if (num == 2) //Move to South { if (maze[row_robot][column_robot] != wall) { if (maze[row_robot][column_robot] != e) { maze[row_robot][column_robot] = space; row_robot++; maze[row_robot][column_robot] = robot; break; } } } else if (num == 3) //Move to East { if (maze[row_robot][column_robot] != wall) { if (maze[row_robot][column_robot] != e) { maze[row_robot][column_robot] = space; column_robot++; maze[row_robot][column_robot] = robot; break; } } else //Move to west { if (maze[row_robot][column_robot] != wall) { if (maze[row_robot][column_robot] != e) { maze[row_robot][column_robot] = space; column_robot--; maze[row_robot][column_robot] = robot; break; } } } } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started