Mercurial > public > geoquiz
comparison GeoQuiz/Helpers/GameToolbar.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 |
---|---|
5 // Created by Dennis Concepción Martín on 18/9/22. | 5 // Created by Dennis Concepción Martín on 18/9/22. |
6 // | 6 // |
7 | 7 |
8 import SwiftUI | 8 import SwiftUI |
9 | 9 |
10 struct GameToolbar: View { | 10 struct GameToolbar<T: Game>: View { |
11 @Binding var userScore: Int | |
12 @Binding var userLives: Int | |
13 @Binding var gameName: GameName? | 11 @Binding var gameName: GameName? |
14 @Binding var showingBuyLivesView: Bool | 12 @ObservedObject var game: T |
13 | |
15 | 14 |
16 var body: some View { | 15 var body: some View { |
17 HStack(spacing: 0) { | 16 HStack(spacing: 0) { |
18 Group { | 17 Group { |
19 Button { | 18 Button { |
30 .foregroundColor(.white) | 29 .foregroundColor(.white) |
31 .font(.headline) | 30 .font(.headline) |
32 .frame(maxWidth: .infinity, alignment: .leading) | 31 .frame(maxWidth: .infinity, alignment: .leading) |
33 | 32 |
34 Group { | 33 Group { |
35 Text("\(userScore)") | 34 Text("\(game.userScore)") |
36 .padding() | 35 .padding() |
37 .background( | 36 .background( |
38 Circle() | 37 Circle() |
39 .strokeBorder(lineWidth: 3) | 38 .strokeBorder(lineWidth: 3) |
40 ) | 39 ) |
41 } | 40 } |
42 .foregroundColor(.white) | 41 .foregroundColor(.white) |
43 .font(.title2) | 42 .font(.title2) |
43 .scaleEffect(game.scoreScaleAmount) | |
44 .frame(maxWidth: .infinity, alignment: .center) | 44 .frame(maxWidth: .infinity, alignment: .center) |
45 | 45 |
46 Group { | 46 Group { |
47 Button { | 47 Button { |
48 showingBuyLivesView = true | 48 game.showingBuyLivesView = true |
49 } label: { | 49 } label: { |
50 HStack { | 50 HStack { |
51 Image(systemName: "heart.fill") | 51 Image(systemName: "heart.fill") |
52 Text("\(userLives)") | 52 Text("\(game.userLives)") |
53 } | 53 } |
54 .padding(10) | 54 .padding(10) |
55 .background( | 55 .background( |
56 Capsule() | 56 Capsule() |
57 .strokeBorder(lineWidth: 2) | 57 .strokeBorder(lineWidth: 2) |
58 ) | 58 ) |
59 .scaleEffect(game.livesScaleAmount) | |
59 } | 60 } |
60 } | 61 } |
61 .foregroundColor(.white) | 62 .foregroundColor(.white) |
62 .font(.headline) | 63 .font(.headline) |
63 .frame(maxWidth: .infinity, alignment: .trailing) | 64 .frame(maxWidth: .infinity, alignment: .trailing) |
72 .ignoresSafeArea() | 73 .ignoresSafeArea() |
73 | 74 |
74 GeometryReader { geo in | 75 GeometryReader { geo in |
75 VStack { | 76 VStack { |
76 GameToolbar( | 77 GameToolbar( |
77 userScore: .constant(0), | 78 gameName: .constant(GameName.guessTheFlag), |
78 userLives: .constant(6), | 79 game: GuessTheFlag() |
79 gameName: .constant(.guessTheFlag), showingBuyLivesView: .constant(false) | |
80 ) | 80 ) |
81 | 81 |
82 Spacer() | 82 Spacer() |
83 } | 83 } |
84 .padding() | 84 .padding() |