Mercurial > public > geoquiz
comparison 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 |
comparison
equal
deleted
inserted
replaced
3:4dbe0cd9dadc | 4:de54f05adb78 |
---|---|
20 | 20 |
21 // User | 21 // User |
22 var userChoices: [String: T] { get set } | 22 var userChoices: [String: T] { get set } |
23 var userScore: Int { get set } | 23 var userScore: Int { get set } |
24 var userLives: Int { get set } | 24 var userLives: Int { get set } |
25 var correctAnswers: [String: T] { get set } | |
26 var wrongAnswers: [String: T] { get set } | |
25 | 27 |
26 // Alerts | 28 // Alerts |
27 var alertTitle: String { get set } | 29 var alertTitle: String { get set } |
28 var alertMessage: String { get set } | 30 var alertMessage: String { get set } |
29 var showingNoLivesAlert: Bool { get set } | 31 var showingNoLivesAlert: Bool { get set } |
30 var showingEndGameAlert: Bool { get set } | 32 var showingEndGameAlert: Bool { get set } |
31 var showingWrongAnswerAlert: Bool { get set } | 33 var showingWrongAnswerAlert: Bool { get set } |
34 var showingExitGameAlert: Bool { get set } | |
32 | 35 |
33 // Animations | 36 // Animations |
34 var scoreScaleAmount: Double { get set } | 37 var scoreScaleAmount: Double { get set } |
35 var livesScaleAmount: Double { get set } | 38 var livesScaleAmount: Double { get set } |
36 | 39 |
37 // Modal views | 40 // Modal views |
38 var showingBuyLivesView: Bool { get set } | 41 var showingBuyLivesView: Bool { get set } |
42 var showingGameStatsView: Bool { get set } | |
39 } | 43 } |
40 | 44 |
41 extension Game { | 45 extension Game { |
42 var questionCounter: Int { | 46 var questionCounter: Int { |
43 dataAsked.count | 47 dataAsked.count |
89 return | 93 return |
90 } | 94 } |
91 | 95 |
92 if correctAnswer == choice { | 96 if correctAnswer == choice { |
93 hapticSuccess() | 97 hapticSuccess() |
94 userScore += 1 | 98 |
95 | |
96 withAnimation(.easeIn(duration: 0.5)) { | 99 withAnimation(.easeIn(duration: 0.5)) { |
97 scoreScaleAmount += 1 | 100 scoreScaleAmount += 1 |
101 userScore += 1 | |
98 } | 102 } |
99 | 103 |
104 correctAnswers[correctAnswer.key] = correctAnswer.value | |
100 askQuestion() | 105 askQuestion() |
101 } else { | 106 } else { |
102 hapticError() | 107 hapticError() |
103 userLives -= 1 | 108 |
104 | 109 |
105 withAnimation(.easeIn(duration: 0.5)) { | 110 withAnimation(.easeIn(duration: 0.5)) { |
106 livesScaleAmount += 1 | 111 livesScaleAmount += 1 |
112 userLives -= 1 | |
107 } | 113 } |
108 | 114 |
109 alertTitle = "Wrong!" | 115 alertTitle = "Wrong!" |
110 alertMessage = "You have \(userLives) lives left" | 116 alertMessage = "You have \(userLives) lives left" |
111 showingWrongAnswerAlert = true | 117 showingWrongAnswerAlert = true |
118 | |
119 wrongAnswers[choice.key] = choice.value | |
112 } | 120 } |
113 | 121 |
114 DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [self] in | 122 DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [self] in |
115 withAnimation(.easeIn(duration: 0.5)) { | 123 withAnimation(.easeIn(duration: 0.5)) { |
116 scoreScaleAmount = 1 | 124 scoreScaleAmount = 1 |