1
我現在正在編寫一個遊戲批處理,當我遇到這個問題時我並沒有走得太遠。我試圖爲用戶答案設置一個變量,然後將這個答案用於IF語句,但由於某種原因,它總是進入:Quit
塊。有想法該怎麼解決這個嗎?如果批量聲明不起作用?
Echo . Are you ready?
Echo Your options are:
call :colorEcho C "================="
Echo.
Echo 1. Yes
Echo 2. No
call :colorEcho C "================="
Echo.
Echo Please enter the number corresponding to your answer.
set /p Answer1 = "Enter your choice: "
if "%Answer1%" == "1" goto Game
if "%Answer1%" == "2" goto Quit
:Quit
Echo You have chosen to quit.
pause
exit
:Game
::Game goes here.
Echo Test
pause
pause
exit
:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i
colorEcho只是爲一串文本設置了不同的顏色。
這是當我運行遊戲會發生什麼:
選項1選擇:
選項2選擇:
提前感謝!
黑桃
我建議看看[選擇](http://ss64.com/nt/choice.html),因爲它是專門爲這些東西製作的 –