From 53f7668bd1973f6441a86b0a66c280aa259f056d Mon Sep 17 00:00:00 2001 From: Tiago Rodrigues Date: Sat, 3 Feb 2024 12:12:55 +0000 Subject: [PATCH] new game, guess aws service name --- ios/Shared/DataModels/AwsServices.swift | 13 +++++++-- ios/Shared/MainViews/Game.swift | 38 +++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/ios/Shared/DataModels/AwsServices.swift b/ios/Shared/DataModels/AwsServices.swift index 3290368..8a1327e 100644 --- a/ios/Shared/DataModels/AwsServices.swift +++ b/ios/Shared/DataModels/AwsServices.swift @@ -10,13 +10,22 @@ import Foundation var fm = FileManager.default var subUrl: URL? var mainUrl: URL? = Bundle.main.url(forResource: "aws_services", withExtension: "json") +var lastRandom: awsService = awsService(id: 10, name: "DeepRacer", longName: "AWS DeepRacer", shortDesctiption: "DeepRacer", imageURL: "https://static.tig.pt/awsary/logos/Arch_AWS-DeepRacer_64@5x.png", youtube_id: "") class AwsServices: ObservableObject { @Published var services = [awsService]() - + + func getNameOfLastRandom() -> String { + return lastRandom.longName + } + + func getLastRandom() -> awsService { + return lastRandom + } func getRandomElement() -> awsService{ - return services.randomElement()! + lastRandom = services.randomElement()! + return lastRandom } init() { refresh() diff --git a/ios/Shared/MainViews/Game.swift b/ios/Shared/MainViews/Game.swift index fd6811a..4f3ec92 100644 --- a/ios/Shared/MainViews/Game.swift +++ b/ios/Shared/MainViews/Game.swift @@ -8,9 +8,41 @@ import SwiftUI struct Game: View { - var body: some View { - Text("Hello, World from GAME!") - } + @ObservedObject var awsServices = AwsServices() + @State private var showServiceName = false + + var body: some View { + var lastRandomService: awsService = awsServices.getLastRandom() + VStack{ + Spacer() + Text("Name the AWS service") + .font(.title).bold() + AWSserviceImagePlaceHolderView(service: lastRandomService, showLabel: false) + .frame(minHeight: 140) + if (showServiceName){ + Text(awsServices.getNameOfLastRandom()).font(.title) + .multilineTextAlignment(.center) + } else { + Text(" ").font(.title) + } + Spacer() + if(showServiceName){ + Button(action: { + if (showServiceName){ + lastRandomService = awsServices.getRandomElement() + showServiceName = false + } + }, label: { + Text("Generate a new Random Service") + }) + }else { + Button(action: {showServiceName = true}, label: { + Text("Reveal") + }) + } + Spacer() + } + } } #Preview {