* 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,8 +45,8 @@ 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() {

View File

@ -54,7 +54,7 @@ class RoundCalculatorService {
} }
playerMovesByBase.removeValue(forKey: playerName) playerMovesByBase.removeValue(forKey: playerName)
} }
for (_, playerMoves) in playerMovesByBase { for (_, playerMoves) in playerMovesByBase {
for playerMove in playerMoves { for playerMove in playerMoves {
for base in currentSnapshotModel!.baseEntites { for base in currentSnapshotModel!.baseEntites {
@ -84,11 +84,22 @@ class RoundCalculatorService {
for base in currentSnapshotModel!.baseEntites { for base in currentSnapshotModel!.baseEntites {
if base.baseId == playerMoveWithMaxUnits.value.toBase { if base.baseId == playerMoveWithMaxUnits.value.toBase {
base.unitCount += playerMoveWithMaxUnits.value.unitCount if base.ownership == nil {
if playerMoveWithMaxUnits.value.unitCount == 0 { base.unitCount += playerMoveWithMaxUnits.value.unitCount
base.ownership = nil if playerMoveWithMaxUnits.value.unitCount == 0 {
base.ownership = nil
} else {
base.ownership = playerMoveWithMaxUnits.key
}
} else { } else {
base.ownership = playerMoveWithMaxUnits.key 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
}
} }
} }
} }
@ -96,7 +107,9 @@ class RoundCalculatorService {
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,13 +26,11 @@ 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?) {