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