我正在 Delphi 中开发一个问答游戏,我想要一个计时器,以便玩家没有无限的时间来回答问题。我正在使用“时间”函数来获取当前时间,但我不知道如何将其转换为整数之类的东西,这样当假设 10 秒过去了时,玩家就失去了机会。它看起来像这样:
Var
CurrentTime,Aux:TDateTime;
Begin
CurrentTime:=Time; //Current Time is assigned to a global variable.
Aux:=CurrentTime;
While (Aux-10000<=CurrentTime) do
Begin
if (Answer:=True) then //If the answer is already given by the player we break the while loop
Break;
Aux:=Time; //We refresh the auxilary variable
if (Aux-10000>=CurrentTime) then //We check if 10 seconds have passed
Begin
showmessage('You have taken too much time, your turn is lost');
exit; //We leave the script
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
问题是我不能在 DateTimes 中进行算术运算,据我所知,所以我需要一种不同的方法来比较 2 个不同的时间实例。任何帮助将不胜感激,谢谢!