From e21395d0dbb79d82544e4d89e6b38530fcdf3163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chauntalle=20Schu=CC=88le?= Date: Mon, 4 May 2020 21:44:50 +0200 Subject: [PATCH] Checken ob match gefunden wurde --- GoldWars/GoldWars/MatchmakingHelper.swift | 16 +++++++++++++--- GoldWars/GoldWars/Scenes/MenuScene.swift | 6 ++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/GoldWars/GoldWars/MatchmakingHelper.swift b/GoldWars/GoldWars/MatchmakingHelper.swift index d546c0e..41b09ac 100644 --- a/GoldWars/GoldWars/MatchmakingHelper.swift +++ b/GoldWars/GoldWars/MatchmakingHelper.swift @@ -2,7 +2,7 @@ // MatchmakingHelper.swift // GoldWars // -// Created by Chauntalle Schüle on 03.05.20. +// Created by Chauntalle Schüle, Ömer Özel, Eray Kör on 03.05.20. // Copyright © 2020 SP2. All rights reserved. // @@ -40,6 +40,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe } func presentMatchmaker() { + print("I'm in 43") guard GKLocalPlayer.local.isAuthenticated else { print("Player ist nicht authentifiziert") return @@ -74,12 +75,14 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe //The user has cancelled matchmaking func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) { + print("I'm in 78") viewController.dismiss(animated: true, completion: nil) delegate?.matchEnded() } //Matchmaking has failed with an error func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFailWithError error: Error) { + print("I'm in 85") viewController.dismiss(animated: true, completion: nil) print("Error finding match", error.localizedDescription) delegate?.matchEnded() @@ -87,6 +90,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe // A peer-to-peer match has been found, the game should start func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) { + print("I'm in 93") viewController.dismiss(animated: true, completion: nil) mpMatch = match match.delegate = self @@ -99,12 +103,14 @@ 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) } private func match(match: GKMatch!, didFailWithError error: NSError!) { + print("I'm in 113") if mpMatch != match { return } @@ -114,6 +120,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe // The player state changed (eg. connected or disconnected) func match(_ match: GKMatch, player: GKPlayer, didChange state: GKPlayerConnectionState) { + print("I'm in 123") if mpMatch != match { return } @@ -129,7 +136,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe case GKPlayerConnectionState.disconnected: print("Player disconnected!") mpMatchStarted = false - delegate!.matchEnded() + delegate?.matchEnded() default: print("Player unknown status!") } @@ -138,7 +145,9 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe func startMatch() { mpMatch!.chooseBestHostingPlayer(completionHandler: { (player) in + print("I'm in 147") self.mpMatchStarted = true + print(self.mpMatchStarted) if player == GKLocalPlayer.local { print("I am the server") self.isServer = true @@ -148,11 +157,12 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe self.serverPlayer = player } - self.delegate!.matchStarted() + self.delegate?.matchStarted() }) } func disconnect() { + print("I'm in 164") if mpMatch != nil { mpMatch?.disconnect() } diff --git a/GoldWars/GoldWars/Scenes/MenuScene.swift b/GoldWars/GoldWars/Scenes/MenuScene.swift index b4cda64..e6b80a3 100644 --- a/GoldWars/GoldWars/Scenes/MenuScene.swift +++ b/GoldWars/GoldWars/Scenes/MenuScene.swift @@ -22,8 +22,11 @@ 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: "", @@ -31,7 +34,6 @@ class MenuScene: SKScene { position: CGPoint(x: midX, y: midY - 80 ), onButtonPress: { //TODO: create Settings Scene - MatchmakingHelper.sharedInstance.presentMatchmaker() })) entityManager.add(Background(size: self.size)) }