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
|
|
9
|
|
10 struct GuessTheFlagView: View {
|
|
11 @Binding var gameName: GameName?
|
6
|
12 @StateObject var game = CountryGame()
|
0
|
13
|
|
14 var body: some View {
|
|
15 ZStack {
|
|
16 LinearGradient(gradient: .main, startPoint: .top, endPoint: .bottom)
|
|
17 .ignoresSafeArea()
|
|
18
|
3
|
19 GeometryReader { geo in
|
0
|
20 VStack(spacing: 20) {
|
6
|
21 GameToolbar(game: game, color: .mayaBlue)
|
0
|
22
|
|
23 HStack {
|
|
24 VStack(alignment: .leading, spacing: 10) {
|
3
|
25 Text("Question \(game.questionCounter) of \(game.data.count)")
|
0
|
26 .font(.title3)
|
6
|
27 .foregroundColor(.white.opacity(0.7))
|
|
28
|
3
|
29 Text("What is the flag of \(game.correctAnswer.key)?")
|
0
|
30 .font(.title)
|
|
31 .fontWeight(.semibold)
|
6
|
32 .foregroundColor(.white)
|
0
|
33 }
|
6
|
34
|
0
|
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: {
|
6
|
44 FlagImage(flagSymbol: game.data[countryName]!.flag, 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) {
|
6
|
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 }
|