matchmaking funktioniert

This commit is contained in:
Chauntalle Schüle 2020-05-04 23:44:23 +02:00 committed by Chauntalle Schüle
parent e21395d0db
commit e1d5af8a4a
2 changed files with 24 additions and 14 deletions

View File

@ -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))
})
}

View File

@ -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))
}
}