好的,所以我有这个小游戏,我正在这台Windows XP计算机上批量编写。当我运行以下代码时,我得到“此时没有预料到”(对不起,它真的很长,我还没有把它缩小。注意我没有要求你让我代码较小,所以请不要这样做):
@echo off
set str=0
set int=0
set agi=0
set dex=0
goto chrselect
:chrselect
cls
echo Character select!
echo.
echo 1) mage
echo.
echo 2) swords man
echo.
echo 3) archer
set /p start=-
if %start%==1 goto skillsetupm
if %start%==2 goto skillsetups
if %start%==3 goto skillsetupa
:skillsetupm
set health=50
set mana=100
set str=3
set int=6
set agi=5
set dex=4
set chr=m1
goto skillsee
:skillsetups
set health=100
set mana=50
set str=6
set int=4
set agi=3
set dex=5
set chr=s1
goto skillsee
:skillsetupa
set health=75
set mana=75
set str=3
set int=4
set agi=6
set dex=5
set chr=a1
goto skillsee
:skillsee
cls
echo Skills as is:
echo.
echo Strength: %str%
echo Intelligence: %int%
echo Agility: %agi%
echo Dexterity: %dex%
echo.
echo 1) Choose new character
echo.
echo 2) Continue to see how stats influence combat!
set /p start=-
if %start%==1 goto chrselect
if %start%==2 goto skillc
:skillc
set /a handattk=3+%str%
set /a magicattk=2+%str%+%dex%
set /a block=%agility%+%dex%
set /a blockchnc=%block%*5
set /a bowattk=3+%str%+%dex%
set /a swrdattk=4+%str%+%dex%
set /a slowchnc=%str%*4
if %chr%==m1 goto skillcinf
if %chr%==s1 goto skillcinf
if %chr%==a1 goto skillcinf
:skillcinf
cls
echo Skill stuff!
echo.
echo Hand attack: %handattk%
echo.
echo Block chance: %blockchnc% %
echo.
echo Slow chance: %slowchnc% %
echo.
if %chr%==m1 echo Magic attack: %magicattk%
if %chr%==s1 echo Sword attack: %swrdattk%
if %chr%==a1 echo Bow attack: %bowattk%
echo.
echo 1) Choose new character(last chance)
echo.
echo 2) Start game
set /p start=-
if %start%==1 goto chrselect
if %start%==2 goto menue
:menue
cls
set bossh=500
set exp=0
set playcount=0
echo Health:///%health%///
echo Mana:////%mana%////
echo Experience:////%exp%/////
echo Play count: %playcount%
echo Battle?(y/n)
set /p start=-
if %start%==y goto battle
if %start%==n goto menue
:battle
set /a playcount=%playcount%+1
cls
echo Health:///%health%///
echo Mana:////%mana%////
echo Experience:////%exp%/////
echo Play count: %playcount%
echo Attack Dragon(Health:%bossh%) with?
echo.
echo 1-Hand(%handattk% damage)
echo.
echo 2-Block(%blockchnc% % chance of blocking)
echo.
if %chr%==m1 echo 3-Magic attack(%magicattk% damage)
if %chr%==s1 echo 3-Sword Attack(%swrdattack% damage)
if %chr%==a1 echo 3-Bow Attack (%bowattk% damage)
set /p start=-
pause >nul
if %start%==1 set /a bossh=%bossh%-%handattk%
if %start%==2 set /a blockrandm=%random% %%100
goto battle2
if %start%==3 goto spclattk
:spclattk
cls
if %chr%==m1 set /a bossh=%bossh%-%magicattk%%
if %chr%==s1 set /a bossh=%bossh%-%swrdattk%
if %chr%==a1 set /a bossh=%bossh%-%bowattk%
goto battle2
:battle2
if %bossh% leq 0 goto win
set /a bossd=%random% %%5
if %blockrandm%==%blockchnc% set bossd=0
set /a health=%health%-%bossd%
cls
echo Health:///%health%///
echo Mana:////%mana%////
echo Experience:////%exp%/////
echo Play count: %playcount%
echo Attack Dragon(Health:%bossh%) with?
echo.
echo 1-Hand(%handattk% damage)
echo.
echo 2-Block(%blockchnc% % chance of blocking)
echo.
if %chr%==m1 echo 3-Magic attack(%magicattk% damage)
if %chr%==s1 echo 3-Sword Attack(%swrdattack% damage)
if %chr%==a1 echo 3-Bow Attack (%bowattk% damage)
set /p start=-
if %start%==1 set /a bossh=%bossh%-%handattk%
if %start%==2 set /a blockrandm=%random% %%100
if %start%==3 goto battleattk
goto battle2
任何时候我进入:战斗屏幕并按下我预设的选项,此时不会被预料到。
答案 0 :(得分:3)
当您到达%blockrandm%
时,您的变量:battle2
未初始化,因此第148行的比较显示
if ==0 set bossd=0
这显然是无效的语法。您可以通过引用比较的两面来避免它(在编写此类代码时几乎在所有情况下都是伟大的想法)。
供将来参考:删除echo off
并至少看看哪条线是负责的,通常也是为什么它失败。