6
|
1 //
|
|
2 // GuessTheCountryView.swift
|
|
3 // GeoQuiz
|
|
4 //
|
|
5 // Created by Dennis Concepción Martín on 24/9/22.
|
|
6 //
|
|
7
|
|
8 import SwiftUI
|
|
9
|
|
10 struct GuessTheCountryView: View {
|
|
11 @StateObject var game = CityGame()
|
|
12
|
|
13 var body: some View {
|
|
14 ZStack {
|
|
15 LinearGradient(gradient: .tertiary, startPoint: .top, endPoint: .bottom)
|
|
16 .ignoresSafeArea()
|
|
17
|
|
18 GeometryReader { geo in
|
|
19 VStack(spacing: 20) {
|
|
20 GameToolbar(game: game, color: .pinkLavender)
|
|
21
|
|
22 Spacer()
|
7
|
23
|
8
|
24 CityMap(game: game, geo: geo)
|
6
|
25
|
|
26 Spacer()
|
|
27
|
|
28 HStack {
|
|
29 VStack(alignment: .leading, spacing: 10) {
|
|
30 Text("Question \(game.questionCounter) of \(game.data.count)")
|
|
31 .font(.title3)
|
|
32 .foregroundColor(.white.opacity(0.7))
|
|
33
|
|
34 Text("In what country is \(game.correctAnswer.key)?")
|
|
35 .font(.title)
|
|
36 .fontWeight(.semibold)
|
|
37 .foregroundColor(.white)
|
|
38 }
|
|
39
|
|
40 Spacer()
|
|
41 }
|
|
42
|
|
43 VStack {
|
|
44 ForEach(Array(game.userChoices.keys), id: \.self) { cityName in
|
|
45 Button {
|
8
|
46 game.answer((key: cityName, value: game.data[cityName]!)) {
|
|
47 game.selector()
|
|
48 }
|
6
|
49 } label: {
|
|
50 AnswerButton(
|
|
51 optionName: game.data[cityName]!.country,
|
|
52 color: .blueBell
|
|
53 )
|
|
54 .frame(height: geo.size.height * 0.08)
|
|
55 }
|
|
56 }
|
|
57 }
|
|
58
|
|
59 }
|
|
60 .padding()
|
|
61 }
|
|
62 }
|
|
63 .navigationBarHidden(true)
|
7
|
64 .modifier(GameAlertsModifier(game: game))
|
6
|
65 }
|
|
66 }
|
|
67
|
|
68 struct GuessTheCountryView_Previews: PreviewProvider {
|
|
69 static var previews: some View {
|
7
|
70 GuessTheCountryView()
|
6
|
71 }
|
|
72 }
|