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