comparison GeoQuiz/Components/RecentGameHelper.swift @ 16:1011e56b7832

implement user profile
author Dennis C. M. <dennis@denniscm.com>
date Thu, 20 Oct 2022 13:49:42 +0200
parents
children 8dac58bb4569
comparison
equal deleted inserted replaced
15:f1967f8cc67b 16:1011e56b7832
1 //
2 // RecentGameHelper.swift
3 // GeoQuiz
4 //
5 // Created by Dennis Concepción Martín on 19/10/22.
6 //
7
8 import SwiftUI
9
10 struct RecentGame: View {
11 let game: PlayedGame
12 let name: String
13 let gradient: Gradient
14 let symbol: String
15
16 var body: some View {
17 HStack(alignment: .center, spacing: 15) {
18 RoundedRectangle(cornerRadius: 5)
19 .fill(
20 LinearGradient(
21 gradient: gradient,
22 startPoint: .top, endPoint: .bottom
23 )
24 )
25 .frame(width: 35, height: 35)
26 .overlay(
27 Image(systemName: symbol)
28 .font(.headline)
29 .foregroundColor(.white)
30 .padding(5)
31 )
32
33 VStack(alignment: .leading) {
34 Text(name)
35 .font(.headline)
36
37 Text("\(game.date, format: .dateTime)")
38 .font(.callout)
39 .foregroundColor(.secondary)
40 }
41
42 Spacer()
43
44 Text("\(game.score, format: .number) ⭐️")
45
46 }
47 .padding()
48 .background(
49 RoundedRectangle(cornerRadius: 20)
50 .foregroundColor(.white)
51 )
52 }
53
54 init(game: PlayedGame) {
55 self.game = game
56
57 switch game.type {
58 case .guessTheFlag:
59 self.name = GuessTheFlagInfo.name
60 self.gradient = GuessTheFlagInfo.gradient
61 self.symbol = GuessTheFlagInfo.symbol
62 case .guessTheCapital:
63 self.name = GuessTheCapitalInfo.name
64 self.gradient = GuessTheCapitalInfo.gradient
65 self.symbol = GuessTheCapitalInfo.symbol
66 case .guessTheCountry:
67 self.name = GuessTheCountryInfo.name
68 self.gradient = GuessTheCountryInfo.gradient
69 self.symbol = GuessTheCountryInfo.symbol
70 case .guessThePopulation:
71 self.name = GuessThePopulationInfo.name
72 self.gradient = GuessThePopulationInfo.gradient
73 self.symbol = GuessThePopulationInfo.symbol
74 }
75 }
76 }