如何检测 Pascal 中经过的时间?
我正在尝试用 Pascal 创建一个简单的游戏。它使用控制台。游戏的目标是在 60 秒内收集尽可能多的“苹果”。游戏结构是一个简单的无限循环。每次迭代,您都可以迈出一步。问题是,在您采取行动 (readKey
) 之前,时间可以随心所欲地流逝。例如,用户可以在10秒后按下一个键!有什么办法可以计算时间吗?我需要程序知道用户何时玩游戏(按下按键之前和之后),所以我不知道如何防止用户“作弊”。
这是我的游戏的简单结构:
begin
repeat
{* ... *}
case ReadKey of
{* ... *}
end;
{* ... *}
until false;
end.
完整代码: http://non.dagrevis.lv /junk/pascal/Parad0x/Parad0x.pas。
据我所知,有两种可能的解决方案:
- getTime(来自DOS)、
- delay(来自CRT)。
...但我不知道如何在我的循环中使用它们。
I'm trying to create a simple game in Pascal. It uses the console. The goal in the game is to collect as many 'apples' as you can in 60 seconds. The game structure is a simple infinite loop. Each iteration, you can make one move. And here's the problem — before you make the move (readKey
), time can pass as much as it wants. For example, the user can press a key after 10 seconds! Is there any way to count time? I need the program to know when user plays (before and after a key is pressed), so I don't know how to prevent user from "cheating".
Here's simple structure of my game:
begin
repeat
{* ... *}
case ReadKey of
{* ... *}
end;
{* ... *}
until false;
end.
Full code: http://non.dagrevis.lv/junk/pascal/Parad0x/Parad0x.pas.
As far I know that there are two possible solutions:
- getTime (from DOS),
- delay (from CRT).
...but I don't know how to use them with my loop.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查此链接。可能有一些对您有用的信息。 这里与您所要求的相同。 这就是您要查找的内容(与下面的代码相同)。
Check this link. There might be some useful information for you. And here is the same you're asking for. And here's what you're looking for (same as the code below).