Last active
September 23, 2015 20:34
-
-
Save jacobthemyth/32c251c590b6d8e80a04 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Declare a variable that will later store the selected character and enemy | |
var selectedCharacter; | |
var selectedEnemy; | |
// Define a constructor | |
window.Character = function(params) { | |
_.extend(this, params); | |
}; | |
// Give all characters an attack function | |
Character.prototype.attack = function(enemy) { | |
enemy.health = enemy.health - this.attack; | |
$(document).trigger('health:changed'); | |
}; | |
// Create some character instances | |
window.characters = { | |
'Bulbasaur': new Character({ | |
health: 12, | |
attack: 1 | |
}), | |
'Charizard': new Character({ | |
health: 6, | |
attack: 2 | |
}) | |
}; | |
$(document).on('character:selected', function(character) { | |
selectedCharacter = character; | |
}); | |
$(document).on('enemy:selected', function(enemy) { | |
selectedEnemy = enemy; | |
}); | |
$(document).on('attack:enemy', function() { | |
selectedCharacter.attack(selectedEnemy); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment