Mercurial > public > geoquiz
comparison GeoQuiz/GuessTheFlagView.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 |
---|---|
14 var body: some View { | 14 var body: some View { |
15 ZStack { | 15 ZStack { |
16 LinearGradient(gradient: .main, startPoint: .top, endPoint: .bottom) | 16 LinearGradient(gradient: .main, startPoint: .top, endPoint: .bottom) |
17 .ignoresSafeArea() | 17 .ignoresSafeArea() |
18 | 18 |
19 GeometryReader{ geo in | 19 GeometryReader { geo in |
20 VStack(spacing: 20) { | 20 VStack(spacing: 20) { |
21 GameToolbar( | 21 GameToolbar(gameName: $gameName, game: game) |
22 userScore: $game.userScore, | |
23 userLives: $game.userLives, | |
24 gameName: $gameName, | |
25 showingBuyLivesView: $game.showingBuyLivesView | |
26 ) | |
27 | 22 |
28 HStack { | 23 HStack { |
29 VStack(alignment: .leading, spacing: 10) { | 24 VStack(alignment: .leading, spacing: 10) { |
30 Text("Question \(game.questionCounter) of \(game.countries.count)") | 25 Text("Question \(game.questionCounter) of \(game.data.count)") |
31 .font(.title3) | 26 .font(.title3) |
32 | 27 |
33 Text("What is the flag of \(game.countryNameAsked)?") | 28 Text("What is the flag of \(game.correctAnswer.key)?") |
34 .font(.title) | 29 .font(.title) |
35 .fontWeight(.semibold) | 30 .fontWeight(.semibold) |
36 } | 31 } |
37 .foregroundColor(.white) | 32 .foregroundColor(.white) |
38 | 33 |
39 Spacer() | 34 Spacer() |
40 } | 35 } |
41 | 36 |
42 Spacer() | 37 Spacer() |
43 | 38 |
44 ForEach(Array(game.userChoices.values), id: \.self) { flagSymbol in | 39 ForEach(Array(game.userChoices.keys), id: \.self) { countryName in |
45 Button { | 40 Button { |
46 game.answered(userChoice: flagSymbol) | 41 game.answer((key: countryName, value: game.data[countryName]!)) |
47 } label: { | 42 } label: { |
48 FlagImage(flagSymbol: flagSymbol, cornerRadius: 20) | 43 FlagImage(flagSymbol: game.data[countryName]!, cornerRadius: 20) |
49 .shadow(radius: 10) | 44 .shadow(radius: 10) |
50 .frame(height: geo.size.height * 0.15) | 45 .frame(height: geo.size.height * 0.15) |
51 } | 46 } |
52 .padding(.top) | 47 .padding(.top) |
53 } | 48 } |
56 } | 51 } |
57 .padding() | 52 .padding() |
58 } | 53 } |
59 } | 54 } |
60 .navigationBarHidden(true) | 55 .navigationBarHidden(true) |
61 | 56 .modifier(GameAlertsModifier(game: game, gameName: $gameName)) |
62 .sheet(isPresented: $game.showingBuyLivesView) { | 57 .sheet(isPresented: $game.showingBuyLivesView) { |
63 BuyLivesModal() | 58 BuyLivesModal() |
64 } | |
65 | |
66 .alert(game.alertTitle, isPresented: $game.showingNoLivesAlert) { | |
67 Button("Buy lives") { game.showingBuyLivesView = true } | |
68 Button("Exit", role: .destructive) { gameName = nil } | |
69 Button("Cancel", role: .cancel) { } | |
70 } message: { | |
71 Text(game.alertMessage) | |
72 } | |
73 | |
74 .alert(game.alertTitle, isPresented: $game.showingWrongAnswerAlert) { | |
75 Button("Continue", role: .cancel) { game.askQuestion() } | |
76 } message: { | |
77 Text(game.alertMessage) | |
78 } | |
79 | |
80 .alert(game.alertTitle, isPresented: $game.showingEndGameAlert) { | |
81 Button("Exit", role: .cancel) { gameName = nil } | |
82 } message: { | |
83 Text(game.alertMessage) | |
84 } | 59 } |
85 } | 60 } |
86 } | 61 } |
87 | 62 |
88 struct GuessTheFlagView_Previews: PreviewProvider { | 63 struct GuessTheFlagView_Previews: PreviewProvider { |