我的BatchRPG没有正确地对If语句做

时间:2016-06-01 01:31:14

标签: batch-file if-statement

@echo off
title Batch RPG V1
color 0a
setlocal enabledelayedexpansion

:menu
cls
echo Welcome Home!
timeout /t 3 >nul
cls
echo Batch RPG Game!
echo ---------------
echo.
echo 1) Begin
echo.
echo 2) Exit
echo.
set /p input=C:\

if "%input%" == "1" goto name
if "%input%" == "2" exit
goto menu

:name
cls
echo Please select a name!
echo ---------------------
echo.
set /p name=Name:
cls
echo Is "%name%" correct?
echo ------------------
echo.
echo 1) Yes
echo.
echo 2) No
echo.
set /p input=C:\
if "%input%" == "1" goto new
if "%input%" == "2" goto name
goto name

:new
cls
set hp=100
set mhp=30
set pdmg=10
set mdmg=3
set lvl=1
set pexp=0
echo Would you like to battle an enemy?
echo ----------------------------------
echo.
echo 1) Yes
echo.
echo 2) No
echo.
set /p input=C:\

if "%input%" == "1" goto encounter1
if "%input%" == "2" goto new
goto new

:new2
cls
set hp=100
set mhp=30
set pdmg=10
set mdmg=3
echo Would you like to battle an enemy?
echo ----------------------------------
echo.
echo 1) Yes
echo.
echo 2) No
echo.
set /p input=C:\

if "%input%" == "1" goto encounter1
if "%input%" == "2" goto new
goto new

:encounter1
cls
echo %name% Level: %lvl%
echo Damage: %pdmg%
echo Health: %hp%
echo.
echo Skeleton Level: 1
echo Damage: %mdmg%
echo Health: %mhp%
echo.
echo.
echo What would you like to do?
echo --------------------------
echo.
echo 1) Attack
echo.
echo 2) Run
echo.
set /p input=C:\

if "%input%" == "1" goto attack
if "%input%" == "2" goto new
if "%input%" == " " goto encounter1
goto encounter1

:attack
cls
echo You are now attacking the enemy!
echo --------------------------------
timeout /t 2 >nul
echo.
echo The enemy is now attacking you!
echo -------------------------------
echo.
timeout /t 1 >nul
set /a hp=%hp% - %mdmg%
set /a mhp=%mhp% - %pdmg%

if %hp% == leq 0 goto lose
if %mhp% == leq 0 goto win
goto encounter1

:win
echo     You Win!    
echo ----------------
echo.
set /a pexp=%pexp%+25
echo 25 EXP Awarded! You now have %pexp%!
timout /t 1 >nul
echo.
echo.
echo Returning Home!
timeout /t 5 >nul
goto new2

:lose
echo     You Lost!    
echo -----------------
timeout /t 1 >nul
echo.
echo.
echo Returning Home!
timeout /t 5 >nul
goto new

我认为错误行为的原因就在底部附近。但是当你运行它时,它会继续战斗,即使我要求它说你在怪物达到0或更低的生命值时获胜。我认为这是IF声明,但我不能证明这一点。我是初学者,所以如果你可以进行任何其他调整以使我的代码更紧凑,那也会有所帮助:D!

0 个答案:

没有答案