我在批处理RPG中处理if语句时遇到了一些麻烦。因此,当你在教程战斗中击败第一只狼时,流程会跳到:胜利,从那里到:LevelUp,那就是它崩溃的地方。如果它没有检查级别的if语句就可以正常工作,问题是它仍然使字符升级,好像第二个if语句(检查playerEXP小于65的那个)不存在。 我用if语句犯了什么错误?
:StartAdventure
call :PlayerStats
call :Save
echo/
if %sex% == 1 echo His blood boiling with the thirst of adventure, he couldn't wait to get the
if %sex% == 2 echo Her blood boiling with the thirst of adventure, she couldn't wait to get the
echo chance to enlist in Kovalor's army. The deadliest force in the history of Vinladia.
pause >nul
echo/
echo Meanwhile, %name% had to defend the farm's lifestock from frequent attacks by wolves and other
echo vermin.One could see the edge of the woods a few meters away from the tool shed. Everything
echo that was used in %name%'s obligations was there.
pause >nul
@set checkpoint=1
call :Save
:Checkpoint1
echo/
echo A wolf approached from the forest, while %name% tilled the carrot patch, its eyes locked on a stray
echo sheep. Losing a sheep was as good as losing a month's food. %name% sprung into action.
pause >nul
cls
call :GrayWolf1
call save%name%.bat
call :BattleSystemTut
cls
echo/
echo With the wolf dead, %name% was able to rest for the afternoon.
@set /a playerHP=%playerMAXHP%
pause >nul
@set checkpoint=2
call :Save
:Checkpoint2
echo/
echo Next morning was as boring as any other. Get up, get dressed, feed and water the lifestock and mind
echo the fields.
echo Torwards the end of the day, there was sudden movement near the town of Dagoba, which was visible
echo from the hill %name% always rested on in the evenings.
pause >nul
echo/
echo Screams could be heard and columns of smoke started appearing above the buildings. %name% lived
if %sex% equ 1 echo alone on his farm. He was becoming afraid of the raiders, whose presense was now obvious, to make
if %sex% equ 2 echo alone on her farm. She was becoming afraid of the raiders, whose presense was now obvious, to make
echo their way up there and loot %name%'s home.
pause >nul
echo/
echo A wolf darted out of the woods, bloodthirsty and mad. It made for %name%.
pause >nul
call :GrayWolf1
call save%name%.bat
call :BattleSystem1
cls
echo/
echo There was something about the eyes of the wolf that made %name% think that its attack wasn't a
echo simple matter of being scared, there was fire in his pupils.
pause >nul
echo/
echo %name% decided to investigate a pillar of smoke miles west of Dagoba, but just a few minutes' walk
echo from %name%'s farm.
pause >nul
set checkpoint=3
call save%name%.bat
call :Save
:Checkpoint3
cls
echo/
echo %name% is now at the entrance of the Dagoba Forest.
goto :ForestEntrance1
:ForestEntrance1
echo/
echo %name% proceeds by...
echo ----------------------------------------
echo -----F-Following the path forward-------
echo ----------------------------------------
echo -----I-Looking into the Invenory--------
echo ----------------------------------------
if %sex% equ 1 echo -----S-Taking a look at his status------
if %sex% equ 2 echo -----S-Taking a look at her status------
echo ----------------------------------------
echo -----M-Menu-----------------------------
echo ----------------------------------------
choice.exe /C fism /N
goto Option%ERRORLEVEL%
:Option1
echo %name% walks in a little bit further.
pause>nul
goto :Forest1-1
:Option2
call :Inventory
:Option3
call :ShowStats
:Option4
call :PauseMenu
:Forest1-1
set checkpoint=4
call save%name%.bat
call :Save
:Checkpoint4
cls
echo/
echo %name% is surrounded by plant life, with the faint sound of animals rustling the bushes and
echo the smell of smoke in the air.
goto :Forest1
:Forest1
echo/
echo %name% proceeds by...
echo ----------------------------------------
echo -----F-Following the path forward-------
echo ----------------------------------------
echo -----B-Backtrack------------------------
echo ----------------------------------------
echo -----I-Looking into the Invenory--------
echo ----------------------------------------
if %sex% equ 1 echo -----S-Taking a look at his status------
if %sex% equ 2 echo -----S-Taking a look at her status------
echo ----------------------------------------
echo -----M-Menu-----------------------------
echo ----------------------------------------
choice.exe /C fbism /N
goto Option%ERRORLEVEL%
:Option1
echo %name% walks further into the forest.
pause >nul
goto :Forest1-2
:Option2
echo %name% walks back to the entrance of the Dagoba Forest.
pause>nul
goto :Checkpoint3
:Option3
call :Inventory
:Option4
call :ShowStats
:Option5
call :PauseMenu
:Forest1-2
set checkpoint=5
call save%name%.bat
call :Save
:Checkpoint5
cls
echo/
echo The smell of smoke is getting stronger just like the sounds from the woods. There may be
echo a creature lurking between the leaves.
echo The path continues forward. The light from outside the forest is nearly blocked altogether
echo due to the density of the foliage.
goto :Forest2
:Forest2
echo/
echo %name% proceeds by...
echo ----------------------------------------
echo -----F-Following the path forward-------
echo ----------------------------------------
echo -----B-Backtrack------------------------
echo ----------------------------------------
echo -----I-Looking into the Invenory--------
echo ----------------------------------------
if %sex% equ 1 echo -----S-Taking a look at his status------
if %sex% equ 2 echo -----S-Taking a look at her status------
echo ----------------------------------------
echo -----M-Menu-----------------------------
echo ----------------------------------------
choice.exe /C fbism /N
goto Option%ERRORLEVEL%
:Option1
goto :Forest1-3
:Option2
goto :Forest1
:Option3
call :Inventory
:Option4
call :ShowStats
:Option5
call :PauseMenu
:Forest1-3
set checkpoint=6
call save%name%.bat
call :Save
:Checkpoint6
cls
echo/
echo There is very loud rustling coming from the bushes.
SET /A randomEnc=%RANDOM% * 3 / 32768 + 1
if %randomEnc% equ 3(call save.%name%.bat
call :GrayWolf1
call :BattleSystem1
)else(echo The creature appears to have gone away.)
goto :Forest3
:Forest3
echo/
echo %name% proceeds by...
echo ----------------------------------------
echo -----F-Following the path forward-------
echo ----------------------------------------
echo -----B-Backtrack------------------------
echo ----------------------------------------
echo -----I-Looking into the Invenory--------
echo ----------------------------------------
if %sex% equ 1 echo -----S-Taking a look at his status------
if %sex% equ 2 echo -----S-Taking a look at her status------
echo ----------------------------------------
echo -----M-Menu-----------------------------
echo ----------------------------------------
choice.exe /C fbism /N
goto Option%ERRORLEVEL%
:Option1
goto :Forest1-4
:Option2
goto :Forest2
:Option3
call :Inventory
:Option4
call :ShowStats
:Option5
call :PauseMenu
::--------------------------------------------------------------------------------------------------------
:::::::::::::::Main Game::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::Player Stats:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::--------------------------------------------------------------------------------------------------------
:PlayerStats
@set playerHP=25
@set playerMAXHP=25
@set playerATK=5
@set playerDEF=0
@set playerLVL=1
@set playerEXP=0
@set playerGLD=10
@set playerMP=0
@set playerMAXMP=0
exit /b
::--------------------------------------------------------------------------------------------------------
:::::::::::::::Player Stats:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::Show Stats:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::--------------------------------------------------------------------------------------------------------
:ShowStats
cls
call save%name%.bat
echo/
echo Level: %playerLVL% Experience Points: %playerEXP%
echo HP: %playerHP%/%playerMAXHP%
echo MP: %playerMP%/%playerMAXMP%
echo Attack: %playerATK%
echo Defense: %playerDEF%
echo Gold: %playerGLD%
echo/
echo Press any key to return.
pause >nul
goto :Checkpoint%checkpoint%
::--------------------------------------------------------------------------------------------------------
:::::::::::::::Show Stats:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::Battle System Tutorial:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::--------------------------------------------------------------------------------------------------------
:BattleSystemTut
echo/BATTLE START!
echo/
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo :%name% LVL: %playerLVL% Hp: %playerHP%/%playerMAXHP%:----:
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo/
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo :%enemy% HP: %enemyHP% :-----------------------:
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo *TUTORIAL* Here you can see your current HP (hit points) if they deplete, you die.
pause >nul
cls
echo/
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo :%name% LVL: %playerLVL% Hp: %playerHP%/%playerMAXHP%:----:
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo/
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo :%enemy% HP: %enemyHP% :-----------------------:
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo *TUTORIAL* Your level is also visible here. It's proof of the experiences you've had.
pause >nul
cls
echo/
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo :%name% LVL: %playerLVL% Hp: %playerHP%/%playerMAXHP%:----:
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo/
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo :%enemy% HP: %enemyHP% :-----------------------:
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo *TUTORIAL* Your enemy's name and HP are also visible.
pause >nul
cls
goto :FightMenuTut
:FightMenuTut
echo/
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo :%name% LVL: %playerLVL% Hp: %playerHP%/%playerMAXHP%:----:
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo/
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo :%enemy% HP: %enemyHP% :-----------------------:
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo/
echo -------------------
echo -----F-Fight-------
echo -------------------
echo -----S-Spells------
echo -------------------
echo -----I-Inventory---
echo -------------------
echo -----E-Escape------
echo -------------------
echo/
echo *TUTORIAL* Press the key that corresponds to your choice
choice.exe /C fsie /N /M "What will you do?"
goto Option%ERRORLEVEL%
:Option1
echo/
@set /a ATK=playerATK+itemATK
@set /a DAMG=ATK-enemyDEF
@set /a enemyHP=enemyHP-DAMG
echo ::::::::::::::::::::::::::::::::::
echo %enemy% received %ATK% damage.
echo ::::::::::::::::::::::::::::::::::
goto :EnemyAttackTut
:EnemyAttackTut
SET /A dice=%RANDOM% * %dieRoll% / 32768 + 1
echo/
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if %dice% equ 1 (set /a enemyATK=%dmgattack1%
echo %enemy% attacked with %attack1%)
if %dice% equ 2 (set /a enemyATK=%dmgattack2%
echo %enemy% attacked with %attack2%)
if %dice% equ 3 (set /a enemyATK=%dmgattack3%
echo %enemy% attacked with %attack3%)
if %dice% equ 4 (set /a enemyATK=%dmgattack4%
echo %enemy% attacked with %attack4%)
if %dice% equ 5 (set /a enemyATK=%dmgattack5%
echo %enemy% attacked with %attack5%)
@set /a playerHP=playerHP-enemyATK
echo %name% received %enemyATK% damage.
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if %enemyHP% lss 1 goto :VictoryTut
if %playerHP% lss 1 goto :GameOver
goto :FightMenuTut
:Option2
echo/
echo Your magics are not developed enough yet.
pause >nul
goto :FightMenuTut
:Option3
echo/
echo You have no items yet.
pause >nul
goto :FightMenuTut
:Option4
echo/
echo Escape is not an option now.
pause >nul
goto :FightMenuTut
:VictoryTut
cls
echo/
echo You are victorious!
echo *TUTORIAL* When you defeat an enemy you gain experience points.
echo Once you have enough experience you will gain a level, and that increases your
echo battle capabilities.
set /a playerEXP=playerEXP+enemyEXP
set /a playerGLD=playerGLD+enemyGLD
echo You gain %enemyEXP% experience points.
echo Your total experience points: %playerEXP%.
call :Save
pause >nul
if %enemyGLD% equ 0 call :LevelUp
if %enemyGLD% equ 1 (echo %name% found 1 gold piece.
call :LevelUp)
if %enemyGLD% gtr 1 (echo You found %enemyGLD% gold pieces.
call :LevelUp)
::--------------------------------------------------------------------------------------------------------
:::::::::::::::Battle System Tutorial:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::Battle System1:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::--------------------------------------------------------------------------------------------------------
:BattleSystem1
cls
echo/
echo BATTLE START!
goto:FightMenu1
:FightMenu1
echo/
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo :%name% LVL: %playerLVL% Hp: %playerHP%/%playerMAXHP%:----:
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo/
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo :%enemy% HP: %enemyHP% :-----------------------:
echo :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
echo/
echo -------------------
echo -----F-Fight-------
echo -------------------
echo -----S-Spells------
echo -------------------
echo -----I-Inventory---
echo -------------------
echo -----E-Escape------
echo -------------------
echo/
choice.exe /C fsie /N /M "What will you do?"
goto Option%ERRORLEVEL%
:Option1
echo/
@set /a ATK=playerATK+itemATK
@set /a DAMG=ATK-enemyDEF
@set /a enemyHP=enemyHP-DAMG
echo ::::::::::::::::::::::::::::::::::
echo %enemy% received %ATK% damage.
echo ::::::::::::::::::::::::::::::::::
goto :EnemyAttack1
:EnemyAttack1
SET /A dice=%RANDOM% * %dieRoll% / 32768 + 1
echo/
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if %dice% equ 1 (set /a enemyATK=%dmgattack1%
echo %enemy% attacked with %attack1%)
if %dice% equ 2 (set /a enemyATK=%dmgattack2%
echo %enemy% attacked with %attack2%)
if %dice% equ 3(SET /A result=%RANDOM% * 2 / 32768 + 1
if result equ 2 (set /a enemyATK=%dmgattack3%
echo %enemy% attacked with %attack3%)
)
if %dice% equ 4(SET /A result=%RANDOM% * 3 / 32768 + 1
if %dice% equ 3 (set /a enemyATK=%dmgattack4%
echo %enemy% attacked with %attack4%)
)
if %dice% equ 5(SET /A result=%RANDOM% * 4 / 32768 + 1
if %dice% equ 4 (set /a enemyATK=%dmgattack5%
echo %enemy% attacked with %attack5%)
)
@set /a playerHP=playerHP-enemyATK
echo %name% received %enemyATK% damage.
echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if %enemyHP% lss 1 goto :Victory
if %playerHP% lss 1 goto :GameOver
goto :FightMenu1
:Option2
echo/
echo Your magics are not developed enough yet.
pause >nul
goto :FightMenu1
:Option3
echo/
echo You have no items yet.
pause >nul
goto :FightMenu1
:Option4
echo/
echo Escape is not an option now.
pause >nul
goto :FightMenu1
:Victory1
cls
echo/
set /a playerEXP=playerEXP+enemyEXP
set /a playerGLD=playerGLD+enemyGLD
call :Save
echo You are victorious!
echo/
echo You gain %enemyEXP% experience points.
echo Your total experience points: %playerEXP%.
pause >nul
if %enemyGLD% equ 0 call :LevelUp
if %enemyGLD% equ 1 (echo %name% found 1 gold piece.
call :LevelUp)
if %enemyGLD% gtr 1 (echo You found %enemyGLD% gold pieces.
call :LevelUp)
::--------------------------------------------------------------------------------------------------------
:::::::::::::::Battle System1:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::Save System::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::--------------------------------------------------------------------------------------------------------
:Save
@echo @ECHO OFF > save%name%.bat
@echo SET "name=%name%" >> save%name%.bat
@echo SET "sex=%sex%" >> save%name%.bat
@echo SET "playerHP=%playerHP%" >> save%name%.bat
@echo SET "playerMP=%playerMP%" >> save%name%.bat
@echo SET "playerATK=%playerATK%" >> save%name%.bat
@echo SET "playerDEF=%playerDEF%" >> save%name%.bat
@echo SET "playerLVL=%playerLVL%" >> save%name%.bat
@echo SET "playerEXP=%playerEXP%" >> save%name%.bat
@echo SET "playerGLD=%playerGLD%" >> save%name%.bat
@echo SET "checkpoint=%checkpoint%" >> save%name%.bat
@echo SET "playerMAXHP=%playerMAXHP%" >> save%name%.bat
@echo SET "playerMAXMP=%playerMAXMP%" >> save%name%.bat
exit /B
::--------------------------------------------------------------------------------------------------------
:::::::::::::::Save System::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::Level Up System::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:LevelUp
call save%name%.bat
if !playerLVL! equ 1(
if !playerEXP! geq 30 (
if !playerEXP! lss 65 (echo/
echo Level Up! You are now level 2!
echo You gain +3 HP
echo +2 ATK
echo +1 DEF
echo/
set /a playerMAXHP="playerMAXHP+3"
set /a playerATK="playerATK+2"
set /a playerDEF="playerDEF+1"
set /a playerLVL="playerLVL+1"
pause >nul
goto :Save)
)else goto :Save
)
if !playerLVL! equ 2(
if !playerEXP! geq 65(
if !playerEXP! lss 115(echo/
echo Level Up! You are now level 3!
echo You gain +4 HP
echo +1 ATK
echo +2 DEF
echo +15 MP
set /a playerMAXHP="playerMAXHP+4"
set /a playerATK="playerATK+1"
set /a playerDEF="playerDEF+2"
set /a playerMAXMP="playerMAXMP+15"
set /a playerLVL="playerLVL+1"
pause >nul
goto :Save)
)
)else (goto :Save)
:::::::::::::::Level Up System::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::