游戏代码非常简单,代码如下。无法弄清楚为什么:WRONG
部分的语法错误。我已经尝试从开始部分完全镜像它,并且是相同的。有人提供任何意见吗?
color 4a
cls
:MAIN
@echo off
echo Welcome to XXXX's Trivia Game!!
pause & echo Ready to start?
set /p input=(Y/N)
if %input%==y goto SECTION1
goto BYE
:BYE
@echo Sorry to see you leave! Have a nice day!
pause
exit
:SECTION1
@echo FIRST QUESTION!!!!
pause
cls & echo At what temperature does rain turn to snow?
echo A. 112 degrees
echo B. -37 degrees
echo C. 32 degrees
echo D. 17,341 degrees
set /p input=Answer?
if %input%==C goto 2
goto WRONG
:SECTION2
:SECTION3
:SECTION4
:SECTION5
:SECTION6
:SECTION7
:SECTION8
:SECTION9
:SECTION10
:WRONG
cls & echo You were wrong, would you like to start again?
set /p input==(Y/N)
if %input%==y goto :SECTION1
goto BYE
pause
:HALFWAY
:WIN
我尝试过的事情:
:SECTION1
和:WRONG
:WRONG
并在:SECTION1
:HALFWAY
和:WIN
:MAIN
(正常工作)复制到:WRONG
(仍然没有骰子)答案 0 :(得分:0)
以下命令有一个额外的=
导致语法错误:
set /p input==(Y/N)
set /p
的提示不能以=
开头。删除不需要的char,如下所示,命令将起作用。
set /p input=(Y/N)
您正在重复使用input
变量,如果用户只需按set /p
,<Enter>
将保留任何预先存在的值。您应该在提示输入之前清除该值。
set "input="
set /p input=(Y/N)
还有很多其他方面可以(应该)改进您的代码,但我会让您按照自己的进度发现它们。
答案 1 :(得分:0)
基本的是/否选择命令示例:
@Choice /M "Ready to start?"
@Echo=%%ERRORLEVEL%% is %ERRORLEVEL%
@Timeout 5
运行它,看看输入不同选项时会发生什么。
答案 2 :(得分:0)
修正了你的游戏:)
尝试以下代码......
编辑:做了一些代码改进和清理,希望你喜欢它......
@echo off
color 4a
cls
:MAIN
cls
echo.
echo --------------------------------------
echo Welcome to New-B-Admin's Trivia Game!!
echo --------------------------------------
echo.
set /p input="Ready to start playing ? Answer (Y/N): "
if /i "%input%"=="y" goto SECTION1
if /i "%input%"=="n" goto BYE
if not "%input%"=="Place_Holder_Value_Dont_Remove" goto MAIN
:SECTION1
cls
echo ------------------
echo Question Number 1
echo ------------------
echo.
echo At what temperature does rain turn to snow?
echo.
echo A. 112 degrees
echo B. -37 degrees
echo C. 32 degrees
echo D. 17,341 degrees
echo.
set /p input="Your answer?: "
if /i "%input%"=="a" goto WRONG
if /i "%input%"=="b" goto WRONG
if /i "%input%"=="c" (
call :CORRECT
goto SECTION2
)
if /i "%input%"=="d" goto WRONG
::the below if statment prevents the user from just hitting Enter Key or any non relevant letters or numbers.
if not "%input%"=="Place_Holder_Value_Dont_Remove" goto SECTION1 rem rename this goto statment to the same name as the label.
:SECTION2
cls
echo ------------------
echo Question Number 2
echo ------------------
echo.
echo What year was the two dollar bill last printed in the United States?
echo.
echo A. 1997
echo B. 2001
echo C. 2003
echo D. 2007
echo.
set /p input="Your answer?: "
if /i "%input%"=="a" goto WRONG
if /i "%input%"=="b" goto WRONG
if /i "%input%"=="c" (
call :CORRECT
goto SECTION3
)
if /i "%input%"=="d" goto WRONG
:: the below if statment prevents the user from just hitting Enter Key or any non relevant letters or numbers.
if not "%input%"=="Place_Holder_Value_Dont_Remove" goto SECTION2 rem rename this goto statment to the same name as the label.
:SECTION3
cls
echo ------------------
echo Question Number 3
echo ------------------
echo.
echo How many super bowls have the Denver Broncos won?
echo.
echo A. 5
echo B. 10
echo C. 7
echo D. 3
echo.
set /p input="Your answer?: "
if /i "%input%"=="a" goto WRONG
if /i "%input%"=="b" goto WRONG
if /i "%input%"=="d" (
call :CORRECT
goto SECTION4
)
if /i "%input%"=="c" goto WRONG
:: the below if statment prevents the user from just hitting Enter Key or any non relevant letters or numbers.
if not "%input%"=="Place_Holder_Value_Dont_Remove" goto SECTION3 rem rename this goto statment to the same name as the label.
:SECTION4
cls
echo ------------------
echo Question Number 4
echo ------------------
echo.
echo What was the name of the hourse from The Lone Ranger Movie that he saved from an enraged buffalo?
echo.
echo A. Silver
echo B. Yellow
echo C. White
echo D. Buck
echo.
set /p input="Your answer?: "
if /i "%input%"=="c" goto WRONG
if /i "%input%"=="b" goto WRONG
if /i "%input%"=="a" (
call :CORRECT
goto SECTION5
)
if /i "%input%"=="d" goto WRONG
:: the below if statment prevents the user from just hitting Enter Key or any non relevant letters or numbers.
if not "%input%"=="Place_Holder_Value_Dont_Remove" goto SECTION4 rem rename this goto statment to the same name as the label.
:SECTION5
:SECTION6
:SECTION7
:SECTION8
:SECTION9
:SECTION10
:END
cls
echo.
echo --------------------
echo No more questions!!!
echo --------------------
echo.
set /p input="Would you like to restart the game ? Answer (Y/N): "
if /i "%input%"=="y" goto SECTION1
if /i "%input%"=="n" goto BYE
if not "%input%"=="Place_Holder_Value_Dont_Remove" goto END
:WRONG
cls
echo.
set /p input="You were wrong, would you like to start again?(Y/N): "
if /i "%input%"=="y" goto SECTION1
if /i "%input%"=="n" goto BYE
if not "%input%"=="Place_Holder_Value_Dont_Remove" goto WRONG
:CORRECT
cls
set input=0
echo.
echo Correct!!! Great progress :)
echo Press enter to continue to next question...
pause >nul
goto :EOF
:HALFWAY
:WIN
:BYE
cls
echo.
echo ----------------------------------------
echo Sorry to see you leave! Have a nice day!
echo ----------------------------------------
pause >nul
exit