diff GeoQuiz/Components/GameButton.swift @ 20:e281791e0494

finish implementation
author Dennis C. M. <dennis@denniscm.com>
date Sun, 23 Oct 2022 11:48:39 +0100
parents GeoQuiz/Components/GameButtonHelper.swift@f140bb277c96
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GeoQuiz/Components/GameButton.swift	Sun Oct 23 11:48:39 2022 +0100
@@ -0,0 +1,64 @@
+//
+//  GameButton.swift
+//  GeoQuiz
+//
+//  Created by Dennis Concepción Martín on 5/9/22.
+//
+
+import SwiftUI
+
+struct GameButton: View {
+    let gameInfo: GameInfo
+    let isActive: Bool
+    
+    init(gameType: GameType, isActive: Bool) {
+        self.gameInfo = GameInfoController.getInfo(for: gameType)
+        self.isActive = isActive
+    }
+    
+    var body: some View {
+        RoundedRectangle(cornerRadius: 20)
+            .fill(
+                LinearGradient(
+                    gradient: gameInfo.gradient,
+                    startPoint: .trailing, endPoint: .leading
+                )
+            )
+            .frame(height: 180)
+            .frame(maxWidth: 700)
+            .overlay {
+                ZStack(alignment: .trailing) {
+                    VStack(alignment: .leading) {
+                        HStack {
+                            Image(systemName: isActive ? gameInfo.symbol : "lock.fill")
+                                .font(.headline)
+                                .padding(5)
+                                .background(
+                                    RoundedRectangle(cornerRadius: 5)
+                                        .stroke(lineWidth: 1.5)
+                                )
+                            
+                            Spacer()
+                        }
+                        .padding(.bottom)
+                        
+                        VStack(alignment: .leading, spacing: 5) {
+                            Text(gameInfo.level)
+                                .font(.callout)
+                            
+                            Text(gameInfo.name)
+                                .font(.title.bold())
+                        }
+                    }
+                    .foregroundColor(.white)
+                    .padding()
+                }
+            }
+    }
+}
+
+struct GameButton_Previews: PreviewProvider {
+    static var previews: some View {
+        GameButton(gameType: .guessTheFlag, isActive: false)
+    }
+}