Skip to content

Instantly share code, notes, and snippets.

@ElectricCoffee
Last active December 29, 2015 23:09
Show Gist options
  • Save ElectricCoffee/7741142 to your computer and use it in GitHub Desktop.
Save ElectricCoffee/7741142 to your computer and use it in GitHub Desktop.
based off of the codecademy dragon slayer tutorial program, but with loads of stuff added
var slaying = true;
var youHit = function() {
return Math.round(Math.random());
};
var damageThisRound = 0;
var damage = function(min, max) {
return Math.floor(Math.random() * max + min);
};
var dragonHealth = 10;
var playerHealth = 10;
while(slaying) {
damageThisRound = damage(1,5);
console.log("your health: " + playerHealth);
console.log("dragon's health: " + dragonHealth);
if(youHit()) {
console.log("you hit the dragon with " + damageThisRound + " damage!");
dragonHealth -= damageThisRound;
if(dragonHealth <= 0) {
console.log("dragon's health: " + dragonHealth);
console.log("you slew the dragon!");
slaying = false;
}
}
else {
console.log("your attack missed!");
var dragonAttack = damage(3, 20);
console.log("the dragon hit you with: " + dragonAttack + " damage!");
playerHealth -= dragonAttack;
if(playerHealth <= 0) {
console.log("your health: " + playerHealth);
console.log("the dragon slayed you!");
slaying = false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment