Last active
March 27, 2022 14:17
-
-
Save zeroeth/8622428 to your computer and use it in GitHub Desktop.
javascript game basics.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hit_enemy = function(enemy, weapon) { | |
if(enemy.state == "alive") { | |
enemy.health = enemy.health - weapon.damage; | |
console.log("hit!", enemy.health); | |
if(enemy.health <= 0) { | |
console.log("it died"); | |
enemy.state = "dead"; | |
} | |
} | |
else { | |
console.log("its already dead"); | |
} | |
} | |
var player1 = {name: "bob", health: 40}; | |
var sword = {name: "laser sword", damage: 6}; | |
player1.weapon = sword; | |
var enemy1 = {name: "skeletor", health: 14, state: "alive"}; | |
hit_enemy(enemy1, player1.weapon); | |
hit_enemy(enemy1, player1.weapon); | |
hit_enemy(enemy1, player1.weapon); | |
hit_enemy(enemy1, player1.weapon); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is this?