Mercurial > public > geoquiz
diff GeoQuiz/Logic/Game.swift @ 7:d945e52b0704
implement dynamic map
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Tue, 04 Oct 2022 18:54:24 +0200 |
parents | 1946bbfde4af |
children | e09959b4e4a8 |
line wrap: on
line diff
--- a/GeoQuiz/Logic/Game.swift Thu Sep 29 12:00:17 2022 +0200 +++ b/GeoQuiz/Logic/Game.swift Tue Oct 04 18:54:24 2022 +0200 @@ -29,7 +29,7 @@ // Alerts var alertTitle: String { get set } var alertMessage: String { get set } - var showingNoLivesAlert: Bool { get set } + var showingGameOverAlert: Bool { get set } var showingEndGameAlert: Bool { get set } var showingWrongAnswerAlert: Bool { get set } var showingExitGameAlert: Bool { get set } @@ -38,10 +38,6 @@ var scoreScaleAmount: Double { get set } var livesScaleAmount: Double { get set } - // Modal views - var showingBuyLivesView: Bool { get set } - var showingGameStatsView: Bool { get set } - // Sound effects var player: AVAudioPlayer? { get set } } @@ -53,8 +49,8 @@ func askQuestion() { guard questionCounter < data.count else { - alertTitle = "Amazing!" - alertMessage = "You've completed the game." + alertTitle = "⭐️ Congratulations ⭐️" + alertMessage = "You completed the game." showingEndGameAlert = true return @@ -89,14 +85,6 @@ } func answer(_ choice: (key: String, value: T)) { - guard userLives > 0 else { - alertTitle = "Not enough lives!" - alertMessage = "Please buy more lives to keep playing" - showingNoLivesAlert = true - - return - } - if correctAnswer == choice { hapticSuccess() playSound("correctAnswer") @@ -116,12 +104,18 @@ livesScaleAmount += 1 userLives -= 1 } - - alertTitle = "Wrong!" - alertMessage = "You have \(userLives) lives left" - showingWrongAnswerAlert = true wrongAnswers[choice.key] = choice.value + + if userLives == 0 { + alertTitle = "🤕 Game over 🤕" + alertMessage = "Get up and try again." + showingGameOverAlert = true + } else { + alertTitle = "🔴 Wrong 🔴" + alertMessage = "You have \(userLives) lives left." + showingWrongAnswerAlert = true + } } DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [self] in @@ -132,6 +126,15 @@ } } + func reset() { + dataAsked = [String: T]() + userScore = 0 + userLives = 3 + correctAnswers = [String: T]() + wrongAnswers = [String: T]() + askQuestion() + } + private func playSound(_ filename: String) { guard let soundFileURL = Bundle.main.url(forResource: filename, withExtension: "wav") else { fatalError("Sound file \(filename) couldn't be found")