Mercurial > public > geoquiz
comparison GeoQuiz/Logic/CountryGame.swift @ 6:1946bbfde4af
reformat data structures
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Thu, 29 Sep 2022 12:00:17 +0200 |
parents | GeoQuiz/Logic/GuessTheFlag.swift@f31a61462e7a |
children | d945e52b0704 |
comparison
equal
deleted
inserted
replaced
5:f31a61462e7a | 6:1946bbfde4af |
---|---|
1 // | |
2 // CountryGame.swift | |
3 // GeoQuiz | |
4 // | |
5 // Created by Dennis Concepción Martín on 20/9/22. | |
6 // | |
7 | |
8 import Foundation | |
9 import AVFAudio | |
10 | |
11 class CountryGame: Game, ObservableObject { | |
12 | |
13 // Define type of generics | |
14 typealias T = CountryModel.CountryData | |
15 | |
16 var data: [String: T] | |
17 var dataAsked = [String: T]() | |
18 | |
19 // Data | |
20 @Published var correctAnswer = ( | |
21 key: String(), | |
22 value: T(flag: String(), currency: String(), population: Int(), capital: String()) | |
23 ) | |
24 | |
25 // User | |
26 @Published var userChoices = [String: T]() | |
27 @Published var userScore = 0 | |
28 @Published var userLives = 3 | |
29 @Published var correctAnswers = [String: T]() | |
30 @Published var wrongAnswers = [String: T]() | |
31 | |
32 // Alerts | |
33 @Published var alertTitle = String() | |
34 @Published var alertMessage = String() | |
35 @Published var showingNoLivesAlert = false | |
36 @Published var showingEndGameAlert = false | |
37 @Published var showingWrongAnswerAlert = false | |
38 @Published var showingExitGameAlert = false | |
39 | |
40 // Animations | |
41 @Published var scoreScaleAmount = 1.0 | |
42 @Published var livesScaleAmount = 1.0 | |
43 | |
44 // Modal views | |
45 @Published var showingBuyLivesView = false | |
46 @Published var showingGameStatsView = false | |
47 | |
48 // Sound effects | |
49 @Published var player: AVAudioPlayer? | |
50 | |
51 init() { | |
52 let data: CountryModel = load("countries.json") | |
53 self.data = data.countries | |
54 askQuestion() | |
55 } | |
56 } |