Checken ob match gefunden wurde
This commit is contained in:
parent
54d31d929d
commit
e21395d0db
@ -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()
|
||||
}
|
||||
|
@ -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))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user