Mercurial > public > geoquiz
comparison GeoQuiz/GuessTheCapitalView.swift @ 6:1946bbfde4af
reformat data structures
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Thu, 29 Sep 2022 12:00:17 +0200 |
parents | de54f05adb78 |
children | d945e52b0704 |
comparison
equal
deleted
inserted
replaced
5:f31a61462e7a | 6:1946bbfde4af |
---|---|
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 struct GuessTheCapitalView: View { | 10 struct GuessTheCapitalView: View { |
11 @Binding var gameName: GameName? | 11 @Binding var gameName: GameName? |
12 @StateObject var game = GuessTheCapital() | 12 @StateObject var game = CountryGame() |
13 | |
14 // var flagSymbol: String { | |
15 // if let countryAsked = game.countries[game.countryNameAsked] { | |
16 // return countryAsked.flagSymbol | |
17 // } else { | |
18 // fatalError("Couldn't find \(game.countryNameAsked) in countries") | |
19 // } | |
20 // } | |
21 | 13 |
22 var body: some View { | 14 var body: some View { |
23 ZStack { | 15 ZStack { |
24 LinearGradient(gradient: .secondary, startPoint: .top, endPoint: .bottom) | 16 LinearGradient(gradient: .secondary, startPoint: .top, endPoint: .bottom) |
25 .ignoresSafeArea() | 17 .ignoresSafeArea() |
26 | 18 |
27 GeometryReader { geo in | 19 GeometryReader { geo in |
28 VStack(spacing: 20) { | 20 VStack(spacing: 20) { |
29 // GameToolbar( | 21 GameToolbar(game: game, color: .atomicTangerine) |
30 // userScore: $game.userScore, | 22 |
31 // userLives: $game.userLives, | 23 Spacer() |
32 // gameName: $gameName, | 24 |
33 // showingBuyLivesView: $game.showingBuyLivesView | 25 FlagImage(flagSymbol: game.correctAnswer.value.flag, cornerRadius: 20) |
34 // ) | 26 .shadow(radius: 10) |
35 | 27 .frame(height: geo.size.height * 0.15) |
28 | |
29 Spacer() | |
30 | |
31 HStack { | |
32 VStack(alignment: .leading, spacing: 10) { | |
33 Text("Question \(game.questionCounter) of \(game.data.count)") | |
34 .font(.title3) | |
35 .foregroundColor(.white.opacity(0.7)) | |
36 | |
37 Text("What is the capital of \(game.correctAnswer.key)?") | |
38 .font(.title) | |
39 .fontWeight(.semibold) | |
40 .foregroundColor(.white) | |
41 } | |
42 | |
36 Spacer() | 43 Spacer() |
37 | 44 } |
38 // FlagImage(flagSymbol: flagSymbol, cornerRadius: 20) | 45 |
39 // .shadow(radius: 10) | 46 VStack { |
40 // .frame(height: geo.size.height * 0.15) | 47 ForEach(Array(game.userChoices.keys), id: \.self) { countryName in |
41 | 48 Button { |
42 Spacer() | 49 game.answer((key: countryName, value: game.data[countryName]!)) |
43 | 50 } label: { |
44 HStack { | 51 AnswerButton( |
45 // VStack(alignment: .leading, spacing: 10) { | 52 optionName: game.data[countryName]!.capital, |
46 // Text("Question \(game.questionCounter) of \(game.countries.count)") | 53 color: .chinaPink |
47 // .font(.title3) | 54 ) |
48 // | 55 .frame(height: geo.size.height * 0.08) |
49 // Text("What is the capital of \(game.countryNameAsked)?") | 56 } |
50 // .font(.title) | |
51 // .fontWeight(.semibold) | |
52 // } | |
53 // .foregroundColor(.white) | |
54 | |
55 Spacer() | |
56 } | |
57 | |
58 VStack { | |
59 // ForEach(Array(game.userChoices.values), id: \.self) { country in | |
60 // Button { | |
61 // game.answered(userChoice: country.capitalName) | |
62 // } label: { | |
63 // AnswerButton(optionName: country.capitalName, color: .secondary) | |
64 // .frame(height: geo.size.height * 0.08) | |
65 // } | |
66 // } | |
67 } | 57 } |
68 } | 58 } |
69 .padding() | 59 } |
60 .padding() | |
70 } | 61 } |
71 } | 62 } |
72 .navigationBarHidden(true) | 63 .navigationBarHidden(true) |
64 .modifier(GameAlertsModifier(game: game, gameName: $gameName)) | |
65 .sheet(isPresented: $game.showingBuyLivesView) { | |
66 BuyLivesModalView() | |
67 } | |
73 | 68 |
74 // .sheet(isPresented: $game.showingBuyLivesView) { | 69 .sheet(isPresented: $game.showingGameStatsView) { |
75 // BuyLivesModalView() | 70 // GameStatsModalView(game: game) |
76 // } | 71 } |
77 // | |
78 // .alert(game.alertTitle, isPresented: $game.showingNoLivesAlert) { | |
79 // Button("Buy lives") { game.showingBuyLivesView = true } | |
80 // Button("Exit", role: .destructive) { gameName = nil } | |
81 // Button("Cancel", role: .cancel) { } | |
82 // } message: { | |
83 // Text(game.alertMessage) | |
84 // } | |
85 // | |
86 // .alert(game.alertTitle, isPresented: $game.showingWrongAnswerAlert) { | |
87 // Button("Continue", role: .cancel) { game.askQuestion() } | |
88 // } message: { | |
89 // Text(game.alertMessage) | |
90 // } | |
91 // | |
92 // .alert(game.alertTitle, isPresented: $game.showingEndGameAlert) { | |
93 // Button("Exit", role: .cancel) { gameName = nil } | |
94 // } message: { | |
95 // Text(game.alertMessage) | |
96 // } | |
97 } | 72 } |
98 } | 73 } |
99 | 74 |
100 struct GuessCapitalView_Previews: PreviewProvider { | 75 struct GuessCapitalView_Previews: PreviewProvider { |
101 static var previews: some View { | 76 static var previews: some View { |