2014-09-06 92 views
1

好吧,那麼,我正在製作一個粗略的基於文本的批處理遊戲演示,它是一款劍鬥遊戲......我以前從未使用過任何類型的編碼,我盡我所能地教了自己......我知道這是一個非常原始且容易學習的語言,但我不太明白我做錯了什麼......它不會對你或敵人造成傷害,並且統計隨機數發生器有時會給出等於或低於0的數字...我一直在調整,並以我不太明白的方式更改代碼,試圖修復它,所以代碼在某些部分可能有點奇怪,感覺自由建設性地批評,改進可能會發揮作用的部分,並且請找出所述的問題......(PS。它也被編程認定我是「創造者」和我的女朋友,並用她的暱稱給她打電話,但這很好,所以我把它從這段代碼中刪除。) 代碼:基於文本的批處理遊戲演示,編碼錯誤

@echo off 
color 02 
cls 
setlocal enabledelayedexpansion 
set file=AdventureTextMusic.mp3 
(echo Set Sound = CreateObject("WMPlayer.OCX.7"^) 
    echo Sound.URL = "%file%" 
    echo Sound.Controls.play 
    echo do while Sound.currentmedia.duration = 0 
    echo wscript.sleep 100 
    echo loop 
    echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000) >sound.vbs 
start /min sound.vbs 
title New Adventurer 
echo. 
echo Hello Adventurer! 
echo. 
echo may I ask your name? 
echo. 
set /p name= 
echo. 
if %name% equ Michelle goto bunni 
if %name% equ Stuart goto kitty 
if %name% neq Stuart goto random 
:bunni 
cls 
echo. 
echo Bunni? Welcome to my game! I worked hard on it, I don't know if it will be good... We'll see I guess!! 
set /a gold=%random% %% 25-1 
echo. 
echo Here's %gold% gold to get you started! I hope it helps! 
echo. 
set name=Bunni 
echo Good luck %name%! 
pause 
goto continue 
:kitty 
cls 
echo. 
echo Creator? Bug fixing I assume? I hope all is well in the land of Adventure Text! Good luck! 
set /a gold=%random% %% 25-1 
echo. 
echo Here's %gold% gold to get you started! I hope it helps! 
pause 
goto continue 
:random 
cls 
echo. 
echo That name suits you! Welcome %name%! To the land of Adventure Text! 
set /a gold=%random% %% 15-1 
echo. 
echo Here's %gold% gold to get you started! I hope it helps! 
echo. 
echo Good luck %name%! 
pause 
goto continue 
:continue 
cls 
echo The controls are simple, when it asks for your choice of attack, pick an option. 
echo. 
echo Slash does your weapons default damage, minus enemy armor strength, and takes no stamina 
echo. 
echo Slice does your weapons default damage, ignoring armor strength, and takes 2 stamina 
echo. 
echo whereas Stab does 1.5 damage, ignoring armor strength, but takes 4 stamina 
echo. 
pause 
cls 
echo. 
echo Would you like to begin, %name%? 
pause 
title %name%'s Quest 
cls 
set /a health=%random% %% 15-1 +2 
set /a armor=%random% %% 2-1 +2 
set /a damage=%random% %% 4-2 +2 
set /a stamina=%random% %% 15-8 +2 
echo. 
echo Health: %health% Gold: %gold% Armor Strength: %armor% Damage per Hit: %damage% Stamina: %stamina% 
pause 
cls 
echo. 
set /a number=%random% %% 2-1 
if %number% equ 1 goto Grunt 
if %number% equ 2 goto Guard 
:Guard 
set enemy=Guard 
set EHealth=12 
set EArmor=1 
set EDamage=1 
goto battle1 
:Grunt 
set enemy=Grunt 
set EHealth=10 
set EArmor=0 
set EDamage=2 
goto battle1 
:battle1 
echo An enemy %enemy% has spotted you! 
echo Enemy Health: %EHealth% Enemy Armor Strength: %EArmor% Enemy Damage: %EDamage% 
pause 
cls 
echo. 
goto turn1 
:turn1 
echo What would you like to do? 
echo 1) Slash 
echo 2) Slice 
echo 3) Stab 
set /p attack= 
if %attack% equ 1 goto slash 
if %attack% equ 2 goto slice 
if %attack% equ 3 goto stab 
:turn2 
echo Health: !health! Stamina: !stamina! 
if !EHealth! leq 0 goto end 
echo Enemy Health: !EHealth! 
echo Enemy turn! 
pause 
cls 
goto enemy 
:enemy 
set /a EAttack=%random% %% 3-1 
if %EAttack% equ 1 goto Eslash 
if %EAttack% equ 2 goto Eslice 
if %EAttack% equ 3 goto Estab 
if %EAttack% neq 3 goto enemy 
:Eslash 
set health-=!EDamage!-!armor! 
if !health1 leq 0 goto lose 
goto turn1 
:Eslice 
set health-=!EDamage! 
if !health! leq 0 goto lose 
goto turn1 
:Estab 
set EDamage*=1.5 
set health-=!EDamage! 
set EDamage/=1.5 
if !health! leq 0 goto lose 
goto turn1 
:slash 
set EHealth-=!damage!-!EArmor! 
goto turn2 
:slice 
if %stamina% lss 2 cls 
if %stamina% lss 2 echo. 
if %stamina% lss 2 echo You do not have enough stamina to Slice 
if %stamina% lss 2 goto turn1 
set EHealth-=!damage! 
set stamina-=2 
goto turn2 
:stab 
if %stamina% lss 4 cls 
if %stamina% lss 4 echo. 
if %stamina% lss 4 echo You do not have enough stamina to Stab 
if %stamina% lss 4 goto turn1 
set damage*=1.5 
set EHealth-=!damage! 
set damage/=1.5 
set stamina-=4-2 
goto turn2 
:lose 
cls 
echo. 
echo Im sorry %name%... but you lost... 
pause 
cls 
echo This game is in pre-alpha, I will likely be updating it to add the full story. 
echo Created by: SteweeBee 
pause 
taskkill /f /im "wscript.exe" 
exit 
:end 
cls 
echo. 
echo ----  ----  ---- [----] ------- ---- 
echo \ \ / \ // I I I  \ I I 
echo \ \ / \ // I I I I\ \I I 
echo \ \_/ /\ \_/ / I I I I \ I I 
echo \  /\  / I I I I \ I 
echo  ------  ------  [----] I___I \___I 
pause 
cls 
echo This game is in pre-alpha, I will likely be updating it to add the full story. 
echo Created by: SteweeBee 
pause 
taskkill /f /im "wscript.exe" 
exit 

回答

2
set /a health=%random% %% 15-1 +2 

上面的線是一樣的

set /a health=%random% %% 16 

,我想你想的:

set /a health=(%random% %% 15-1) +2 

以下行使用延遲擴展,但你不使用需要它的代碼(如循環中) - 您可以使用正常的擴展,如%health%

!health! 

此代碼將起作用,除非在打字時添加另一個字符,然後將失敗。變量attack也應該在set /p之前初始化,因爲set /p會記住如果沒有輸入按下enter,最後一次是什麼。輸入像1 2與空間將導致它也失敗(與&同上)。

set /p attack= 
if %attack% equ 1 goto slash 
if %attack% equ 2 goto slice 
if %attack% equ 3 goto stab 

它應該真的在最後檢查無效輸入 - 只是一個goto :get_input迴環輸入將做。