Last active
August 5, 2018 18:06
-
-
Save nicohvi/64f20514d2eeca21ff592428d7beb5a2 to your computer and use it in GitHub Desktop.
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
function getAttackPower(pokemon: Pokemon) { | |
return pokemon.level * pokemon.attackPower; | |
} | |
function defend(pokemon: Pokemon, damage: number) { | |
const hp = pokemon.hp - damage; | |
return Object.assign({}, pokemon, { hp }); | |
} | |
function performAttack(attacker: Pokemon, defender: Pokemon) { | |
const dmg = getAttackPower(attacker); | |
return { | |
attacker, | |
defender: defend(defender, dmg) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment