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
|
6
|
13 var color: Color
|
0
|
14
|
|
15 var body: some View {
|
|
16 HStack(spacing: 0) {
|
|
17 Group {
|
|
18 Button {
|
4
|
19 game.showingExitGameAlert = true
|
0
|
20 } label: {
|
|
21 Image(systemName: "multiply")
|
6
|
22 .font(.headline)
|
|
23 .foregroundColor(color)
|
0
|
24 .padding(10)
|
|
25 .background(
|
|
26 Circle()
|
7
|
27 .foregroundStyle(.regularMaterial)
|
0
|
28 )
|
|
29 }
|
|
30 }
|
|
31 .font(.headline)
|
|
32 .frame(maxWidth: .infinity, alignment: .leading)
|
|
33
|
|
34 Group {
|
7
|
35 Text("\(game.userScore)")
|
|
36 .font(.title.bold())
|
|
37 .foregroundColor(color)
|
|
38 .padding()
|
|
39 .background(
|
|
40 Circle()
|
|
41 .foregroundStyle(.regularMaterial)
|
|
42 )
|
0
|
43 }
|
|
44 .font(.title2)
|
3
|
45 .scaleEffect(game.scoreScaleAmount)
|
0
|
46 .frame(maxWidth: .infinity, alignment: .center)
|
|
47
|
|
48 Group {
|
7
|
49 HStack {
|
|
50 Image(systemName: "heart.fill")
|
|
51 Text("\(game.userLives)")
|
0
|
52 }
|
7
|
53 .font(.headline)
|
|
54 .foregroundColor(color)
|
|
55 .padding(10)
|
|
56 .background(
|
|
57 Capsule()
|
|
58 .foregroundStyle(.regularMaterial)
|
|
59 )
|
|
60 .scaleEffect(game.livesScaleAmount)
|
0
|
61 }
|
|
62 .font(.headline)
|
|
63 .frame(maxWidth: .infinity, alignment: .trailing)
|
|
64 }
|
|
65 }
|
|
66 }
|
|
67
|
|
68 struct GameToolbar_Previews: PreviewProvider {
|
|
69 static var previews: some View {
|
|
70 ZStack {
|
|
71 LinearGradient(gradient: .main, startPoint: .top, endPoint: .bottom)
|
|
72 .ignoresSafeArea()
|
|
73
|
|
74 GeometryReader { geo in
|
|
75 VStack {
|
6
|
76 GameToolbar(game: CountryGame(), color: .mayaBlue)
|
0
|
77
|
|
78 Spacer()
|
|
79 }
|
|
80 .padding()
|
|
81 }
|
|
82 }
|
|
83 }
|
|
84 }
|