minor refactoring

This commit is contained in:
127-Z3R0 2020-06-02 22:18:59 +02:00
parent 09062d5f5d
commit cbf288e86d
2 changed files with 30 additions and 29 deletions

View File

@ -131,35 +131,35 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
} }
if let state = try? jsonDecoder.decode(State.self, from: data) { if let state = try? jsonDecoder.decode(State.self, from: data) {
switch state.state { switch state.state {
case 0: case 0:
os_log("State 0 erhalten", log: LOG, type: .info) os_log("State 0 erhalten", log: LOG, type: .info)
sendStateToPeers(state: State(state: 1)) sendStateToPeers(state: State(state: 1))
case 1: case 1:
os_log("State 1 erhalten", log: LOG, type: .info) os_log("State 1 erhalten", log: LOG, type: .info)
if isServer { if isServer {
os_log("Peer hat Player initialisiert", log: LOG, type: .info) os_log("Peer hat Player initialisiert", log: LOG, type: .info)
initAndSendMap() initAndSendMap()
}else { }else {
os_log("Host hat Player initialisiert", log: LOG, type: .info) os_log("Host hat Player initialisiert", log: LOG, type: .info)
} }
case 2: case 2:
os_log("State 2 erhalten", log: LOG, type: .info) os_log("State 2 erhalten", log: LOG, type: .info)
sendStateToPeers(state: State(state: 3)) sendStateToPeers(state: State(state: 3))
initIsFinish = true initIsFinish = true
os_log("Spiel startet", log: LOG, type: .info) os_log("Spiel startet", log: LOG, type: .info)
case 3: case 3:
os_log("State 3 erhalten", log: LOG, type: .info) os_log("State 3 erhalten", log: LOG, type: .info)
initIsFinish = true initIsFinish = true
os_log("Spiel startet", log: LOG, type: .info) os_log("Spiel startet", log: LOG, type: .info)
case 4: case 4:
os_log("State 4 erhalten, Peer hat verloren", log: LOG, type: .info) os_log("State 4 erhalten, Peer hat verloren", log: LOG, type: .info)
// TODO: Trigger Loser Scene // TODO: Trigger Loser Scene
case 5: case 5:
os_log("State 5 erhalten, Peer hat gewonnen", log: LOG, type: .info) os_log("State 5 erhalten, Peer hat gewonnen", log: LOG, type: .info)
// TODO: Trigger Winner Scene // TODO: Trigger Winner Scene
default: default:
break break
} }
} }
if let roundData = try? jsonDecoder.decode(LocalRoundData.self, from: data) { if let roundData = try? jsonDecoder.decode(LocalRoundData.self, from: data) {

View File

@ -158,6 +158,7 @@ class RoundCalculatorService {
winner = determineWinner(by: "capture") winner = determineWinner(by: "capture")
} }
winner == GameCenterManager.sharedInstance.hostingPlayer?.displayName ? GameCenterManager.sharedInstance.sendStateToPeers(state: State(state: 4)) : GameCenterManager.sharedInstance.sendStateToPeers(state: State(state: 5)) winner == GameCenterManager.sharedInstance.hostingPlayer?.displayName ? GameCenterManager.sharedInstance.sendStateToPeers(state: State(state: 4)) : GameCenterManager.sharedInstance.sendStateToPeers(state: State(state: 5))
//TODO: Trigger Winner/Loser-Scene for Server
return return
} }
currentRound += 1 currentRound += 1