* Impl. a usecase of a fight scenario
* Reset playermoves when necessary
This commit is contained in:
parent
fbe8dbde9d
commit
604001a365
@ -45,9 +45,9 @@ class MultiplayerNetwork{
|
||||
let encoder = JSONEncoder()
|
||||
let encoded = (try? encoder.encode(playerMoves))!
|
||||
sendDataToHost(data: encoded)
|
||||
}
|
||||
DataService.sharedInstance.localPlayerMoves.removeAll()
|
||||
}
|
||||
}
|
||||
|
||||
func sendHostIdentifier() {
|
||||
let encoder = JSONEncoder()
|
||||
|
@ -84,19 +84,32 @@ class RoundCalculatorService {
|
||||
|
||||
for base in currentSnapshotModel!.baseEntites {
|
||||
if base.baseId == playerMoveWithMaxUnits.value.toBase {
|
||||
if base.ownership == nil {
|
||||
base.unitCount += playerMoveWithMaxUnits.value.unitCount
|
||||
if playerMoveWithMaxUnits.value.unitCount == 0 {
|
||||
base.ownership = nil
|
||||
} else {
|
||||
base.ownership = playerMoveWithMaxUnits.key
|
||||
}
|
||||
} else {
|
||||
if base.unitCount < playerMoveWithMaxUnits.value.unitCount {
|
||||
base.unitCount = playerMoveWithMaxUnits.value.unitCount - base.unitCount
|
||||
base.ownership = playerMoveWithMaxUnits.key
|
||||
} else if (base.unitCount == playerMoveWithMaxUnits.value.unitCount) {
|
||||
base.ownership = nil
|
||||
} else {
|
||||
base.unitCount -= playerMoveWithMaxUnits.value.unitCount
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
baseSpecificMoves.removeValue(forKey: baseId)
|
||||
}
|
||||
allPlayerMoves.removeAll()
|
||||
DataService.sharedInstance.localPlayerMoves.removeAll()
|
||||
MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers()
|
||||
DataService.sharedInstance.snapshotModel = currentSnapshotModel
|
||||
EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel!)
|
||||
os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info)
|
||||
}
|
||||
|
@ -26,14 +26,12 @@ class GameScene: SKScene{
|
||||
}
|
||||
|
||||
func initMap() {
|
||||
|
||||
if (DataService.sharedInstance.gameHost?.playerName == GKLocalPlayer.local.displayName) {
|
||||
let mapModel = MapFactory(scene: self, entityManager: EntityManager.sharedInstance).loadMap()
|
||||
MultiplayerNetwork.sharedInstance.sendMapModelToPlayers(mapModel: mapModel)
|
||||
}
|
||||
|
||||
DataService.sharedInstance.setSnapshotModel(snapshotModel: EntityManager.sharedInstance.getSnapshotModel())
|
||||
}
|
||||
}
|
||||
|
||||
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||
guard let touch = touches.first else {
|
||||
|
Loading…
Reference in New Issue
Block a user