Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. class DiceGameTracker: DiceGameDelegate { // 프로토콜의 조건에 맞추기위해 3개의 메소드가 구현되어 있다.
  2. var numberOfTurns = 0
  3. func gameDidStart(_ game: DiceGame) {
  4. numberOfTurns = 0
  5. if game is SnakesAndLadders { // SnakesAndLadders 클래스의 인스턴스가 매개변수로 들어오면 실행
  6. print("Started a new game of Snakes and Ladders")
  7. }
  8. print("The game is using a \(game.dice.sides)-sided dice")
  9. }
  10. func game(_ game: DiceGame, didStartNewTurnWithDiceRoll diceRoll: Int) {
  11. numberOfTurns += 1
  12. print("Rolled a \(diceRoll)")
  13. }
  14. func gameDidEnd(_ game: DiceGame) {
  15. print("The game lasted for \(numberOfTurns) turns")
  16. }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement