C++ 自动和手动引导机器人通过迷宫c++;
整个程序有一个函数,可以读取迷宫中使用的测试文件 墙为X,路径为负号,终点位置为$,起点位置为+, 并使用draw_Box函数将其转换为更好的图形迷宫 在不同颜色的正方形中(取决于是否有墙或路径),结束位置 或者开始位置示例,如果它读取X,那么它将放入一个灰色正方形(一堵墙) 白色表示(一条小路),红色表示$(最终位置)等 我画了迷宫,下面这个函数可以移动机器人 (只是一个蓝色方块)基于命令(箭头键),但现在我需要 修改move_robot(移动机器人)功能,使机器人能够移动到 自行操作,直到到达末端位置,以及手动操作 (用户将键入命令以确定机器人是否移动 自动或手动) 我怎么能这样做C++ 自动和手动引导机器人通过迷宫c++;,c++,maze,C++,Maze,整个程序有一个函数,可以读取迷宫中使用的测试文件 墙为X,路径为负号,终点位置为$,起点位置为+, 并使用draw_Box函数将其转换为更好的图形迷宫 在不同颜色的正方形中(取决于是否有墙或路径),结束位置 或者开始位置示例,如果它读取X,那么它将放入一个灰色正方形(一堵墙) 白色表示(一条小路),红色表示$(最终位置)等 我画了迷宫,下面这个函数可以移动机器人 (只是一个蓝色方块)基于命令(箭头键),但现在我需要 修改move_robot(移动机器人)功能,使机器人能够移动到 自行操作,直到到
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 blue robot square left 1 space)
else if(c==-89) //ASCII for right arrow key
x_new=x+square_side; //(move blue robot square right 1 space)
else if(c==-90) //ASCII for up arrow key
y_new=y-square_side; //(move blue robot square up 1 space)
else if(c==-88) //ASCII for down arrow key
y_new=y+square_side; //(move move blue 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 blue 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]=='$')
// if position is the end position do the following
{
move_to(window_length/2,window_width/2);
set_pen_width(2);
set_pen_color(color::blue);
write_string("WINNING!!!");
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);
}
}
}
}
下次请清理粘贴的代码以使其可读(删除不必要的空格和制表符)