2017-10-12 32 views
0

好的,所以我製作了一個批處理遊戲,現在我正在通過教程編寫代碼。我的計劃是使滾%%當我輸入內容時,批量程序出現意外

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 

以上是我的代碼。當我爲FIRST框輸入1,然後單擊enter時,它會彈出一個閃爍的「1意外...」或類似的內容。有想法該怎麼解決這個嗎? 全部代碼在這裏: https://pastebin.com/kBNgNV1G

+0

'|。'是一批特殊字符不要使用它(或使用'^ |'如果你絕對必須使用它)。 – SomethingDark

+0

滑稽,當我運行沒有問題代碼,只有當我輸入1:/ – spokify

+0

嗨,感謝您的幫助。雖然它沒有修復代碼,但它幫助我調試代碼:) 編輯:沒關係,我遇到了另一個bug,並使用^ |幫助過我。謝謝。 – spokify

回答

0

我做了一些變化,有些是修復其他的都希望能夠幫助你看到的做事方式不同,*(主要使用的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 
+0

修復了我的問題,謝謝。不確定我會使用選項/ c,因爲我只是想讓選擇系統保持原樣。但是謝謝你的解決方案 – spokify