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