1

好的,所以我在这台 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

每当我进入 :battle 屏幕并按下一个选项时,我都没有预料到我会被设置。

4

1 回答 1

3

当您到达时,您的变量%blockrandm%未初始化,:battle2因此第 148 行的比较显示为

if ==0 set bossd=0

这显然是无效的语法。您可以通过引用比较的双方来避免它(在编写此类代码时,这在几乎所有情况下都是一个好主意)。

供将来参考:删除echo off并且您至少可以看到是哪条线路负责,并且通常还会看到它失败的原因。

于 2012-06-27T16:51:16.583 回答