代码之家  ›  专栏  ›  技术社区  ›  user7039042

键入内容时意外的批处理程序

  •  0
  • user7039042  · 技术社区  · 7 年前

    好的,我做了一个批量游戏,我现在正在写教程。我的计划是做%roll%

    set /a roll=(%random% %% 7) + 1
    

    能够带走 %enhealth% %yourhealth%

    :foresttutorial
    cls
    echo.
    echo   __________________________
    echo  |                          |
    echo  | An enemy appeared!       |
    echo  | Enemy health: %enhealth% |
    echo  | Your health: %yourhealth%|
    echo  |                          |
    echo  | 1. ATK    2. USE POT     |
    echo  | 3. GOLD   4. PASS        |
    echo  | _________________________|
    echo.
    echo Here appears an attack screen!
    echo Quick, press 1 and enter!
    set /p choice8
    if %choice8% == 1 goto atkforesttutorial1 else goto invalidforesttutorial1
    
    :invalidforesttutorial1
    cls
    echo Invalid answer. You can try the other options soon,
    echo for now just press 1.
    pause
    goto foresttutorial
    
    :atkforesttutorial1
    set /a roll=(%random% %% 7) + 1
    set enhealth = %enhealth% - %roll%
    echo You attacked the enemy!
    echo.
    echo   __________________________
    echo  |                          |
    echo  | An enemy appeared!       |
    echo  | Enemy health: %enhealth% |
    echo  | Your health: %yourhealth%|
    echo  |                          |
    echo  | 1. ATK    2. USE POT     |
    echo  | 3. GOLD   4. PASS        |
    echo  | _________________________|
    echo.
    pause
    

    以上是我的代码。当我在第一个框中输入1,然后单击enter,它会弹出一个flash,上面写着“1出乎意料…”或者类似的东西。关于如何解决这个问题有什么想法吗? 此处为完整代码: https://pastebin.com/kBNgNV1G

    1 回复  |  直到 7 年前
        1
  •  0
  •   Compo    7 年前

    我做了一些修改,一些是修复,其他的希望能帮助你看到一种不同的做事方式,*(主要是使用 Choice /C 用于输入选择和 Call :label 尽量减少重复回声文本。

    @Echo Off
    If /I Not "%CD%"=="directoryForscreed" CD /D "directoryForscreed" 2>Nul||Exit/B
    For %%A In ("premenupicture" "dice" "atkmenusample" "mainmenuforscreed"
    ) Do If Not Exist "%%A.txt" Exit/B
    Title Forscreed
    Color 07
    Mode 80,25
    
    :premenu
    Echo=
    Type premenupicture.txt
    Echo=
    Choice /C 123 /M "Please type in your choice number: "
    If ErrorLevel 3 GoTo credits
    If ErrorLevel 2 GoTo loadgame
    If ErrorLevel 1 GoTo newgame
    ClS
    GoTo premenu
    
    :newgame
    Set/A "key=chest=level=rank=gold=playwon=playloss=enwon=enloss=dice=prestige=0"
    Set/A "atk=def=int=vit=1"
    Set "health=100"
    
    :prologue
    ClS
    Echo Wake up..
    Timeout 2 /NoBreak>Nul
    ClS
    Echo Wake up!
    Timeout 2 /NoBreak>Nul
    ClS
    Call :prologEcho
    Choice /C 1234
    If ErrorLevel 4 GoTo tutorialfinish1
    If ErrorLevel 3 GoTo caveprologue
    If ErrorLevel 2 GoTo scavengeprologue
    If ErrorLevel 1 GoTo prologueboat
    GoTo prologue
    
    :prologueboat
    ClS
    Call :prologueboatEcho
    Choice /C 1234
    If ErrorLevel 4 GoTo prologue
    If ErrorLevel 3 GoTo prologuemast
    If ErrorLevel 2 GoTo prologuecaptaincabin
    If ErrorLevel 1 GoTo prologuedeck
    GoTo prologueboat
    
    :prologuedeck
    ClS
    Echo The deck is empty, except for a satchel. You reach inside and find a Rusty
    Echo Pistol and equip it. You walk out off the deck.
    Timeout -1
    
    :prologueboat2
    ClS
    Call :prologueboatEcho
    Choice /C 1234
    If ErrorLevel 4 GoTo prologue
    If ErrorLevel 3 GoTo prologuemast
    If ErrorLevel 2 GoTo prologuecaptaincabin
    If ErrorLevel 1 GoTo prologuedeck2
    GoTo prologueboat2
    
    :prologuedeck2
    ClS
    Echo Nothing here!
    Timeout -1
    GoTo prologueboat2
    
    :prologuecaptaincabin
    ClS
    Echo The captain's cabin is tiny. Cramped up, you walk into the room. There is a
    Echo bag of gold, a magazine for a pistol, and an old pair of boots. You walk out
    Echo of the captain's cabin.
    Timeout -1
    
    :prologueboat3
    ClS
    Call :prologueboatEcho
    Choice /C 1234
    If ErrorLevel 4 GoTo prologue
    If ErrorLevel 3 GoTo prologuemast
    If ErrorLevel 2 GoTo prologuecaptaincabin2
    If ErrorLevel 1 GoTo prologuedeck2
    GoTo prologueboat3
    
    :prologuecaptaincabin2
    ClS
    Echo Nothing here!
    Timeout -1
    GoTo prologueboat3
    
    :prologuemast
    ClS
    Echo You climb up the mast. Nothing here! You can use the ropes though, so you
    Echo take it off.
    Timeout -1
    
    :prologueboat4
    ClS
    Call :prologueboatEcho
    Choice /C 1234
    If ErrorLevel 4 GoTo prologue
    If ErrorLevel 3 GoTo prologuemast2
    If ErrorLevel 2 GoTo prologuecaptaincabin2
    If ErrorLevel 1 GoTo prologuedeck2
    GoTo prologueboat4
    
    :scavengeprologue
    ClS
    Echo A dice appeared! What do you do with it? Shrugging, you put it in your pocket.
    Echo (You can't scavenge anymore after this until you finish the tutorial!)
    Set/A dice+=1
    Timeout -1
    
    :prologue2
    ClS
    Call :prologEcho
    Choice /C 1234
    If ErrorLevel 4 GoTo tutorialfinish1
    If ErrorLevel 3 GoTo caveprologue
    If ErrorLevel 2 GoTo scavengeprologue2
    If ErrorLevel 1 GoTo prologueboat
    GoTo prologue2
    
    :scavengeprologue2
    ClS
    Echo Can't scavenge in the tutorial! Complete the tutorial first, then you can
    Echo scavenge again.
    Timeout -1
    GoTo prologue2
    
    :caveprologue
    Cls
    Echo You walk to the cave and find a warm fire lit up. How was it lit? You don't
    Echo know. You quickly scramble to near the fire for warmth, satisfied.
    Timeout -1
    GoTo prologue
    
    :tutorialfinish1
    ClS
    Echo You pull out what you found from your pockets. A rusty gun, a magazine for
    the gun, and a dice. I wonder what the dice does?
    Timeout -1
    ClS
    Echo The dice rolls in your hand, and you accidentally drop it. It glows golden!
    Timeout -1
    ClS
    Timeout 1 /NoBreak>Nul
    Type dice.txt
    Echo=
    Echo Rolling a 7-sided die...
    Timeout 2 /NoBreak>Nul
    Set/A roll=(%random% %% 7) + 1
    Echo You landed a %roll%!
    Timeout -1
    ClS
    Echo Your objective is to build up a boat to go find the artifacts which end the
    Echo game. The game is frequently updated, so check on the website for more quests
    Echo and islands, plus new artifacts. The main playing style is fighting,
    Echo equipping, trading, buying, leveling, and surviving as best as you can.
    Timeout -1
    ClS
    Type atkmenusample.txt
    Echo This is what you'll get upon questing or fighting in the woods! Monsters drop
    Echo food, which is what you need to survive. You lose health every time do you a
    Echo task, an estimated 0.712 health taken. You can regain the health with food. To
    Echo fight, you will normally type in 1 and attack. The golden dice will do
    Echo everything for you! The formula consists of your strength, weapons, and the
    Echo dice rolled.
    Timeout -1
    ClS
    Echo Then, the enemy takes his turn to attack! The computer will calculate all of
    Echo this for you, and deal in the damage. Press 2 to use a health potion, and
    Echo press 3 to your gold. If you're feeling it, you can also pass your turn,
    Echo allowing the enemy to go. Other that fighting, the game is really mainly about
    Echo a mystery storyline, which often requires equipment, gold, and equipment from
    Echo quests. You can level up tools this way too. One of the special things about
    Echo Forscreed is that there are no "different" swords. It simply levels up your
    Echo swords to deal more damage.
    Timeout -1
    ClS
    Echo Let's give attacking a try!
    Echo Travel to the main menu:
    Timeout -1
    
    :mainmenututorial
    ClS
    Echo Here we are, at the tutorial. When this tutorial ends, it should look a bit
    Echo like this:
    Echo=
    Type mainmenuforscreed.txt
    Echo=
    Echo Above is the main menu. You're going to want to attack, so let's hit 1.
    Choice /C 1
    If Not Errorlevel 1 goto invalidmainmenututorial1
    GoTo foresttutorial
    
    :invalidmainmenututorial1
    ClS
    Echo Invalid answer. You can try the other options soon, for now just press 1.
    Timeout -1
    GoTo mainmenututorial
    
    :foresttutorial
    ClS
    Echo=
    Echo   __________________________
    Echo  ^|                          ^|
    Echo  ^|    An enemy appeared!    ^|
    Echo  ^| Enemy health: %enhealth% ^|
    Echo  ^| Your health: %yourhealth%^|
    Echo  ^|                          ^|
    Echo  ^|   1. ATK    2. USE POT   ^|
    Echo  ^|   3. GOLD   4. PASS      ^|
    Echo  ^| _________________________^|
    Echo=
    Echo Here appears an attack screen! Quick, press 1!
    Choice /C 1
    If Not ErrorLevel 1 GoTo invalidforesttutorial1
    GoTo atkforesttutorial1
    
    :invalidforesttutorial1
    ClS
    Echo Invalid answer. You can try the other options soon, or now just press 1.
    Timeout -1
    GoTo foresttutorial
    
    :atkforesttutorial1
    ClS
    Set/A roll=(%random% %% 7) + 1
    Set/A enhealth-=roll
    Echo You attacked the enemy!
    Echo=
    Echo   __________________________
    Echo  ^|                          ^|
    Echo  ^|    An enemy appeared!    ^|
    Echo  ^| Enemy health: %enhealth% ^|
    Echo  ^| Your health: %yourhealth%^|
    Echo  ^|                          ^|
    Echo  ^|   1. ATK    2. USE POT   ^|
    Echo  ^|   3. GOLD   4. PASS      ^|
    Echo  ^| _________________________^|
    Echo=
    Timeout -1
    
    Exit/B
    
    :prologEcho
    Echo The sea is glimmering.. A broken boat seems to have crashed against a huge
    Echo wooden rod. A spiritual tomb of some sort! You remember now. The Queen of
    Echo Walkers sent you on a mission to save the kingdom by finding an artifact on
    Echo the other side of the world, but you faced a storm and crashed into this
    Echo wooden tomb.
    Echo=
    Echo Night is falling quick, what will you do?
    Echo 1. Go to the boat.
    Echo 2. Scavenge for resources.
    Echo 3. Look around that cave nearby, looks fishy.
    Echo 4. I already did all of these.
    GoTo :EOF
    
    :prologueboatEcho
    Echo You walk to the boat. It's broken at the side, so it can't be used. The
    Echo material is also weak. It's been thrashed by heavy waves and can't sail.
    Echo Where do you search on the boat?
    Echo 1. The deck
    Echo 2. The captain's cabin
    Echo 3. The mast
    Echo 4. Get off boat
    GoTo :EOF