如果没有输入变量,如何让我的脚本不能继续?

时间:2016-03-14 00:37:50

标签: batch-file

我想这样做是为了在我的游戏中,如果你在不输入选择的情况下按Enter键,它就不会继续代码。我怎样才能做到这一点?我的意思是如果你按下回车而不输入1,2,3等等。是否有命令允许我这样做?

@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do     rem"') do (
  set "DEL=%%a"
)
:start
echo You have been studying for years for this moment, to create a human master race, all you have to do is complete the circuit connecting the lightning rods to the speciman.  Do you do it?
ping -n 2 1.1.1.1 > nul
echo.
echo 1) Connect the circuit.
echo 2) No, you take your work and burn it.
echo.
set /p Choice=Choose Now: 
if "%Choice%"=="1" goto awaken
if "%Choice%"=="2" goto end1

:awaken
cls
echo 3
timeout /t 2 /nobreak >nul
cls
echo 2
timeout /t 2 /nobreak >nul
cls
echo 1
timeout /t 2 /nobreak >nul
cls
echo CRACK!!
timeout /t 2 /nobreak >nul
cls
echo Lightning strikes the rod and you see movement coming from the speciman under the sheet on the table.
pause
cls
echo The creature sits up.  It is more disgusting then you ever could have imagined, you are terrified.  It stares at you with mindless eyes, what do you do?
echo.
echo 1) Run for your life.
echo 2) Stay in the Room.
echo.
set /p Choice=Choose Now: 
if "%Choice%"=="1" goto run4life
if "%Choice%"=="2" goto staycalm

:run4life [
cls

]

:staycalm [
cls
echo The monster stares at you.
timeout /t 4 /nobreak >nul
echo It screams
timeout /t 1 /nobreak >nul
call :colorEcho 0a "RAAAAUUUGGGHHH"
timeout /t 2 /nobreak >nul
echo.
echo 1) Run for your life.
echo 2) Stay in the Room.
echo.
set /p Choice=Choose Now: 
if "%Choice%"=="1" goto run4life
if "%Choice%"=="2" goto staycalm2
]

:staycalm2
[
cls
timeout /t 3 /nobreak >nul
echo You hear a knock at the door.
call :colorEcho 0a " Hello, anyone there?  Someone reported hearing a scream from your residence."
echo.
echo How should you react?
echo.
echo 1) Jump out the window.
echo 2) Answer the door.
echo.
set /p Choice=Choose Now: 
if "%Choice%"=="1" goto run4life
if "%Choice%"=="2" goto staycalm3
]

:staycalm3
[
cls
call :colorEcho 0c "Oh yes, I was just scared by a spider."
echo.
timeout /t 2 /nobreak >nul
echo.
call :colorEcho ob "uhhmmm..."
timeout /t 2 /nobreak >nul
echo.
echo.
call :colorEcho 0b "Well, do you mind if I come in just to check around?
]

:end 1
cls
echo Congratulations, you have completed the game without causing anyone to die!
echo.
echo 1) Exit
echo 2) Play Again!
echo.
set /p Choice=Choose Now: 
if "%Choice%"=="1" goto 
if "%Choice%"=="2" goto first

:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i

1 个答案:

答案 0 :(得分:1)

这是一种方式:

echo.
:loop1
set "Choice="
set /p Choice=Choose Now: 
if "%Choice%"=="1" goto run4life
if "%Choice%"=="2" goto staycalm
goto :loop1