Skip to content

Instantly share code, notes, and snippets.

@nicohvi
Last active August 5, 2018 18:06
Show Gist options
  • Save nicohvi/64f20514d2eeca21ff592428d7beb5a2 to your computer and use it in GitHub Desktop.
Save nicohvi/64f20514d2eeca21ff592428d7beb5a2 to your computer and use it in GitHub Desktop.
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