* Impl. a usecase of a fight scenario

* Reset playermoves when necessary
This commit is contained in:
Aldin Duraki 2020-05-20 22:14:29 +02:00
parent fbe8dbde9d
commit 604001a365
3 changed files with 20 additions and 9 deletions

View File

@ -45,9 +45,9 @@ class MultiplayerNetwork{
let encoder = JSONEncoder() let encoder = JSONEncoder()
let encoded = (try? encoder.encode(playerMoves))! let encoded = (try? encoder.encode(playerMoves))!
sendDataToHost(data: encoded) sendDataToHost(data: encoded)
}
DataService.sharedInstance.localPlayerMoves.removeAll() DataService.sharedInstance.localPlayerMoves.removeAll()
} }
}
func sendHostIdentifier() { func sendHostIdentifier() {
let encoder = JSONEncoder() let encoder = JSONEncoder()

View File

@ -84,19 +84,32 @@ class RoundCalculatorService {
for base in currentSnapshotModel!.baseEntites { for base in currentSnapshotModel!.baseEntites {
if base.baseId == playerMoveWithMaxUnits.value.toBase { if base.baseId == playerMoveWithMaxUnits.value.toBase {
if base.ownership == nil {
base.unitCount += playerMoveWithMaxUnits.value.unitCount base.unitCount += playerMoveWithMaxUnits.value.unitCount
if playerMoveWithMaxUnits.value.unitCount == 0 { if playerMoveWithMaxUnits.value.unitCount == 0 {
base.ownership = nil base.ownership = nil
} else { } else {
base.ownership = playerMoveWithMaxUnits.key 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) baseSpecificMoves.removeValue(forKey: baseId)
} }
allPlayerMoves.removeAll() allPlayerMoves.removeAll()
DataService.sharedInstance.localPlayerMoves.removeAll()
MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers() MultiplayerNetwork.sharedInstance.sendSnapshotModelToPlayers()
DataService.sharedInstance.snapshotModel = currentSnapshotModel
EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel!) EntityManager.sharedInstance.updateSnapshotModel(snapshotModel: currentSnapshotModel!)
os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info) os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info)
} }

View File

@ -26,14 +26,12 @@ class GameScene: SKScene{
} }
func initMap() { func initMap() {
if (DataService.sharedInstance.gameHost?.playerName == GKLocalPlayer.local.displayName) { if (DataService.sharedInstance.gameHost?.playerName == GKLocalPlayer.local.displayName) {
let mapModel = MapFactory(scene: self, entityManager: EntityManager.sharedInstance).loadMap() let mapModel = MapFactory(scene: self, entityManager: EntityManager.sharedInstance).loadMap()
MultiplayerNetwork.sharedInstance.sendMapModelToPlayers(mapModel: mapModel) MultiplayerNetwork.sharedInstance.sendMapModelToPlayers(mapModel: mapModel)
}
DataService.sharedInstance.setSnapshotModel(snapshotModel: EntityManager.sharedInstance.getSnapshotModel()) DataService.sharedInstance.setSnapshotModel(snapshotModel: EntityManager.sharedInstance.getSnapshotModel())
} }
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { guard let touch = touches.first else {