comparison GeoQuiz/GuessTheFlagView.swift @ 6:1946bbfde4af

reformat data structures
author Dennis C. M. <dennis@denniscm.com>
date Thu, 29 Sep 2022 12:00:17 +0200
parents f31a61462e7a
children d945e52b0704
comparison
equal deleted inserted replaced
5:f31a61462e7a 6:1946bbfde4af
4 // 4 //
5 // Created by Dennis Concepción Martín on 20/9/22. 5 // Created by Dennis Concepción Martín on 20/9/22.
6 // 6 //
7 7
8 import SwiftUI 8 import SwiftUI
9 import AVFAudio
10 9
11 struct GuessTheFlagView: View { 10 struct GuessTheFlagView: View {
12 @Binding var gameName: GameName? 11 @Binding var gameName: GameName?
13 @StateObject var game = GuessTheFlag() 12 @StateObject var game = CountryGame()
14 13
15 var body: some View { 14 var body: some View {
16 ZStack { 15 ZStack {
17 LinearGradient(gradient: .main, startPoint: .top, endPoint: .bottom) 16 LinearGradient(gradient: .main, startPoint: .top, endPoint: .bottom)
18 .ignoresSafeArea() 17 .ignoresSafeArea()
19 18
20 GeometryReader { geo in 19 GeometryReader { geo in
21 VStack(spacing: 20) { 20 VStack(spacing: 20) {
22 GameToolbar(game: game) 21 GameToolbar(game: game, color: .mayaBlue)
23 22
24 HStack { 23 HStack {
25 VStack(alignment: .leading, spacing: 10) { 24 VStack(alignment: .leading, spacing: 10) {
26 Text("Question \(game.questionCounter) of \(game.data.count)") 25 Text("Question \(game.questionCounter) of \(game.data.count)")
27 .font(.title3) 26 .font(.title3)
28 27 .foregroundColor(.white.opacity(0.7))
28
29 Text("What is the flag of \(game.correctAnswer.key)?") 29 Text("What is the flag of \(game.correctAnswer.key)?")
30 .font(.title) 30 .font(.title)
31 .fontWeight(.semibold) 31 .fontWeight(.semibold)
32 .foregroundColor(.white)
32 } 33 }
33 .foregroundColor(.white) 34
34
35 Spacer() 35 Spacer()
36 } 36 }
37 37
38 Spacer() 38 Spacer()
39 39
40 ForEach(Array(game.userChoices.keys), id: \.self) { countryName in 40 ForEach(Array(game.userChoices.keys), id: \.self) { countryName in
41 Button { 41 Button {
42 game.answer((key: countryName, value: game.data[countryName]!)) 42 game.answer((key: countryName, value: game.data[countryName]!))
43 } label: { 43 } label: {
44 FlagImage(flagSymbol: game.data[countryName]!, cornerRadius: 20) 44 FlagImage(flagSymbol: game.data[countryName]!.flag, cornerRadius: 20)
45 .shadow(radius: 10) 45 .shadow(radius: 10)
46 .frame(height: geo.size.height * 0.15) 46 .frame(height: geo.size.height * 0.15)
47 } 47 }
48 .padding(.top) 48 .padding(.top)
49 } 49 }
58 .sheet(isPresented: $game.showingBuyLivesView) { 58 .sheet(isPresented: $game.showingBuyLivesView) {
59 BuyLivesModalView() 59 BuyLivesModalView()
60 } 60 }
61 61
62 .sheet(isPresented: $game.showingGameStatsView) { 62 .sheet(isPresented: $game.showingGameStatsView) {
63 GameStatsModalView(game: game) 63 // GameStatsModalView(game: game)
64 } 64 }
65 } 65 }
66 } 66 }
67 67
68 struct GuessTheFlagView_Previews: PreviewProvider { 68 struct GuessTheFlagView_Previews: PreviewProvider {