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
|
|
10 struct GameToolbar: View {
|
|
11 @Binding var userScore: Int
|
|
12 @Binding var userLives: Int
|
|
13 @Binding var gameName: GameName?
|
|
14 @Binding var showingBuyLivesView: Bool
|
|
15
|
|
16 var body: some View {
|
|
17 HStack(spacing: 0) {
|
|
18 Group {
|
|
19 Button {
|
|
20 gameName = nil
|
|
21 } label: {
|
|
22 Image(systemName: "multiply")
|
|
23 .padding(10)
|
|
24 .background(
|
|
25 Circle()
|
|
26 .strokeBorder(lineWidth: 2)
|
|
27 )
|
|
28 }
|
|
29 }
|
|
30 .foregroundColor(.white)
|
|
31 .font(.headline)
|
|
32 .frame(maxWidth: .infinity, alignment: .leading)
|
|
33
|
|
34 Group {
|
|
35 Text("\(userScore)")
|
|
36 .padding()
|
|
37 .background(
|
|
38 Circle()
|
|
39 .strokeBorder(lineWidth: 3)
|
|
40 )
|
|
41 }
|
|
42 .foregroundColor(.white)
|
|
43 .font(.title2)
|
|
44 .frame(maxWidth: .infinity, alignment: .center)
|
|
45
|
|
46 Group {
|
|
47 Button {
|
|
48 showingBuyLivesView = true
|
|
49 } label: {
|
|
50 HStack {
|
|
51 Image(systemName: "heart.fill")
|
|
52 Text("\(userLives)")
|
|
53 }
|
|
54 .padding(10)
|
|
55 .background(
|
|
56 Capsule()
|
|
57 .strokeBorder(lineWidth: 2)
|
|
58 )
|
|
59 }
|
|
60 }
|
|
61 .foregroundColor(.white)
|
|
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 {
|
|
76 GameToolbar(
|
|
77 userScore: .constant(0),
|
|
78 userLives: .constant(6),
|
|
79 gameName: .constant(.guessTheFlag), showingBuyLivesView: .constant(false)
|
|
80 )
|
|
81
|
|
82 Spacer()
|
|
83 }
|
|
84 .padding()
|
|
85 }
|
|
86 }
|
|
87 }
|
|
88 }
|