Mercurial > public > geoquiz
comparison GeoQuiz/GuessTheFlagView.swift @ 0:413e2d21333e
first commit
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Tue, 20 Sep 2022 08:13:26 +0200 |
parents | |
children | 4dbe0cd9dadc |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:413e2d21333e |
---|---|
1 // | |
2 // GuessTheFlagView.swift | |
3 // GeoQuiz | |
4 // | |
5 // Created by Dennis Concepción Martín on 20/9/22. | |
6 // | |
7 | |
8 import SwiftUI | |
9 | |
10 struct GuessTheFlagView: View { | |
11 @Binding var gameName: GameName? | |
12 @StateObject var game = GuessTheFlag() | |
13 | |
14 var body: some View { | |
15 ZStack { | |
16 LinearGradient(gradient: .main, startPoint: .top, endPoint: .bottom) | |
17 .ignoresSafeArea() | |
18 | |
19 GeometryReader{ geo in | |
20 VStack(spacing: 20) { | |
21 GameToolbar( | |
22 userScore: $game.userScore, | |
23 userLives: $game.userLives, | |
24 gameName: $gameName, | |
25 showingBuyLivesView: $game.showingBuyLivesView | |
26 ) | |
27 | |
28 HStack { | |
29 VStack(alignment: .leading, spacing: 10) { | |
30 Text("Question \(game.questionCounter) of \(game.countries.count)") | |
31 .font(.title3) | |
32 | |
33 Text("What is the flag of \(game.countryNameAsked)?") | |
34 .font(.title) | |
35 .fontWeight(.semibold) | |
36 } | |
37 .foregroundColor(.white) | |
38 | |
39 Spacer() | |
40 } | |
41 | |
42 Spacer() | |
43 | |
44 ForEach(Array(game.userChoices.values), id: \.self) { flagSymbol in | |
45 Button { | |
46 game.answered(userChoice: flagSymbol) | |
47 } label: { | |
48 FlagImage(flagSymbol: flagSymbol, cornerRadius: 20) | |
49 .shadow(radius: 10) | |
50 .frame(height: geo.size.height * 0.15) | |
51 } | |
52 .padding(.top) | |
53 } | |
54 | |
55 Spacer() | |
56 } | |
57 .padding() | |
58 } | |
59 } | |
60 .navigationBarHidden(true) | |
61 | |
62 .sheet(isPresented: $game.showingBuyLivesView) { | |
63 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 } | |
85 } | |
86 } | |
87 | |
88 struct GuessTheFlagView_Previews: PreviewProvider { | |
89 static var previews: some View { | |
90 GuessTheFlagView(gameName: .constant(GameName.guessTheFlag)) | |
91 } | |
92 } |