Skip to content

Instantly share code, notes, and snippets.

@toshi0383
Created July 14, 2016 12:32
Show Gist options
  • Save toshi0383/69419f39e835438ce155e9df8e360c81 to your computer and use it in GitHub Desktop.
Save toshi0383/69419f39e835438ce155e9df8e360c81 to your computer and use it in GitHub Desktop.
Swift3でリストの要素にprotocolを指定できるようになったとのことで、ポケモン攻撃問題をやってみた。 #CodePiece
import PokemonKit
let a = PokeDeck(pokemons: [
Pikachu(level: 1),
Bulbasaur(level: 5),
Pikachu(level: 11),
Pikachu(level: 4),
Pikachu(level: 20)
])
for pokemon in a.pokemons {
do {
try pokemon.attack(move: ElectricMove.ThunderShock)
} catch {
try! pokemon.attack(move: NormalMove.Scratch)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment