void Game::key_thread(void* arg) { putimage(zuoqishi + mouse.y * size, shangqishi + mouse.x * size, &bgs[2]); } void Game::timer_thread(void* arg) { bool flag1 = false; while (seconds >= 0) { int gewei, shiwei; gewei = seconds % 10; shiwei = seconds / 10; putimage(1012, 600, &number[shiwei]); putimage(1062, 600, &number[gewei]); Sleep(1000); seconds--; if (flag == true) { flag1 = true; break;//说明时间内走到了终点 } if (shengmingzhi == 0) { break; } } if (seconds < 0) { flag = false; biaoji.time = true; } if (flag1 == false) endgame(); } void Game::game() { _beginthread(key_thread, 0, NULL); _beginthread(timer_thread, 0, NULL); Sleep(10000000000000000000); }这段代码为什么会报错应该怎么修改
时间: 2024-02-04 20:04:31 浏览: 128
这段代码中的错误是因为`flag`和`shengmingzhi`变量没有定义,需要在代码中添加它们的定义。另外,`endgame()`函数也没有给出,需要根据需要自行实现。修改后的代码如下:
```
bool flag = false;
int shengmingzhi = 3;
void Game::key_thread(void* arg) {
putimage(zuoqishi + mouse.y * size, shangqishi + mouse.x * size, &bgs[2]);
}
void Game::timer_thread(void* arg) {
bool flag1 = false;
while (seconds >= 0) {
int gewei, shiwei;
gewei = seconds % 10;
shiwei = seconds / 10;
putimage(1012, 600, &number[shiwei]);
putimage(1062, 600, &number[gewei]);
Sleep(1000);
seconds--;
if (flag == true) {
flag1 = true;
break;//说明时间内走到了终点
}
if (shengmingzhi == 0) {
break;
}
}
if (seconds < 0) {
flag = false;
biaoji.time = true;
}
if (flag1 == false) {
endgame();//根据需要实现
}
}
void Game::game() {
_beginthread(key_thread, 0, NULL);
_beginthread(timer_thread, 0, NULL);
Sleep(10000000000000000000);
}
```
注意,`Sleep(10000000000000000000);`这行代码是无效的,需要根据实际情况修改。
阅读全文