Mercurial > public > geoquiz
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GeoQuiz/Logic/CountryGame.swift Thu Sep 29 12:00:17 2022 +0200 @@ -0,0 +1,56 @@ +// +// CountryGame.swift +// GeoQuiz +// +// Created by Dennis Concepción Martín on 20/9/22. +// + +import Foundation +import AVFAudio + +class CountryGame: Game, ObservableObject { + + // Define type of generics + typealias T = CountryModel.CountryData + + var data: [String: T] + var dataAsked = [String: T]() + + // Data + @Published var correctAnswer = ( + key: String(), + value: T(flag: String(), currency: String(), population: Int(), capital: String()) + ) + + // User + @Published var userChoices = [String: T]() + @Published var userScore = 0 + @Published var userLives = 3 + @Published var correctAnswers = [String: T]() + @Published var wrongAnswers = [String: T]() + + // Alerts + @Published var alertTitle = String() + @Published var alertMessage = String() + @Published var showingNoLivesAlert = false + @Published var showingEndGameAlert = false + @Published var showingWrongAnswerAlert = false + @Published var showingExitGameAlert = false + + // Animations + @Published var scoreScaleAmount = 1.0 + @Published var livesScaleAmount = 1.0 + + // Modal views + @Published var showingBuyLivesView = false + @Published var showingGameStatsView = false + + // Sound effects + @Published var player: AVAudioPlayer? + + init() { + let data: CountryModel = load("countries.json") + self.data = data.countries + askQuestion() + } +}