基于c语言利用easyx库做一个简单小游戏,在游戏界面中想显示游戏时间
通过函数计算函数运行时间,再用outtextxy函数输出到界面但是时间时钟为0
clock_t start = clock();
clock_t end = clock();
int T = (int)((end-start)/ CLOCKS_PER_SEC);
void interface1() {
//setbkmode(OPAQUE);
setcolor(WHITE);
char str1[10], str2[10], str3[10], str4[10];
sprintf_s(str1, " %d", player.life);
sprintf_s(str2, " %d", player.intagla);
sprintf_s(str3, " %d", enemy->speed);
settextstyle(30, 0, "宋体");
outtextxy(444, 100, str1);
outtextxy(429, 70, "生命");
outtextxy(429, 140, "积分");
outtextxy(444, 170, str2);
outtextxy(390, 210, "小车速度");
outtextxy(444, 240, str3);
//clock_t start = clock();
//clock_t end = (clock() - start) / CLOCKS_PER_SEC;
//int time = (int)(end);
sprintf_s(str4, " %d", T);
outtextxy(390, 280, "游戏时间");
outtextxy(390, 310, str4);
}
void ends() { //结束界面
mciSendString("stop /images/racing.mp3", NULL, 0, NULL);
cleardevice();//清除窗口
settextstyle(128, 0, "宋体");
outtextxy(0, 256, "游戏结束");
settextstyle(40, 0, "宋体");
outtextxy(128, 385, "最终得分:");
outtextxy(128, 450, "游戏时间:");
char str3[10];
char str4[10];
sprintf_s(str3, " %d", player.intagla);
outtextxy(300, 385, str3);
sprintf_s(str4, " %d", T);
outtextxy(300, 450, str4);
}
运行结果及详细报错内容
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/790945586076183.png?x-oss-process=image/auto-orient,1/resize,w_320,m_lfit)
![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/527026586076127.png?x-oss-process=image/auto-orient,1/resize,w_320,m_lfit)
想过是sprintf_s函数的问题,和定义的时间T类型问题但是不太明白
麻烦各位有时间能帮我看看,就是想在游戏过程中能看到时间,并且游戏结束页面看到游戏时长