如何在 Delphi 7 中测量经过的时间?
我想知道是否有人可以帮助我。我对 Delphi 编程非常陌生,我有一个 10 天内到期的学校项目,说实话我不知道我在做什么。
对我的期望是,我编写了一个记忆游戏,我目前陷入困境,我必须计算该人玩游戏需要多长时间,然后在最后显示他们花了多长时间作为“分数”。
我如何计时?我应该使用什么组件以及如何对该组件进行编程以计时?它应该在单击按钮时开始,然后在游戏结束时结束。
任何帮助将不胜感激!
I was wondering if anyone could by any chance help me. I am very new to Delphi Programming and I have a school project due in 10 days and to be honest I have no idea what I'm doing.
What is expected of me is that I program a memory game where I am currently stuck in that I have to time how long it takes the person to play the game and then display how long it took them as a 'score' at the end.
How do I time? What component should I use and how do I program this component to time? It should start when a button is clicked and then end when the game finishes.
Any help will be highly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为什么不在他开始游戏时将当前时间保存在变量中,并在他结束时再次保存时间?
您可以通过立即指令获取。
您将在系统中看到当前时间。
Why don't you save the current time in a variable when he starts the game, and again save the time when he ends?
You can take it by the Now instruction.
You'll see the current time in the system.
您将需要
1.- 在表单中
Enabled
属性设置为False
。startTime
来记录用户开始游戏的时间。应该会产生类似这样的结果...
2.- 在开始按钮的单击事件中,初始化 startTime 属性并启动计时器的代码。
3.- 在计时器的计时器事件中,一些代码用于显示时间计数
4.- 在完成按钮的单击事件中,或者当程序认为游戏结束时,一些代码用于停止计时器。
You will need
1.- In your form,
Enabled
property toFalse
.startTime
to record the time when the user starts the game.should result something like this...
2.- At the click event of the start button, the code to initialize the startTime attribute and kick-off the Timer.
3.- At the Timer event of the Timer, some code to display the time counting
4.- At the click event of the finish button, or when the program considers the end of the game, some code to stop the timer.
PA 的答案似乎正是您所需要的。因为如果我理解得很好并且这是您第一次使用delphi,我只需补充一点:
Now
是SysUtils中定义的一个函数,它返回当前日期和时间您将在系统组件面板上找到 TTimer(请参见下面链接中的图片)
通过选择对象检查器中的“事件”选项卡,然后双击输入框(参见下面链接中的图片)
< a href="https://i.sstatic.net/0iNsL.png" rel="nofollow">https://i.sstatic.net/0iNsL.png (抱歉,无法内联图像,因为我还没有必要的声誉)
从这里开始你的申请将会很容易完成,
祝你好运,
G
PA's answer seems to be exactly what you need. because if i understood well and this is your first time working with delphi, i'd only add that:
Now
is a function defined in SysUtils that returns the current date&timeyou'll find the TTimer on the System component pallette (see image in link below)
all the procedures where you need to write the code will be automatically generated by selecting the Events tab in the Object inspector, and then double clicking in the input box (see image in link below)
https://i.sstatic.net/0iNsL.png (sorry, can't inline images because i don't have the necessary reputation yet)
from here on it hould be very easy to finish your application
good luck,
G