0
|
1 //
|
|
2 // GuessTheFlagView.swift
|
|
3 // GeoQuiz
|
|
4 //
|
|
5 // Created by Dennis Concepción Martín on 20/9/22.
|
|
6 //
|
|
7
|
|
8 import SwiftUI
|
5
|
9 import AVFAudio
|
0
|
10
|
|
11 struct GuessTheFlagView: View {
|
|
12 @Binding var gameName: GameName?
|
|
13 @StateObject var game = GuessTheFlag()
|
|
14
|
|
15 var body: some View {
|
|
16 ZStack {
|
|
17 LinearGradient(gradient: .main, startPoint: .top, endPoint: .bottom)
|
|
18 .ignoresSafeArea()
|
|
19
|
3
|
20 GeometryReader { geo in
|
0
|
21 VStack(spacing: 20) {
|
4
|
22 GameToolbar(game: game)
|
0
|
23
|
|
24 HStack {
|
|
25 VStack(alignment: .leading, spacing: 10) {
|
3
|
26 Text("Question \(game.questionCounter) of \(game.data.count)")
|
0
|
27 .font(.title3)
|
|
28
|
3
|
29 Text("What is the flag of \(game.correctAnswer.key)?")
|
0
|
30 .font(.title)
|
|
31 .fontWeight(.semibold)
|
|
32 }
|
|
33 .foregroundColor(.white)
|
|
34
|
|
35 Spacer()
|
|
36 }
|
|
37
|
|
38 Spacer()
|
|
39
|
3
|
40 ForEach(Array(game.userChoices.keys), id: \.self) { countryName in
|
0
|
41 Button {
|
3
|
42 game.answer((key: countryName, value: game.data[countryName]!))
|
0
|
43 } label: {
|
3
|
44 FlagImage(flagSymbol: game.data[countryName]!, cornerRadius: 20)
|
0
|
45 .shadow(radius: 10)
|
|
46 .frame(height: geo.size.height * 0.15)
|
|
47 }
|
|
48 .padding(.top)
|
|
49 }
|
|
50
|
|
51 Spacer()
|
|
52 }
|
|
53 .padding()
|
|
54 }
|
|
55 }
|
|
56 .navigationBarHidden(true)
|
3
|
57 .modifier(GameAlertsModifier(game: game, gameName: $gameName))
|
0
|
58 .sheet(isPresented: $game.showingBuyLivesView) {
|
4
|
59 BuyLivesModalView()
|
|
60 }
|
|
61
|
|
62 .sheet(isPresented: $game.showingGameStatsView) {
|
|
63 GameStatsModalView(game: game)
|
0
|
64 }
|
|
65 }
|
|
66 }
|
|
67
|
|
68 struct GuessTheFlagView_Previews: PreviewProvider {
|
|
69 static var previews: some View {
|
|
70 GuessTheFlagView(gameName: .constant(GameName.guessTheFlag))
|
|
71 }
|
|
72 }
|