Mercurial > public > geoquiz
diff GeoQuiz/Components/GameToolbar.swift @ 20:e281791e0494
finish implementation
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Sun, 23 Oct 2022 11:48:39 +0100 |
parents | GeoQuiz/Components/GameToolbarHelper.swift@f140bb277c96 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GeoQuiz/Components/GameToolbar.swift Sun Oct 23 11:48:39 2022 +0100 @@ -0,0 +1,90 @@ +// +// GameToolbar.swift +// GeoQuiz +// +// Created by Dennis Concepción Martín on 18/9/22. +// + +import SwiftUI + +struct GameToolbar<T: Game>: View { + @ObservedObject var game: T + + var color: Color + + var body: some View { + HStack(spacing: 0) { + Group { + Button { + game.showingExitGameAlert = true + } label: { + Image(systemName: "multiply") + .font(.headline) + .foregroundColor(color) + .padding(10) + .background( + Circle() + .foregroundColor(.white) + ) + } + } + .font(.headline) + .frame(maxWidth: .infinity, alignment: .leading) + + Group { + Text("\(game.userScore)") + .font(.title.bold()) + .foregroundColor(color) + .padding() + .background( + Group { + if game.userScore < 1000 { + Circle() + } else { + Capsule() + } + } + .foregroundColor(.white) + ) + } + .font(.title2) + .scaleEffect(game.scoreScaleAmount) + .frame(maxWidth: .infinity, alignment: .center) + + Group { + HStack { + Image(systemName: "heart.fill") + Text("\(game.userLives)") + } + .font(.headline) + .foregroundColor(color) + .padding(10) + .background( + Capsule() + .foregroundColor(.white) + ) + .scaleEffect(game.livesScaleAmount) + } + .font(.headline) + .frame(maxWidth: .infinity, alignment: .trailing) + } + } +} + +struct GameToolbar_Previews: PreviewProvider { + static var previews: some View { + ZStack { + LinearGradient(gradient: .main, startPoint: .top, endPoint: .bottom) + .ignoresSafeArea() + + GeometryReader { geo in + VStack { + GameToolbar(game: CountryGameController(), color: .mayaBlue) + + Spacer() + } + .padding() + } + } + } +}