本文整理汇总了C++中Timeout::hasTimedOut方法的典型用法代码示例。如果您正苦于以下问题:C++ Timeout::hasTimedOut方法的具体用法?C++ Timeout::hasTimedOut怎么用?C++ Timeout::hasTimedOut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timeout
的用法示例。
在下文中一共展示了Timeout::hasTimedOut方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
Threat threat = Threat(0);
Timeout loopTimeout = Timeout(40);
// game loop
while (1) {
loopTimeout.start();
string enemy1; // name of enemy 1
cin >> enemy1; cin.ignore();
int dist1; // distance to enemy 1
cin >> dist1; cin.ignore();
threat.push_back(Enemy(dist1, enemy1));
string enemy2; // name of enemy 2
cin >> enemy2; cin.ignore();
int dist2; // distance to enemy 2
cin >> dist2; cin.ignore();
threat.push_back(Enemy(dist2, enemy2));
// We have acquired the list of enemy
// We have to sort the list from the
// closest to far away
sort(threat.begin(), threat.end(),
[](const Enemy & a, const Enemy & b)
{
// true will make the sort to let
// the object in the same order
return a.getDist() < b.getDist();
});
// We acquire the enemy which is the closer,
// ie at the end of the list of threat
Enemy threatToEliminate = threat.front();
threat.erase(threat.begin());
// We output the enemy to kill
cout << threatToEliminate.getName() << endl;
if(loopTimeout.hasTimedOut()) break;
}
return EXIT_SUCCESS;
}