Created
July 25, 2020 15:37
-
-
Save apatronl/0ec6737dc0f47aba6c588b5d7af6dbfc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// ViewModel | |
class NumberGuessingGame { | |
private var model: GuessingGame<Int> | |
private var maxGuesses = 3 | |
init() { | |
model = GuessingGame(elementToGuess: NumberGuessingGame.generateGuess(), maxGuesses: maxGuesses) | |
} | |
var status: GuessingGame<Int>.GameStatus { | |
model.gameStatus | |
} | |
func makeGuess(withNumber number: Int) { | |
model.makeGuess(withElement: number) | |
} | |
func reset() { | |
model.reset(with: NumberGuessingGame.generateGuess()) | |
} | |
private static func generateGuess() -> Int { | |
return Int.random(in: 1...10) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment