首页 > 解决方案 > 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);
    }
}

标签: javascript

解决方案


推荐阅读