RPG游戏损坏问题

时间:2019-09-20 14:44:57

标签: batch-file

我正在尝试制作RPG风格的游戏,当我攻击敌人时,它不会造成任何伤害,并且敌人会将我的生命值设为-3,有人可以帮助我吗?

@echo off
title RPG BETA
color 0b

set /p player=Welcome to Xero, what's your name?:
cls
echo Hello %player%!
pause
goto start
rem easteregg
if '%player%'=='Niko' goto win
if '%player%'=='nko' goto win

:start
echo In the distant future, the world was on the brink of destrucion.
timeout 3 /nobreak >nul
echo In the midst of the wasteland, a single man, named %player%, will overcome the odds
pause
goto BFight

:BFight
cls
set CPU=20
set CPUN=Scorpion
set gun=1
set gund=10
set playerh=20
:Fight
cls
if '%CPU%'=='0' goto win
if '%playerh%'=='0' goto lose
cls
echo You encounter a %CPUN%!

echo                            %CPUN% Health: %CPU%
echo.
echo                            Your Health: %playerh%

echo [1]Shoot (%gund%) (%gun%)
echo [2]Punch (3 damage)
echo [3]Flee

set /p fp=What do you do?
if 'fp'=='1' goto gun
if 'fp'=='2' goto punch
if 'fp'=='3' goto flee

:gun
if '%gun%'=='0' goto egun
set /a %gun%=-1
echo You fire at the %CPUN%
timeout 4 >nul
echo It hits!
set /a %CPU%=-%gund%
pause
goto cpufight

:egun
echo You have no bullets!
pause
goto Fight

:punch
echo You punch the %CPUN%
timeout 4 >nul
echo It hits!
set /a CPU=-3
pause
goto cpufight

:cpufight
echo The %CPUN% Attacks!
timeout 4
echo It hits!
set /a playerh= -3
pause
goto fight

:win
cls
echo Congradulations, %player%! You win!
pause

注意:游戏还没有结束,但是如果您玩了游戏,您应该能够知道攻击是如何进行的。我还没有设置逃跑选项。

1 个答案:

答案 0 :(得分:0)

此代码存在几个小问题。我认为这是一个家庭作业问题,而不是您自己开发的东西?

扣除损坏值

在扣除值以显示损坏或正在使用的枪弹时存在问题。示例包括:

week

变量的命名没有百分号,因此在使用class Character { constructor(name, weapon) { this.name = name; this.weapon = weapon; } attack(){ console.log(this.name +' attacks with ' +this.weapon); } } class Elf extends Character { constructor(name, weapon, type) { super(name, weapon); this.type = type; } magicAttack() { console.log(this.name + ' chants '); setTimeout(()=>{ console.log(this.type); }, 3000); } } const aeri = new Elf("Aeri", "bow", "air") const bob = new Character("Bob", "yawn") bob.attack() aeri.magicAttack()时应将set /a %gun%=-1 set /a %CPU%=-%gund% set /a CPU=-3 命名为%GUN%。另外,在执行算术运算时,代码GUN不会减一。它将SET设置为等于x =- 1

以下是对上述内容的更正:

x

收集输入并进行比较

“命令”部分的另一个问题是您在-1中处理命令结果:

SET /a gun = gun - 1
SET /a CPU = CPU - gund
SET /a CPU = CPU - 3

这基本上是说文本 fp是否等于文本 if 'fp' == '1' goto gun if 'fp' == '2' goto punch if 'fp' == '3' goto flee 。显然,这是行不通的。您需要对此进行修改,以使用变量fp的值和数字(删除1):

fp

赢得比赛

最后一个问题是,当玩家或CPU达到0或更低的生命值时,您要计算结束游戏。您当前有:

'

这再次将 text if %fp% == 1 goto gun if %fp% == 2 goto punch if %fp% == 3 goto flee if '%CPU%'=='0' goto win if '%playerh%'=='0' goto lose CPU textual 值进行比较。删除playerh个字符:

0

但是,这仅在健康状况达到0时才有效。如果健康状况低于0 ,则永远不会发生。您需要查找0或以下的值:

'