基于文本的批量游戏演示,编码错误

时间:2014-09-06 02:33:31

标签: batch-file

好的,所以,我正在制作一个粗略的基于文本的批量游戏演示,它是一款剑斗游戏......我之前从未使用任何编码,我自学了我能做到最好......我知道这是一种非常原始且易于学习的语言,但我不太明白我做错了什么......它不会对你或敌人造成伤害,统计随机数发生器有时会给出等于或低于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

1 个答案:

答案 0 :(得分: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循环返回输入即可。