From e1d5af8a4a01f5d83b7e1ce12616a3500641a48d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chauntalle=20Schu=CC=88le?= Date: Mon, 4 May 2020 23:44:23 +0200 Subject: [PATCH] matchmaking funktioniert --- GoldWars/GoldWars/MatchmakingHelper.swift | 22 +++++++++++++--------- GoldWars/GoldWars/Scenes/MenuScene.swift | 16 +++++++++++----- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/GoldWars/GoldWars/MatchmakingHelper.swift b/GoldWars/GoldWars/MatchmakingHelper.swift index 41b09ac..8a5ef28 100644 --- a/GoldWars/GoldWars/MatchmakingHelper.swift +++ b/GoldWars/GoldWars/MatchmakingHelper.swift @@ -10,9 +10,9 @@ import GameKit protocol GameKitHelperDelegate { func matchStarted() - func matchEnded() - func matchReceivedData(match: GKMatch, data: NSData, - fromPlayer player: String) + // func matchEnded() + // func matchReceivedData(match: GKMatch, data: NSData, + // fromPlayer player: String) } @@ -24,6 +24,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe var mpMatchStarted: Bool var isServer: Bool var serverPlayer: GKPlayer? + var menusc: MenuScene? let localPlayer: GKLocalPlayer = GKLocalPlayer.local static let sharedInstance = MatchmakingHelper() @@ -40,6 +41,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe } func presentMatchmaker() { + // menusc = scene print("I'm in 43") guard GKLocalPlayer.local.isAuthenticated else { print("Player ist nicht authentifiziert") @@ -77,7 +79,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) { print("I'm in 78") viewController.dismiss(animated: true, completion: nil) - delegate?.matchEnded() + // delegate?.matchEnded() } //Matchmaking has failed with an error @@ -85,7 +87,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe print("I'm in 85") viewController.dismiss(animated: true, completion: nil) print("Error finding match", error.localizedDescription) - delegate?.matchEnded() + // delegate?.matchEnded() } // A peer-to-peer match has been found, the game should start @@ -104,9 +106,10 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe // The match received data sent from the player. private func match(match: GKMatch!, didReceiveData data: NSData!,fromPlayer playerID: String!) { print("I'm in 106") + if mpMatch != match { return } - delegate?.matchReceivedData(match: match, data: data, fromPlayer: - playerID) + // delegate?.matchReceivedData(match: match, data: data, fromPlayer: + // playerID) } private func match(match: GKMatch!, didFailWithError error: NSError!) { @@ -115,7 +118,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe return } mpMatchStarted = false - delegate?.matchEnded() + //delegate?.matchEnded() } // The player state changed (eg. connected or disconnected) @@ -136,7 +139,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe case GKPlayerConnectionState.disconnected: print("Player disconnected!") mpMatchStarted = false - delegate?.matchEnded() + // delegate?.matchEnded() default: print("Player unknown status!") } @@ -158,6 +161,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe } self.delegate?.matchStarted() + // self.menusc!.loadScene(scene: GameScene(size: self.menusc!.size)) }) } diff --git a/GoldWars/GoldWars/Scenes/MenuScene.swift b/GoldWars/GoldWars/Scenes/MenuScene.swift index e6b80a3..10c7a8b 100644 --- a/GoldWars/GoldWars/Scenes/MenuScene.swift +++ b/GoldWars/GoldWars/Scenes/MenuScene.swift @@ -22,11 +22,6 @@ class MenuScene: SKScene { position: CGPoint(x: midX, y: midY), onButtonPress: { MatchmakingHelper.sharedInstance.presentMatchmaker() - print(MatchmakingHelper.sharedInstance.mpMatchStarted) - // if MatchmakingHelper.sharedInstance.mpMatchStarted{ - self.loadScene(scene: GameScene(size: self.size)) - print(MatchmakingHelper.sharedInstance.mpMatchStarted) - // } })) entityManager.add(Button(name: "settingsButton", iconName: "", @@ -47,4 +42,15 @@ class MenuScene: SKScene { entityManager.getBackground()!.update(deltaTime: currentTime) entityManager.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterHelper.isAuthenticated } + + +} + +extension MenuScene: GameKitHelperDelegate{ + + + func matchStarted() { + print("halo i bims") + self.loadScene(scene: GameScene(size: self.size)) + } }