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(Game::key_thread, 0, NULL); _beginthread(Game::timer_thread, 0, NULL); Sleep(10000000000000000000); }//“Game::key_thread”: 非标准语法;请使用 "&" 来创建指向成员的指针请问这段代码应该怎么修改
时间: 2024-02-14 19:05:48 浏览: 145
常用timer的介绍
3星 · 编辑精心推荐
可以将Sleep函数改为while循环来保证程序不会因为等待时间过长而挂起,同时将_beginthread函数中的指向成员的指针改为指向静态成员函数的指针。修改后的代码如下:
```
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(&Game::key_thread, 0, NULL);
_beginthread(&Game::timer_thread, 0, NULL);
while (true);
}
```
阅读全文