Skip to content

Instantly share code, notes, and snippets.

@vimiomori
Last active July 11, 2022 04:04
Show Gist options
  • Save vimiomori/39dc73fdb0b6029f1c8910f1df56a0d8 to your computer and use it in GitHub Desktop.
Save vimiomori/39dc73fdb0b6029f1c8910f1df56a0d8 to your computer and use it in GitHub Desktop.
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