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?
|
|
12 @StateObject var game = GuessTheFlag()
|
|
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) {
|
3
|
21 GameToolbar(gameName: $gameName, game: game)
|
0
|
22
|
|
23 HStack {
|
|
24 VStack(alignment: .leading, spacing: 10) {
|
3
|
25 Text("Question \(game.questionCounter) of \(game.data.count)")
|
0
|
26 .font(.title3)
|
|
27
|
3
|
28 Text("What is the flag of \(game.correctAnswer.key)?")
|
0
|
29 .font(.title)
|
|
30 .fontWeight(.semibold)
|
|
31 }
|
|
32 .foregroundColor(.white)
|
|
33
|
|
34 Spacer()
|
|
35 }
|
|
36
|
|
37 Spacer()
|
|
38
|
3
|
39 ForEach(Array(game.userChoices.keys), id: \.self) { countryName in
|
0
|
40 Button {
|
3
|
41 game.answer((key: countryName, value: game.data[countryName]!))
|
0
|
42 } label: {
|
3
|
43 FlagImage(flagSymbol: game.data[countryName]!, cornerRadius: 20)
|
0
|
44 .shadow(radius: 10)
|
|
45 .frame(height: geo.size.height * 0.15)
|
|
46 }
|
|
47 .padding(.top)
|
|
48 }
|
|
49
|
|
50 Spacer()
|
|
51 }
|
|
52 .padding()
|
|
53 }
|
|
54 }
|
|
55 .navigationBarHidden(true)
|
3
|
56 .modifier(GameAlertsModifier(game: game, gameName: $gameName))
|
0
|
57 .sheet(isPresented: $game.showingBuyLivesView) {
|
|
58 BuyLivesModal()
|
|
59 }
|
|
60 }
|
|
61 }
|
|
62
|
|
63 struct GuessTheFlagView_Previews: PreviewProvider {
|
|
64 static var previews: some View {
|
|
65 GuessTheFlagView(gameName: .constant(GameName.guessTheFlag))
|
|
66 }
|
|
67 }
|