Skip to content

Instantly share code, notes, and snippets.

@apatronl
Created July 25, 2020 15:37
Show Gist options
  • Save apatronl/0ec6737dc0f47aba6c588b5d7af6dbfc to your computer and use it in GitHub Desktop.
Save apatronl/0ec6737dc0f47aba6c588b5d7af6dbfc to your computer and use it in GitHub Desktop.
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