0
|
1 //
|
|
2 // GameToolbar.swift
|
|
3 // GeoQuiz
|
|
4 //
|
|
5 // Created by Dennis Concepción Martín on 18/9/22.
|
|
6 //
|
|
7
|
|
8 import SwiftUI
|
|
9
|
3
|
10 struct GameToolbar<T: Game>: View {
|
|
11 @ObservedObject var game: T
|
|
12
|
0
|
13
|
|
14 var body: some View {
|
|
15 HStack(spacing: 0) {
|
|
16 Group {
|
|
17 Button {
|
4
|
18 game.showingExitGameAlert = true
|
0
|
19 } label: {
|
|
20 Image(systemName: "multiply")
|
|
21 .padding(10)
|
|
22 .background(
|
|
23 Circle()
|
|
24 .strokeBorder(lineWidth: 2)
|
|
25 )
|
|
26 }
|
|
27 }
|
|
28 .foregroundColor(.white)
|
|
29 .font(.headline)
|
|
30 .frame(maxWidth: .infinity, alignment: .leading)
|
|
31
|
|
32 Group {
|
4
|
33 Button {
|
|
34 game.showingGameStatsView = true
|
|
35 } label: {
|
|
36 Text("\(game.userScore)")
|
|
37 .padding()
|
|
38 .background(
|
|
39 Circle()
|
|
40 .strokeBorder(lineWidth: 3)
|
|
41 )
|
|
42 }
|
0
|
43 }
|
|
44 .foregroundColor(.white)
|
|
45 .font(.title2)
|
3
|
46 .scaleEffect(game.scoreScaleAmount)
|
0
|
47 .frame(maxWidth: .infinity, alignment: .center)
|
|
48
|
|
49 Group {
|
|
50 Button {
|
3
|
51 game.showingBuyLivesView = true
|
0
|
52 } label: {
|
|
53 HStack {
|
|
54 Image(systemName: "heart.fill")
|
3
|
55 Text("\(game.userLives)")
|
0
|
56 }
|
|
57 .padding(10)
|
|
58 .background(
|
|
59 Capsule()
|
|
60 .strokeBorder(lineWidth: 2)
|
|
61 )
|
3
|
62 .scaleEffect(game.livesScaleAmount)
|
0
|
63 }
|
|
64 }
|
|
65 .foregroundColor(.white)
|
|
66 .font(.headline)
|
|
67 .frame(maxWidth: .infinity, alignment: .trailing)
|
|
68 }
|
|
69 }
|
|
70 }
|
|
71
|
|
72 struct GameToolbar_Previews: PreviewProvider {
|
|
73 static var previews: some View {
|
|
74 ZStack {
|
|
75 LinearGradient(gradient: .main, startPoint: .top, endPoint: .bottom)
|
|
76 .ignoresSafeArea()
|
|
77
|
|
78 GeometryReader { geo in
|
|
79 VStack {
|
4
|
80 GameToolbar(game: GuessTheFlag())
|
0
|
81
|
|
82 Spacer()
|
|
83 }
|
|
84 .padding()
|
|
85 }
|
|
86 }
|
|
87 }
|
|
88 }
|