comparison GeoQuiz/Helpers/GameToolbar.swift @ 26:425078c01194

refactor code
author Dennis C. M. <dennis@denniscm.com>
date Wed, 09 Nov 2022 10:30:01 +0100
parents GeoQuiz/Components/GameToolbar.swift@e281791e0494
children
comparison
equal deleted inserted replaced
25:b3df0f5dc750 26:425078c01194
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
10 struct GameToolbar<T: Game>: View {
11 @ObservedObject var gameController: T
12
13 var color: Color
14
15 var body: some View {
16 HStack(spacing: 0) {
17 Group {
18 Button {
19 gameController.showingExitGameAlert = true
20 } label: {
21 Image(systemName: "multiply")
22 .font(.headline)
23 .foregroundColor(color)
24 .padding(10)
25 .background(
26 Circle()
27 .foregroundColor(.white)
28 )
29 }
30 }
31 .font(.headline)
32 .frame(maxWidth: .infinity, alignment: .leading)
33
34 Group {
35 Text("\(gameController.userScore)")
36 .font(.title.bold())
37 .foregroundColor(color)
38 .padding()
39 .background(
40 Group {
41 if gameController.userScore < 1000 {
42 Circle()
43 } else {
44 Capsule()
45 }
46 }
47 .foregroundColor(.white)
48 )
49 }
50 .font(.title2)
51 .scaleEffect(gameController.scoreScaleAmount)
52 .frame(maxWidth: .infinity, alignment: .center)
53
54 Group {
55 HStack {
56 Image(systemName: "heart.fill")
57 Text("\(gameController.userLives)")
58 }
59 .font(.headline)
60 .foregroundColor(color)
61 .padding(10)
62 .background(
63 Capsule()
64 .foregroundColor(.white)
65 )
66 .scaleEffect(gameController.livesScaleAmount)
67 }
68 .font(.headline)
69 .frame(maxWidth: .infinity, alignment: .trailing)
70 }
71 }
72 }
73
74 struct GameToolbar_Previews: PreviewProvider {
75 static var previews: some View {
76 ZStack {
77 LinearGradient(gradient: .main, startPoint: .top, endPoint: .bottom)
78 .ignoresSafeArea()
79
80 GeometryReader { geo in
81 VStack {
82 GameToolbar(gameController: CountryGameController(), color: .mayaBlue)
83
84 Spacer()
85 }
86 .padding()
87 }
88 }
89 }
90 }