为什么我的损坏系统不会起作用(它不会带走健康)

时间:2017-02-22 23:10:49

标签: batch-file

所以我制作了一个RPG,我希望我的伤害系统不是随意的。我用set health - =%monsterdmg%然后我用set monsterhealth - =%playerdmg%这里是我的整个代码也没做完:

@echo off
echo Welcome To Notetopia! We Hope You Enjoy!
pause
goto set
:set
set health=100
set monsterhealth=50
set playerdmg=20
set monsterdmg=7
goto home
:home
cls
echo What do you want to do?
echo 1) BATTLE!
echo 2) Exit :'(
set /p a= Select 1 or 2 
if %a%==1 goto battle1
if %a%==2 goto exitmenu
:battle1
set health=100
cls
echo Your Health: %health%
echo Enemie's Health: %monsterhealth%
echo.
echo.
echo Choose:
echo 1) Attack
echo 2) Run Away
set /p b= Select 1 or 2 
if %b%==1 goto attack1
if %b%==2 goto home
:attack1
cls
set health -= %monsterdmg%
set monsterhealth -= %playerdmg%
goto battle1

1 个答案:

答案 0 :(得分:0)

使用缺少的/ A选项时,可以像这样编写SET语句。

set /a health-=monsterdmg
set /a monsterhealth-=playerdmg

您无需使用百分号来扩展变量。

编辑。这是我玩清除屏幕的游戏。我还删除了战斗功能中的set health=100。当然看起来数学运算正常。

What do you want to do?
1) BATTLE!
2) Exit :'(
Select 1 or 2 1
Your Health: 100
Enemie's Health: 50


Choose:
1) Attack
2) Run Away
Select 1 or 2 1
Your Health: 93
Enemie's Health: 30


Choose:
1) Attack
2) Run Away
Select 1 or 2 1
Your Health: 86
Enemie's Health: 10


Choose:
1) Attack
2) Run Away
Select 1 or 2 1
Your Health: 79
Enemie's Health: -10


Choose:
1) Attack
2) Run Away
Select 1 or 2