comparison GeoQuiz/GuessTheCountryView.swift @ 6:1946bbfde4af

reformat data structures
author Dennis C. M. <dennis@denniscm.com>
date Thu, 29 Sep 2022 12:00:17 +0200
parents
children d945e52b0704
comparison
equal deleted inserted replaced
5:f31a61462e7a 6:1946bbfde4af
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 import MapKit
10
11 struct GuessTheCountryView: View {
12 @Binding var gameName: GameName?
13 @StateObject var game = CityGame()
14
15 var body: some View {
16 ZStack {
17 LinearGradient(gradient: .tertiary, startPoint: .top, endPoint: .bottom)
18 .ignoresSafeArea()
19
20 GeometryReader { geo in
21 VStack(spacing: 20) {
22 GameToolbar(game: game, color: .pinkLavender)
23
24 Spacer()
25
26 CityMap(region: MKCoordinateRegion(
27 center: CLLocationCoordinate2D(
28 latitude: game.correctAnswer.value.lat,
29 longitude: game.correctAnswer.value.lon
30 ),
31 span: MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5))
32 )
33 .frame(height: geo.size.height * 0.3)
34
35 Spacer()
36
37 HStack {
38 VStack(alignment: .leading, spacing: 10) {
39 Text("Question \(game.questionCounter) of \(game.data.count)")
40 .font(.title3)
41 .foregroundColor(.white.opacity(0.7))
42
43 Text("In what country is \(game.correctAnswer.key)?")
44 .font(.title)
45 .fontWeight(.semibold)
46 .foregroundColor(.white)
47 }
48
49 Spacer()
50 }
51
52 VStack {
53 ForEach(Array(game.userChoices.keys), id: \.self) { cityName in
54 Button {
55 game.answer((key: cityName, value: game.data[cityName]!))
56 } label: {
57 AnswerButton(
58 optionName: game.data[cityName]!.country,
59 color: .blueBell
60 )
61 .frame(height: geo.size.height * 0.08)
62 }
63 }
64 }
65
66 }
67 .padding()
68 }
69 }
70 .navigationBarHidden(true)
71 .modifier(GameAlertsModifier(game: game, gameName: $gameName))
72 .sheet(isPresented: $game.showingBuyLivesView) {
73 BuyLivesModalView()
74 }
75
76 .sheet(isPresented: $game.showingGameStatsView) {
77 // GameStatsModalView(game: game)
78 }
79 }
80 }
81
82 struct GuessTheCountryView_Previews: PreviewProvider {
83 static var previews: some View {
84 GuessTheCountryView(gameName: .constant(GameName.guessTheCountry))
85 }
86 }