diff GeoQuiz/Logic/Game.swift @ 4:de54f05adb78

add prototype game stats
author Dennis C. M. <dennis@denniscm.com>
date Thu, 22 Sep 2022 11:38:42 +0200
parents 4dbe0cd9dadc
children f31a61462e7a
line wrap: on
line diff
--- a/GeoQuiz/Logic/Game.swift	Thu Sep 22 10:42:39 2022 +0200
+++ b/GeoQuiz/Logic/Game.swift	Thu Sep 22 11:38:42 2022 +0200
@@ -22,6 +22,8 @@
     var userChoices: [String: T] { get set }
     var userScore: Int { get set }
     var userLives: Int { get set }
+    var correctAnswers: [String: T] { get set }
+    var wrongAnswers: [String: T] { get set }
     
     // Alerts
     var alertTitle: String { get set }
@@ -29,6 +31,7 @@
     var showingNoLivesAlert: Bool { get set }
     var showingEndGameAlert: Bool { get set }
     var showingWrongAnswerAlert: Bool { get set }
+    var showingExitGameAlert: Bool { get set }
     
     // Animations
     var scoreScaleAmount: Double { get set }
@@ -36,6 +39,7 @@
     
     // Modal views
     var showingBuyLivesView: Bool { get set }
+    var showingGameStatsView: Bool { get set }
 }
 
 extension Game {
@@ -91,24 +95,28 @@
         
         if correctAnswer == choice {
             hapticSuccess()
-            userScore += 1
-
+            
             withAnimation(.easeIn(duration: 0.5)) {
                 scoreScaleAmount += 1
+                userScore += 1
             }
             
+            correctAnswers[correctAnswer.key] = correctAnswer.value
             askQuestion()
         } else {
             hapticError()
-            userLives -= 1
+            
 
             withAnimation(.easeIn(duration: 0.5)) {
                 livesScaleAmount += 1
+                userLives -= 1
             }
 
             alertTitle = "Wrong!"
             alertMessage = "You have \(userLives) lives left"
             showingWrongAnswerAlert = true
+            
+            wrongAnswers[choice.key] = choice.value
         }
         
         DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [self] in