Mercurial > public > geoquiz
comparison GeoQuiz/Logic/CityGame.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 // CityGame.swift | |
3 // GeoQuiz | |
4 // | |
5 // Created by Dennis Concepción Martín on 29/9/22. | |
6 // | |
7 | |
8 import Foundation | |
9 import AVFAudio | |
10 | |
11 class CityGame: Game, ObservableObject { | |
12 | |
13 // Define type of generics | |
14 typealias T = CityModel.CityData | |
15 | |
16 var data: [String: T] | |
17 var dataAsked = [String: T]() | |
18 | |
19 // Data | |
20 @Published var correctAnswer = (key: String(), value: T(country: String(), lat: Double(), lon: Double())) | |
21 | |
22 // User | |
23 @Published var userChoices = [String: T]() | |
24 @Published var userScore = 0 | |
25 @Published var userLives = 3 | |
26 @Published var correctAnswers = [String: T]() | |
27 @Published var wrongAnswers = [String: T]() | |
28 | |
29 // Alerts | |
30 @Published var alertTitle = String() | |
31 @Published var alertMessage = String() | |
32 @Published var showingNoLivesAlert = false | |
33 @Published var showingEndGameAlert = false | |
34 @Published var showingWrongAnswerAlert = false | |
35 @Published var showingExitGameAlert = false | |
36 | |
37 // Animations | |
38 @Published var scoreScaleAmount = 1.0 | |
39 @Published var livesScaleAmount = 1.0 | |
40 | |
41 // Modal views | |
42 @Published var showingBuyLivesView = false | |
43 @Published var showingGameStatsView = false | |
44 | |
45 // Sound effects | |
46 @Published var player: AVAudioPlayer? | |
47 | |
48 init() { | |
49 let data: CityModel = load("cities.json") | |
50 self.data = data.cities | |
51 askQuestion() | |
52 } | |
53 } |