0
|
1 //
|
6
|
2 // CountryGame.swift
|
0
|
3 // GeoQuiz
|
|
4 //
|
|
5 // Created by Dennis Concepción Martín on 20/9/22.
|
|
6 //
|
|
7
|
|
8 import Foundation
|
5
|
9 import AVFAudio
|
0
|
10
|
6
|
11 class CountryGame: Game, ObservableObject {
|
|
12
|
3
|
13 // Define type of generics
|
6
|
14 typealias T = CountryModel.CountryData
|
|
15
|
|
16 var data: [String: T]
|
|
17 var dataAsked = [String: T]()
|
0
|
18
|
3
|
19 // Data
|
6
|
20 @Published var correctAnswer = (
|
|
21 key: String(),
|
|
22 value: T(flag: String(), currency: String(), population: Int(), capital: String())
|
|
23 )
|
3
|
24
|
|
25 // User
|
6
|
26 @Published var userChoices = [String: T]()
|
0
|
27 @Published var userScore = 0
|
|
28 @Published var userLives = 3
|
6
|
29 @Published var correctAnswers = [String: T]()
|
|
30 @Published var wrongAnswers = [String: T]()
|
3
|
31
|
|
32 // Alerts
|
|
33 @Published var alertTitle = String()
|
|
34 @Published var alertMessage = String()
|
7
|
35 @Published var showingGameOverAlert = false
|
3
|
36 @Published var showingEndGameAlert = false
|
0
|
37 @Published var showingWrongAnswerAlert = false
|
4
|
38 @Published var showingExitGameAlert = false
|
0
|
39
|
3
|
40 // Animations
|
|
41 @Published var scoreScaleAmount = 1.0
|
|
42 @Published var livesScaleAmount = 1.0
|
|
43
|
5
|
44 // Sound effects
|
|
45 @Published var player: AVAudioPlayer?
|
|
46
|
0
|
47 init() {
|
6
|
48 let data: CountryModel = load("countries.json")
|
|
49 self.data = data.countries
|
0
|
50 askQuestion()
|
|
51 }
|
|
52 }
|