javascript - What's wrong with health and damage system
问题描述
I'm not exactly the best at coding and I'm trying to work on a game. I've been working on a system to make it so that the player will take damage from attacks but it doesn't seem to work. Right now I'm practicing the health system on Codehs so I can figure out what the issue is. I'm using the JavaScript Console code. The problem is that whenever the player takes damage and I ask them to take it again, the health resets back to 100. I'm including the code that I'm using for this if that helps. Thank you and I hope that someone can help. This code is just so I can get the health system down, it isn't the main code for the game.
var Health = 100;
var damage = Randomizer.nextInt(1, 20);
var health = Health - damage;
var crit = Randomizer.nextInt(10, 30);
var dead = Health <= 0;
var rt = Health - crit;
//rt = Round two health
function start(){
var go = readLine("Take Damage? ");
if(go == "yes"){
println("You take " + damage + " Damage!");
println("Health: " + health);
}else if(go == "no"){
println("Nice try! ");
println("You take " + crit + " Damage!");
println("Health: " + (Health - crit));
var rt = Health - crit;
println(rt);
}
var rot = readLine("Take Damage? ");
if(rot == "yes"){
println("You take " + damage + " Damage!");
println("Health: " + health);
}
}
解决方案
推荐阅读
- python - 解释失败的 conda 安装的包请求冲突
- image - Flutter 从图像创建幻灯片视频
- excel - 如何在我的 VBA 代码中解决这个“下标超出范围错误”?
- reactjs - 我无法向网站 REACTJS 添加类别
- javascript - 查询以从当前日期开始根据小日期获取记录?
- matplotlib - 如何在 seaborn/matplotlib 图例中设置固定标记大小?
- mysql - MYSQL SELECT 加入同一张表
- mongodb - 如何使用 haproxy 公开暴露 mongodb
- sql-server - 用于选择和分组的 XQuery
- reactjs - React Native 与 React spring Launch 'Invariant Violation'