From 3c4ae97b613ae636e417a75895c2f5efc3242a9c Mon Sep 17 00:00:00 2001 From: Niko Jochim <82joni1bif@hft-stuttgart.de> Date: Thu, 18 Jun 2020 19:39:59 +0200 Subject: [PATCH] fix getBackground to return a optional --- GoldWars/GoldWars/Entities/EntityManager.swift | 4 ++-- GoldWars/GoldWars/GameCenterManager.swift | 4 ++-- GoldWars/GoldWars/Scenes/GameScene.swift | 9 ++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index 40dc301..8ee6c34 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -277,7 +277,7 @@ class EntityManager { } func getBackground() -> GKEntity? { - return entities.filter{$0 is Background}[0] + return entities.filter{$0 is Background}.first } func getBaseNodeByTeam(for team: Team) -> SKSpriteNode? { @@ -289,7 +289,7 @@ class EntityManager { } func getHUD() -> HUD? { - return entities.filter{$0 is HUD}[0] as? HUD + return entities.filter{$0 is HUD}.first as? HUD } func getSnapshotModel() -> SnapshotModel { diff --git a/GoldWars/GoldWars/GameCenterManager.swift b/GoldWars/GoldWars/GameCenterManager.swift index a4ce191..a6e949c 100644 --- a/GoldWars/GoldWars/GameCenterManager.swift +++ b/GoldWars/GoldWars/GameCenterManager.swift @@ -45,7 +45,7 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG var localPlayerRandomNumber: RandomNumber? var initIsFinish = false var gameEnded = false - var winner:String? + var winner: String? var gameScene: GameScene? static var isAuthenticated: Bool { return GKLocalPlayer.local.isAuthenticated @@ -58,7 +58,7 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG localPlayerRandomNumber = RandomNumber() } - func reset(){ + func reset() { isMatchStarted = false isServer = false localPlayerRandomNumber = RandomNumber() diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index de3f4b9..8c7472d 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -77,11 +77,9 @@ class GameScene: SKScene{ } override func update(_ currentTime: TimeInterval) { - if entityManager.entities.count != 0 { - entityManager.getBackground()?.update(deltaTime: currentTime) - if GameCenterManager.sharedInstance.gameEnded && !gameEndEffects { - gameEnd() - } + entityManager.getBackground()?.update(deltaTime: currentTime) + if GameCenterManager.sharedInstance.gameEnded && !gameEndEffects { + gameEnd() } } @@ -128,6 +126,7 @@ class GameScene: SKScene{ } func gameEnd(){ + entityManager.getHUD()?.blockWholeScreenPane.isHidden = true gameEndEffects = true GameCenterManager.sharedInstance.gameEnded = false let move = SKAction.move(to: CGPoint(x: self.size.width / 2, y: self.size.height / 2), duration: 1)