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