When you run this script it shows the HP for both of the pokemon when you press 1 and click enter it subtracts your attack hit points to the enemies hit points.(运行此脚本时,按1并单击Enter会显示两个口袋妖怪的生命值,它将您的攻击生命值减去敌人生命值。)
When you or the ememy hits 0 or less than 0 hit points it is supposed to stop and just show who won in the console log.(当您或敌人击中0或小于0的生命值时,它应该停止并只显示谁在控制台日志中获胜。) Instead it takes an extra hit to for it to show the message.(而是需要额??外的点击才能显示该消息。)
So if you are at -10 hp it takes one more hit.(因此,如果您的功率为-10 hp,则需要再承受一击。)
let firstFight = false;
while (!firstFight) {
let fightOptions = prompt("1. Fight, 2.Items, 3.Potions " + wildPokemon[0].name + ":" + wildPokemon[0].hp + " " + pokeBox[0].name + ":" + pokeBox[0].hp);
if (fightOptions == 1) {
if (!firstFight) {
if (wildPokemon[0].hp <= 0) {
console.log("You have won!");
firstFight = true;
} else {
let attack1 = wildPokemon[0].hp -= pokeBox[0].attack.hp;
console.log(wildPokemon[0].hp);
}
if (pokeBox[0].hp <= 0) {
console.log(wildPokemon[0] + " has killed you");
firstFight = true;
} else {
let attack2 = pokeBox[0].hp -= wildPokemon[0].attack.hp;
console.log(pokeBox[0].hp);
}
}
} else if (fightOptions == 2) {
} else if (fightOptions == 3) {
} else {
}
}
Are there any ways I can make this code more efficient?(有什么方法可以使这段代码更有效?)
ask by Neiko101 translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…