Checken ob match gefunden wurde
This commit is contained in:
parent
54d31d929d
commit
e21395d0db
@ -2,7 +2,7 @@
|
|||||||
// MatchmakingHelper.swift
|
// MatchmakingHelper.swift
|
||||||
// GoldWars
|
// 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.
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
@ -40,6 +40,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
func presentMatchmaker() {
|
func presentMatchmaker() {
|
||||||
|
print("I'm in 43")
|
||||||
guard GKLocalPlayer.local.isAuthenticated else {
|
guard GKLocalPlayer.local.isAuthenticated else {
|
||||||
print("Player ist nicht authentifiziert")
|
print("Player ist nicht authentifiziert")
|
||||||
return
|
return
|
||||||
@ -74,12 +75,14 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
|
|
||||||
//The user has cancelled matchmaking
|
//The user has cancelled matchmaking
|
||||||
func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) {
|
func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) {
|
||||||
|
print("I'm in 78")
|
||||||
viewController.dismiss(animated: true, completion: nil)
|
viewController.dismiss(animated: true, completion: nil)
|
||||||
delegate?.matchEnded()
|
delegate?.matchEnded()
|
||||||
}
|
}
|
||||||
|
|
||||||
//Matchmaking has failed with an error
|
//Matchmaking has failed with an error
|
||||||
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFailWithError error: Error) {
|
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFailWithError error: Error) {
|
||||||
|
print("I'm in 85")
|
||||||
viewController.dismiss(animated: true, completion: nil)
|
viewController.dismiss(animated: true, completion: nil)
|
||||||
print("Error finding match", error.localizedDescription)
|
print("Error finding match", error.localizedDescription)
|
||||||
delegate?.matchEnded()
|
delegate?.matchEnded()
|
||||||
@ -87,6 +90,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
|
|
||||||
// A peer-to-peer match has been found, the game should start
|
// A peer-to-peer match has been found, the game should start
|
||||||
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) {
|
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) {
|
||||||
|
print("I'm in 93")
|
||||||
viewController.dismiss(animated: true, completion: nil)
|
viewController.dismiss(animated: true, completion: nil)
|
||||||
mpMatch = match
|
mpMatch = match
|
||||||
match.delegate = self
|
match.delegate = self
|
||||||
@ -99,12 +103,14 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
|
|
||||||
// The match received data sent from the player.
|
// The match received data sent from the player.
|
||||||
private func match(match: GKMatch!, didReceiveData data: NSData!,fromPlayer playerID: String!) {
|
private func match(match: GKMatch!, didReceiveData data: NSData!,fromPlayer playerID: String!) {
|
||||||
|
print("I'm in 106")
|
||||||
if mpMatch != match { return }
|
if mpMatch != match { return }
|
||||||
delegate?.matchReceivedData(match: match, data: data, fromPlayer:
|
delegate?.matchReceivedData(match: match, data: data, fromPlayer:
|
||||||
playerID)
|
playerID)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func match(match: GKMatch!, didFailWithError error: NSError!) {
|
private func match(match: GKMatch!, didFailWithError error: NSError!) {
|
||||||
|
print("I'm in 113")
|
||||||
if mpMatch != match {
|
if mpMatch != match {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -114,6 +120,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
|
|
||||||
// The player state changed (eg. connected or disconnected)
|
// The player state changed (eg. connected or disconnected)
|
||||||
func match(_ match: GKMatch, player: GKPlayer, didChange state: GKPlayerConnectionState) {
|
func match(_ match: GKMatch, player: GKPlayer, didChange state: GKPlayerConnectionState) {
|
||||||
|
print("I'm in 123")
|
||||||
if mpMatch != match {
|
if mpMatch != match {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -129,7 +136,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
case GKPlayerConnectionState.disconnected:
|
case GKPlayerConnectionState.disconnected:
|
||||||
print("Player disconnected!")
|
print("Player disconnected!")
|
||||||
mpMatchStarted = false
|
mpMatchStarted = false
|
||||||
delegate!.matchEnded()
|
delegate?.matchEnded()
|
||||||
default:
|
default:
|
||||||
print("Player unknown status!")
|
print("Player unknown status!")
|
||||||
}
|
}
|
||||||
@ -138,7 +145,9 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
func startMatch() {
|
func startMatch() {
|
||||||
mpMatch!.chooseBestHostingPlayer(completionHandler: {
|
mpMatch!.chooseBestHostingPlayer(completionHandler: {
|
||||||
(player) in
|
(player) in
|
||||||
|
print("I'm in 147")
|
||||||
self.mpMatchStarted = true
|
self.mpMatchStarted = true
|
||||||
|
print(self.mpMatchStarted)
|
||||||
if player == GKLocalPlayer.local {
|
if player == GKLocalPlayer.local {
|
||||||
print("I am the server")
|
print("I am the server")
|
||||||
self.isServer = true
|
self.isServer = true
|
||||||
@ -148,11 +157,12 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
self.serverPlayer = player
|
self.serverPlayer = player
|
||||||
|
|
||||||
}
|
}
|
||||||
self.delegate!.matchStarted()
|
self.delegate?.matchStarted()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func disconnect() {
|
func disconnect() {
|
||||||
|
print("I'm in 164")
|
||||||
if mpMatch != nil {
|
if mpMatch != nil {
|
||||||
mpMatch?.disconnect()
|
mpMatch?.disconnect()
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,11 @@ class MenuScene: SKScene {
|
|||||||
position: CGPoint(x: midX, y: midY),
|
position: CGPoint(x: midX, y: midY),
|
||||||
onButtonPress: {
|
onButtonPress: {
|
||||||
MatchmakingHelper.sharedInstance.presentMatchmaker()
|
MatchmakingHelper.sharedInstance.presentMatchmaker()
|
||||||
|
print(MatchmakingHelper.sharedInstance.mpMatchStarted)
|
||||||
|
// if MatchmakingHelper.sharedInstance.mpMatchStarted{
|
||||||
self.loadScene(scene: GameScene(size: self.size))
|
self.loadScene(scene: GameScene(size: self.size))
|
||||||
|
print(MatchmakingHelper.sharedInstance.mpMatchStarted)
|
||||||
|
// }
|
||||||
}))
|
}))
|
||||||
entityManager.add(Button(name: "settingsButton",
|
entityManager.add(Button(name: "settingsButton",
|
||||||
iconName: "",
|
iconName: "",
|
||||||
@ -31,7 +34,6 @@ class MenuScene: SKScene {
|
|||||||
position: CGPoint(x: midX, y: midY - 80 ),
|
position: CGPoint(x: midX, y: midY - 80 ),
|
||||||
onButtonPress: {
|
onButtonPress: {
|
||||||
//TODO: create Settings Scene
|
//TODO: create Settings Scene
|
||||||
MatchmakingHelper.sharedInstance.presentMatchmaker()
|
|
||||||
}))
|
}))
|
||||||
entityManager.add(Background(size: self.size))
|
entityManager.add(Background(size: self.size))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user