如何在此数学挑战赛程序中添加计时器脚本?

编程入门 行业动态 更新时间:2024-10-06 20:39:50
本文介绍了如何在此数学挑战赛程序中添加计时器脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我的脚本/程序;

@echo off cls color 0a :startup REM Determinant to Sign (+-*/) set /a deto1=%random% %%4 +1 set /a deto2=%random% %%4 +1 set /a deto3=%random% %%4 +1 set /a deto4=%random% %%4 +1 REM Set Sign from det if %deto1%==1 set o1=+ if %deto1%==2 set o1=- if %deto1%==3 set o1=* if %deto1%==4 set o1=/ if %deto2%==1 set o2=+ if %deto2%==2 set o2=- if %deto2%==3 set o2=* if %deto2%==4 set o2=/ if %deto3%==1 set o3=+ if %deto3%==2 set o3=- if %deto3%==3 set o3=* if %deto3%==4 set o3=/ if %deto4%==1 set o4=+ if %deto4%==2 set o4=- if %deto4%==3 set o4=* if %deto4%==4 set o4=/ REM Randomize digits from 1-9 set /a d1=%random% %%9 +1 set /a d2=%random% %%9 +1 set /a d3=%random% %%9 +1 set /a d4=%random% %%9 +1 REM Operation for final answer stored inside memory set /a answer=%d1%%o1%%d2%%o2%%d3%%o3%%d4% title MathWhiz! :game cls echo. echo Find the correct operation in order. All non-intregers are rounded down to whole numbers. ( 60 seconds ) echo. echo %d1%...%d2%...%d3%...%d4%=%answer% echo. set /p userans=Answer(Only sign in order from Left to Right): REM Comparasion of user answer to correct answer in memory if %userans%==%o1%%o2%%o3% goto :correct if not %userans%==%o1%%o2%%o3% goto :wrong :wrong cls title That's wrong! :( echo. echo That's wrong unfortunately because the answer is %d1%%o1%%d2%%o2%%d3%%o3%%d4%=%answer%. Try another one! echo. pause goto :startup :correct cls title That's correct! :) echo. echo That's correct as from %d1%%o1%%d2%%o2%%d3%%o3%%d4%=%answer%! Try another problem. echo. pause goto :startup

因此,我们如何添加计时器脚本来计时此数学挑战,该挑战将持续60秒,直到玩家重定向到:wrong 部分.我尝试了许多方法,例如 timeout/t 60/NOBREAK ,如果在用户输入( set/p )之前编写脚本,则不会让玩家输入游戏的答案出现了解决该问题的方法,但是如果在输入后编写脚本,则播放器也不会计时.使用&& 同时运行输入和命令似乎无法正常工作,因为它要么返回空白屏幕,要么返回不显示计时器的同一屏幕.实现其他秒表脚本也面临相同的问题.

So, how do we add the timer script to time this math challenge which will lasts for 60 seconds until the player is redirected to the :wrong section. I've tried numerous ways like timeout /t 60 /NOBREAK which if scripted before the user input ( set /p ) won't let the players input the answers of the problem presented in to solve it but if scripted after the input the player wouldn't be timed either. using the && to run both the input and the command at once doesn't seem to work properly as it either returns a blank screen nor a same screen without the timers shown. Implementing other stopwatch scripts also faces the same problem.

推荐答案

我有一些业余时间,因此我完成了解决此问题的方法.

I had some spare time, so I completed the solution to this problem.

@echo off setlocal EnableDelayedExpansion rem If this file is re-executed as pipe's right side, go to it if "%~1" equ "TimeoutMonitor" goto %1 cls color 0a set "oper=+-*/" :startup REM Determinant to Sign (+-*/) for /L %%i in (1,1,3) do ( set /A det=!random! %% 4 for /F %%d in ("!det!") do set "o%%i=!oper:~%%d,1!" ) REM Randomize digits from 1-9 for /L %%i in (1,1,4) do ( set /A d%%i=!random! %% 9 +1 ) REM Operation for final answer stored inside memory set /A answer=d1%o1%d2%o2%d3%o3%d4 title MathWhiz^^^! cls echo/ echo Find the correct operations in order in less than 60 seconds. echo All non-integers are rounded down to whole numbers. echo/ echo %d1%...%d2%...%d3%...%d4% = %answer% echo/ REM Timed input set "userans=" del InputLine.txt 2> NUL ( set /P "userans=Answer (only three +-*/ operators in order from Left to Right): " > CON >InputLine.txt call echo %%userans%% ) 2> NUL | "%~F0" TimeoutMonitor 60 set /P "userans=" < InputLine.txt del InputLine.txt if "%userans%" equ "timeout" goto :timeout REM Comparison of user answer to correct answer in memory set "result=wrong" set /A "result=d1%userans:~0,1%d2%userans:~1,1%d3%userans:~2,1%d4" 2> NUL if "%result%" equ "%answer%" goto :correct :wrong title That's wrong^^^! :( echo/ echo That's wrong^^^! The answer is %d1%%o1%%d2%%o2%%d3%%o3%%d4%=%answer%. Try another one^^^! goto next :timeout title Timed out^^^! :^| echo/ echo Time out^^^! The correct answer is %d1%%o1%%d2%%o2%%d3%%o3%%d4%=%answer% Try another problem. goto next :correct title That's correct^^^! :) echo/ echo That's correct as from %d1%%userans:~0,1%%d2%%userans:~1,1%%d3%%userans:~2,1%%d4%=%answer% Try another problem. :next echo/ choice /M "Another problem" if not errorlevel 2 goto :startup goto :EOF :TimeoutMonitor rem Get the PID of pipe's left side tasklist /FI "IMAGENAME eq cmd.exe" /FO TABLE /NH > tasklist.txt for /F "tokens=2" %%a in (tasklist.txt) do ( set "leftSidePipePID=!lastButOnePID!" set "lastButOnePID=%%a" ) del tasklist.txt rem Wait for the input line, or until the number of seconds passed for /L %%i in (%2,-1,1) do ( if exist InputLine.txt exit /B title MathWhiz^^^! (%%i seconds left^) ping -n 2 localhost > NUL ) rem Timed out: kill the SET /P process and create a standard input line taskkill /PID %leftSidePipePID% /F > NUL echo/ echo timeout> InputLine.txt exit /B

更多推荐

如何在此数学挑战赛程序中添加计时器脚本?

本文发布于:2023-11-30 18:40:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651098.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在此   计时器   挑战赛   脚本   数学

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!