Impl. neccessary Server identifier
This commit is contained in:
parent
d2f32f41ee
commit
ce4d2fe8a2
@ -20,6 +20,7 @@
|
||||
2086465C2461B66200817C23 /* TimerComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2086465B2461B66200817C23 /* TimerComponent.swift */; };
|
||||
3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */; };
|
||||
3EBD242E245D9332003CECE7 /* Team.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3EBD242D245D9332003CECE7 /* Team.swift */; };
|
||||
3FE19DB3246C690B004827AB /* RoundSimulatorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FE19DB2246C690B004827AB /* RoundSimulatorService.swift */; };
|
||||
9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */; };
|
||||
9E11FF79245CD81100EED3BE /* Fire.sks in Resources */ = {isa = PBXBuildFile; fileRef = 9E11FF77245CD81100EED3BE /* Fire.sks */; };
|
||||
9E174C82245DD81D00209FF0 /* ButtonNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E174C81245DD81D00209FF0 /* ButtonNode.swift */; };
|
||||
@ -38,7 +39,7 @@
|
||||
9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEC245C8143006BC61D /* ModalBackgroundComponent.swift */; };
|
||||
9EA3ABEF245C834B006BC61D /* ModalContentComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */; };
|
||||
9EBFD7552462CF5A00E1E219 /* SliderComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EBFD7542462CF5A00E1E219 /* SliderComponent.swift */; };
|
||||
9EC239E1246878A900952F74 /* MessageProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC239E0246878A900952F74 /* MessageProtocol.swift */; };
|
||||
9EC239E1246878A900952F74 /* MultiplayerNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC239E0246878A900952F74 /* MultiplayerNetwork.swift */; };
|
||||
9EC7E48B2461FBF700396BCD /* SliderNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC7E48A2461FBF700396BCD /* SliderNode.swift */; };
|
||||
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; };
|
||||
9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; };
|
||||
@ -53,7 +54,7 @@
|
||||
C064E9A8246C0EA50022B228 /* LabelNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = C064E9A7246C0EA50022B228 /* LabelNode.swift */; };
|
||||
C064E9AA246C114C0022B228 /* LabelComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C064E9A9246C114C0022B228 /* LabelComponent.swift */; };
|
||||
C064E9AC246C151F0022B228 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = C064E9AB246C151F0022B228 /* Label.swift */; };
|
||||
C099579C246C5E5C0016AA22 /* PlayerMovesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C099579B246C5E5C0016AA22 /* PlayerMovesService.swift */; };
|
||||
C099579C246C5E5C0016AA22 /* DataService.swift in Sources */ = {isa = PBXBuildFile; fileRef = C099579B246C5E5C0016AA22 /* DataService.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
@ -84,6 +85,7 @@
|
||||
2086465B2461B66200817C23 /* TimerComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimerComponent.swift; sourceTree = "<group>"; };
|
||||
3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GameCenterHelper.swift; sourceTree = "<group>"; };
|
||||
3EBD242D245D9332003CECE7 /* Team.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Team.swift; sourceTree = "<group>"; };
|
||||
3FE19DB2246C690B004827AB /* RoundSimulatorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoundSimulatorService.swift; sourceTree = "<group>"; };
|
||||
9E04AFAE245E2B73002D5CFC /* AttackActionComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttackActionComponent.swift; sourceTree = "<group>"; };
|
||||
9E11FF77245CD81100EED3BE /* Fire.sks */ = {isa = PBXFileReference; lastKnownFileType = file.sks; path = Fire.sks; sourceTree = "<group>"; };
|
||||
9E174C81245DD81D00209FF0 /* ButtonNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonNode.swift; sourceTree = "<group>"; };
|
||||
@ -102,7 +104,7 @@
|
||||
9EA3ABEC245C8143006BC61D /* ModalBackgroundComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalBackgroundComponent.swift; sourceTree = "<group>"; };
|
||||
9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalContentComponent.swift; sourceTree = "<group>"; };
|
||||
9EBFD7542462CF5A00E1E219 /* SliderComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderComponent.swift; sourceTree = "<group>"; };
|
||||
9EC239E0246878A900952F74 /* MessageProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageProtocol.swift; sourceTree = "<group>"; };
|
||||
9EC239E0246878A900952F74 /* MultiplayerNetwork.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiplayerNetwork.swift; sourceTree = "<group>"; };
|
||||
9EC7E48A2461FBF700396BCD /* SliderNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SliderNode.swift; sourceTree = "<group>"; };
|
||||
9EC86B9E245C88A300796EF3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = "<group>"; };
|
||||
9EC86BA5245C8AD000796EF3 /* ModalType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalType.swift; sourceTree = "<group>"; };
|
||||
@ -118,7 +120,7 @@
|
||||
C064E9A7246C0EA50022B228 /* LabelNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelNode.swift; sourceTree = "<group>"; };
|
||||
C064E9A9246C114C0022B228 /* LabelComponent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelComponent.swift; sourceTree = "<group>"; };
|
||||
C064E9AB246C151F0022B228 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = "<group>"; };
|
||||
C099579B246C5E5C0016AA22 /* PlayerMovesService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerMovesService.swift; sourceTree = "<group>"; };
|
||||
C099579B246C5E5C0016AA22 /* DataService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataService.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -175,8 +177,8 @@
|
||||
C05FAED52468559D0006AF2E /* SoundManager.swift */,
|
||||
110360DA244B101A008610AF /* GameViewController.swift */,
|
||||
110360DF244B101B008610AF /* Assets.xcassets */,
|
||||
9EC239E0246878A900952F74 /* MessageProtocol.swift */,
|
||||
C099579B246C5E5C0016AA22 /* PlayerMovesService.swift */,
|
||||
9EC239E0246878A900952F74 /* MultiplayerNetwork.swift */,
|
||||
C099579B246C5E5C0016AA22 /* DataService.swift */,
|
||||
110360E4244B101B008610AF /* Info.plist */,
|
||||
AE151588245F18EF001D363E /* MatchmakingHelper.swift */,
|
||||
3EBD242B245D8044003CECE7 /* GameCenterHelper.swift */,
|
||||
@ -263,6 +265,7 @@
|
||||
children = (
|
||||
110360DC244B101A008610AF /* Main.storyboard */,
|
||||
110360E1244B101B008610AF /* LaunchScreen.storyboard */,
|
||||
3FE19DB2246C690B004827AB /* RoundSimulatorService.swift */,
|
||||
);
|
||||
path = Storyboards;
|
||||
sourceTree = "<group>";
|
||||
@ -392,13 +395,14 @@
|
||||
9E78ACB8245CB75B00526FF7 /* TeamComponent.swift in Sources */,
|
||||
9EA3ABEF245C834B006BC61D /* ModalContentComponent.swift in Sources */,
|
||||
9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */,
|
||||
9EC239E1246878A900952F74 /* MessageProtocol.swift in Sources */,
|
||||
9EC239E1246878A900952F74 /* MultiplayerNetwork.swift in Sources */,
|
||||
9E78ACBE245CC9C000526FF7 /* AtkBoostSkillComponent.swift in Sources */,
|
||||
9E78ACC4245CCA3600526FF7 /* SpySkillComponent.swift in Sources */,
|
||||
9EA3ABEB245C6DFA006BC61D /* BaseNode.swift in Sources */,
|
||||
9E04AFAF245E2B73002D5CFC /* AttackActionComponent.swift in Sources */,
|
||||
110360D9244B101A008610AF /* GameScene.swift in Sources */,
|
||||
C04783F024685995004961FB /* SettingsScene.swift in Sources */,
|
||||
3FE19DB3246C690B004827AB /* RoundSimulatorService.swift in Sources */,
|
||||
116060F7245C57D2004E5A36 /* EntityManager.swift in Sources */,
|
||||
C064E9AA246C114C0022B228 /* LabelComponent.swift in Sources */,
|
||||
3EBD242E245D9332003CECE7 /* Team.swift in Sources */,
|
||||
@ -408,7 +412,7 @@
|
||||
9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */,
|
||||
AE151589245F18EF001D363E /* MatchmakingHelper.swift in Sources */,
|
||||
11036113244B3E30008610AF /* MenuScene.swift in Sources */,
|
||||
C099579C246C5E5C0016AA22 /* PlayerMovesService.swift in Sources */,
|
||||
C099579C246C5E5C0016AA22 /* DataService.swift in Sources */,
|
||||
9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */,
|
||||
9E174C8A245E1A0A00209FF0 /* Background.swift in Sources */,
|
||||
9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */,
|
||||
|
@ -44,8 +44,9 @@ class TimerComponent: GKComponent {
|
||||
self.labelNode.text = String(timeLeft())
|
||||
|
||||
if(isFinished()){
|
||||
MatchmakingHelper.shar
|
||||
self.labelNode.text = "Synching"
|
||||
MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: PlayerMovesService.sharedInstance.playerMoves)
|
||||
MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.playerMoves)
|
||||
}
|
||||
}
|
||||
|
||||
|
32
GoldWars/GoldWars/DataService.swift
Normal file
32
GoldWars/GoldWars/DataService.swift
Normal file
@ -0,0 +1,32 @@
|
||||
//
|
||||
// PlayerMovesService.swift
|
||||
// GoldWars
|
||||
//
|
||||
// Created by Tim Herbst on 13.05.20.
|
||||
// Copyright © 2020 SP2. All rights reserved.
|
||||
//
|
||||
|
||||
struct PlayerMove: Codable{
|
||||
let fromBase: Int
|
||||
let toBase: Int
|
||||
let unitCount: Int
|
||||
}
|
||||
|
||||
struct Host: Codable {
|
||||
let playerID: String
|
||||
}
|
||||
|
||||
class DataService {
|
||||
static let sharedInstance = DataService()
|
||||
var playerMoves: [PlayerMove] = []
|
||||
var gameHost: Host?
|
||||
|
||||
|
||||
func addMove(playerMove: PlayerMove) {
|
||||
self.playerMoves.append(playerMove)
|
||||
}
|
||||
|
||||
func setGameHost(host: Host) {
|
||||
self.gameHost = host
|
||||
}
|
||||
}
|
@ -35,7 +35,7 @@ class Base: GKEntity{
|
||||
base.changeOwnerShip = true
|
||||
self.unitCount -= units
|
||||
base.unitCount += units
|
||||
PlayerMovesService.sharedInstance.addMove(playerMove: PlayerMove(fromBase: self.baseID, toBase: base.baseID, unitCount: units))
|
||||
DataService.sharedInstance.addMove(playerMove: PlayerMove(fromBase: self.baseID, toBase: base.baseID, unitCount: units))
|
||||
return [self, base]
|
||||
}
|
||||
|
||||
|
@ -115,9 +115,17 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
||||
let jsonDecoder = JSONDecoder()
|
||||
|
||||
if let message = try? jsonDecoder.decode(PlayerMove.self, from: data) {
|
||||
let count = message.unitCount
|
||||
print("Angekommen \(count)")
|
||||
//TODO: impl logic
|
||||
}
|
||||
|
||||
if let message = try? jsonDecoder.decode(Host.self, from: data) {
|
||||
if !self.isServer {
|
||||
DataService.sharedInstance.gameHost = message
|
||||
print("LocalID: \(GKLocalPlayer.local.gamePlayerID)")
|
||||
print("ServerID: \(message.playerID)")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -167,13 +175,14 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
||||
self.isServer = true
|
||||
self.spieler1 = player
|
||||
self.nameSpieler1 = self.spieler1!.displayName
|
||||
|
||||
DataService.sharedInstance.setGameHost(host: Host(playerName: player!.gamePlayerID))
|
||||
} else {
|
||||
self.isServer = false
|
||||
}
|
||||
|
||||
self.delegate?.matchStarted()
|
||||
self.menusc!.loadScene(scene: GameScene(size: self.menusc!.size))
|
||||
MultiplayerNetwork.sharedInstance.sendHostIdentifier()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// MessageProtocol.swift
|
||||
// MultiplayerNetwork.swift
|
||||
// GoldWars
|
||||
//
|
||||
// Created by Niko Jochim on 10.05.20.
|
||||
@ -9,9 +9,6 @@
|
||||
import GameplayKit
|
||||
import Foundation
|
||||
|
||||
|
||||
|
||||
|
||||
class MultiplayerNetwork{
|
||||
static let sharedInstance = MultiplayerNetwork()
|
||||
|
||||
@ -31,5 +28,11 @@ class MultiplayerNetwork{
|
||||
let encoded = (try? encoder.encode(playerMoves))!
|
||||
sendData(data: encoded)
|
||||
}
|
||||
|
||||
func sendHostIdentifier() {
|
||||
let encoder = JSONEncoder()
|
||||
let encoded = (try? encoder.encode(DataService.sharedInstance.gameHost))!
|
||||
sendData(data: encoded)
|
||||
}
|
||||
|
||||
}
|
@ -12,12 +12,21 @@ struct PlayerMove : Codable{
|
||||
let unitCount: Int
|
||||
}
|
||||
|
||||
class PlayerMovesService {
|
||||
static let sharedInstance = PlayerMovesService()
|
||||
struct Host: Codable {
|
||||
let playerName: String
|
||||
}
|
||||
|
||||
class DataService {
|
||||
static let sharedInstance = DataService()
|
||||
var playerMoves: [PlayerMove] = []
|
||||
var gameHost: Host?
|
||||
|
||||
|
||||
func addMove(playerMove: PlayerMove) {
|
||||
self.playerMoves.append(playerMove)
|
||||
}
|
||||
|
||||
func setGameHost(host: Host) {
|
||||
self.gameHost = host
|
||||
}
|
||||
}
|
||||
|
13
GoldWars/GoldWars/Storyboards/RoundSimulatorService.swift
Normal file
13
GoldWars/GoldWars/Storyboards/RoundSimulatorService.swift
Normal file
@ -0,0 +1,13 @@
|
||||
//
|
||||
// RoundSimulatorService.swift
|
||||
// GoldWars
|
||||
//
|
||||
// Created by student on 13.05.20.
|
||||
// Copyright © 2020 SP2. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class RoundSimulatorService {
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user