我正在做一个批处理文件中的RPG游戏,我想让用户在5秒内输入一个像黄油这样的词。如果他不打算这样做,他将一无所获,然后回去。但是,如果他打字正确,他就会赚到钱。我想让它显示计时器。你们能帮上忙吗?可以使用PING命令来完成吗?
发布于 2018-06-01 03:02:06
算上你的努力,你不配得到它。
只是为了给你一个起点,
batch不适合测量/处理/计算时间。
:: Q:\Test\2018\05\31\typingtest.cmd
@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
:loop
cls
Echo enter butter
choice /n /C b >NUL
set start=%time%
choice /n /C u >NUL
choice /n /C t >NUL
choice /n /C t >NUL
choice /n /C e >NUL
choice /n /C r >NUL
set ready=%time%
Echo start:%start%
Echo ready:%ready%示例输出:
enter butter
start:21:00:50,50
ready:21:00:51,56不管我最初的评论,下面的版本更通用,如果你的%time%返回24小时的格式和数百秒的格式,它可以正确地计算秒。
:: Q:\Test\2018\05\31\typingtest.cmd
@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
cls
Echo enter butter
Set "Start="
For %%A in (b u t t e r) do (
choice /n /C %%A >NUL
if not defined Start Set "Start=%time%"
)
Set "Ready=%time%"
Call :CalcTime Start
Call :CalcTime Ready
Set /A "Lapse=Ready-Start"
Echo Secs : %Lapse:~0,-2%,%Lapse:~-2%
Pause
Goto :Eof
:CalcTime
Echo=%1: !%1!
For /f "tokens=1-4delims=:.," %%H in ("!%1!"
) Do Set /A "%1=(1%%H-100)*360000+(1%%I-100)*6000+(1%%J-100)*100+%%K"示例输出:
enter butter
Start: 16:25:43,42
Ready: 16:25:46,94
Secs : 3,52https://stackoverflow.com/questions/50630539
复制相似问题