SHARE
TWEET

Untitled

a guest Jul 16th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top