<分区>
我有一项任务是创建像 Frogger 这样的游戏(您知道 - Frog 必须过马路的游戏)。到目前为止,我已经创建了 Frog 和汽车运动背后的逻辑,但我似乎无法同时运行这些过程。我知道多线程是执行此操作的正确方法,但我在通过 _beginthread 传递参数时遇到了一些问题。
这是我目前所拥有的:
void moveCarsLeft(int x, int y) {
if (y < 0) {
field[x][y + 4] = '_';
Sleep(600);
refreshField();
showField();
if (y == -4) {
moveCarsLeft(x, WIDTH-1);
}
moveCarsLeft(x, y - 1);
}
else {
if (y > WIDTH-4) {
field[x][y] = '-';
Sleep(600);
refreshField();
showField();
moveCarsLeft(x, y - 1);
}
else {
field[x][y + 4] = '_';
field[x][y] = '-';
Sleep(600); // this is what's messing up the whole thing
// it stops the whole program
// and that's why I think I need multithreading
refreshField();
showField();
moveCarsLeft(x, y - 1);
}
}
}
void moveCarsRight(int x, int y) {
... // the opposite of moveCarsLeft()
}
...
int main() {
...
_beginthread(moveCarsLeft, 0, what do I put here?);
...
}
所以,如果有人能告诉我实现此功能的正确方法,我将不胜感激。提前致谢:]