int move_player() {
if (GetAsyncKeyState(VK_RIGHT) && current_x<max_x) {
int old_x = current_x;
int new_x = current_x+1;
path[old_x] = '_';
path[new_x] = player;
system("cls");
cout << endl;
for (int a=0; a <= 9; a++) {
cout << path[a];
}
} else if (GetAsyncKeyState(VK_LEFT) && current_x>min_x) {
int old_x = current_x;
int new_x = current_x-1;
path[old_x] = '_';
path[new_x]=player;
system("cls");
cout << endl;
for (int b = 0; b <= 9; b++) {
cout << path[b];
}
}
return current_x;
}
大部分代码的作用是它只是围绕一个对象移动(只是向右或向左)。它首先显示最左边的对象然后我可以向右移动一次,但是当我按下向右或向左键时它什么也没做。 我该如何解决?
答案 0 :(得分:0)
我该如何解决?
您需要在while
区块周围使用if-else
循环。
或
在调用函数的move_player
循环中调用while
。