在c ++中创建计时器? [英] Making a Timer in c++?

查看:131
本文介绍了在c ++中创建计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个简单的游戏,在c + +,一个追逐点式的一个,你必须单击一个画在显示器上的圆,然后它跳到另一个随机位置每次点击,但我想让游戏在60秒之后结束,将得分写入文本文件,然后在启动从文本文件读取的程序并将信息存储在数组中并以某种方式重新排列以创建高分表。
我想我可以找出高分和鼠标点击在某个区域自己,但我完全卡住了创建一个可能的计时器。
任何帮助,赞美!

I am developing a simple game in c++, a chase-the-dot style one, where you must click a drawn circle on the display and then it jumps to another random location with every click, but I want to make the game end after 60 seconds or so, write the score to a text file and then upon launching the program read from the text file and store the information into an array and somehow rearrange it to create a high score table. I think I can figure out the high score and mouse clicking in a certain area myself, but I am completely stuck with creating a possible timer. Any help appreciated, cheers!

推荐答案

在C ++ 11中可以轻松访问计时器。例如:

In C++11 there is easy access to timers. For example:

#include <chrono>
#include <iostream>

int main()
{
    std::cout << "begin\n";
    std::chrono::steady_clock::time_point tend = std::chrono::steady_clock::now()
                                               + std::chrono::minutes(1);
    while (std::chrono::steady_clock::now() < tend)
    {
        // do your game
    }
    std::cout << "end\n";
}

您的平台可能支持或不支持< chrono> ; 有一个 boost 实施< chrono>

Your platform may or may not support <chrono> yet. There is a boost implementation of <chrono>.

这篇关于在c ++中创建计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆