2017-01-06 34 views
1

遊戲代碼非常簡單,代碼如下。不知道爲什麼: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(仍然沒有骰子)
+1

沒深入挖掘,我建議你添加/ i開關到你的if,所以比較是獨立的情況。你要求大寫答案並比較小寫字母y。如果你剛剛輸入,var輸入是未定義的,並且會返回一個錯誤,因爲它解析爲'if == y',這是不正確的語法。 – LotPings

+0

你真了不起,謝謝。甚至不知道/ i開關存在!謝謝你。一定會探索更多。 – Newbadmin

+0

刪除第二個'='登錄'set/p input ==(Y/N)'... – aschipfl

回答

0

下面的命令有一個額外的=導致一個語法錯誤:

set /p input==(Y/N) 

set /p提示不能與=開始。按如下方式刪除不需要的字符,命令將起作用。

set /p input=(Y/N) 

正在重用的input變量,set /p將保留任何預先存在的值,如果用戶只需按下<Enter>。您應該在提示輸入前清除該值。

set "input=" 
set /p input=(Y/N) 

有很多地方你的代碼可以(應該)提高其他領域,但我會讓你在自己的步伐發現它們。

+0

太好了,沒有意識到我可以清除預先存在的價值,將會牢記這一點,所以我不必提出大量的變量。非常感謝! – Newbadmin

0

基本是/否選擇命令您例如:

@Choice /M "Ready to start?" 
@Echo=%%ERRORLEVEL%% is %ERRORLEVEL% 
@Timeout 5 

運行一下,看看當你進入不同的選擇會發生什麼。

+0

是的,我現在在一個小時的好時間裏一直在嘲笑Choice。對於我正在努力完成的任務來說,這更清潔。 – Newbadmin

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 
+0

哈哈,甚至沒有考慮合併正確的屏幕。更不用說調用批處理腳本的單獨部分了。這真是太棒了。 – Newbadmin

相關問題