Last active
July 11, 2022 04:04
-
-
Save vimiomori/39dc73fdb0b6029f1c8910f1df56a0d8 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
class PokemonType { | |
name string | |
strongAgainstList Array<string> | |
getName(): string { | |
return this.name | |
} | |
getStrongAgainstList(): Array<string> { | |
return this.strongAgainstList | |
} | |
isStrongAgainst(pokemonType): boolean { | |
return this.getStrongAgainstList().includes(pokemonType.getName()) | |
} | |
} | |
class Pokemon { | |
pokemonType PokemonType | |
getType(): PokemonType { | |
return this.pokemonType | |
} | |
beats(enemyPokemon: Pokemon) { | |
return this.getType().isStrongAgainst(enemyPokemon.getType()) | |
} | |
} | |
class NormalPokemonType extends PokemonType { | |
name = "normal" | |
strongAgainstList = [] | |
} | |
class FightingPokemonType extends PokemonType{ | |
name = "fighting" | |
strongAgainstList = ["normal"] | |
} | |
class NormalPokemon extends Pokemon { | |
pokemonType = new NormalPokemonType | |
} | |
class FightingPokemon extends Pokemon { | |
pokemonType = new FightingPokemonType | |
} | |
const snorlax = new NormalPokemon | |
const machomp = new FightingPokemon | |
machomp.beats(snorlax) // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment