diff --git a/GoldWars/GoldWars/Components/TimerComponent.swift b/GoldWars/GoldWars/Components/TimerComponent.swift index 3d2579c..41461b2 100644 --- a/GoldWars/GoldWars/Components/TimerComponent.swift +++ b/GoldWars/GoldWars/Components/TimerComponent.swift @@ -55,6 +55,7 @@ class TimerComponent: GKComponent { if(isFinished()){ self.labelNode.text = "Synching" + RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats() if !MultiplayerNetwork.sharedInstance.isSending { MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.localPlayerMoves) } diff --git a/GoldWars/GoldWars/Entities/Modal.swift b/GoldWars/GoldWars/Entities/Modal.swift index 1a91bf5..22f92f3 100644 --- a/GoldWars/GoldWars/Entities/Modal.swift +++ b/GoldWars/GoldWars/Entities/Modal.swift @@ -23,7 +23,6 @@ class Modal: GKEntity{ var body: SKLabelNode var footer: SKLabelNode - init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint, collisionBase: Base?) { unitCount = base.unitCount @@ -105,6 +104,7 @@ class Modal: GKEntity{ func sendUnits(currentDraggedBase: Base?, touchLocation: CGPoint, gameScene: GameScene, collisionBase: Base?){ for base in currentDraggedBase!.adjacencyList { if base == collisionBase { + RoundCalculatorService.sharedInstance.increaseMoveCounter(ownBase: currentDraggedBase?.ownershipPlayer == base.ownershipPlayer) entityManager.update((currentDraggedBase?.doPlayerMoveTypeToBase(base: base, playerMoveType: PlayerMoveType.AtkMove, units: Int(GameScene.sendUnits)))!) GameScene.sendUnits = 0 } diff --git a/GoldWars/GoldWars/RoundCalculatorService.swift b/GoldWars/GoldWars/RoundCalculatorService.swift index 2a0a877..8e61759 100644 --- a/GoldWars/GoldWars/RoundCalculatorService.swift +++ b/GoldWars/GoldWars/RoundCalculatorService.swift @@ -19,6 +19,9 @@ class RoundCalculatorService { var isCalculating = false + var numberOfAttacks = 0 + var numberOfOwnUnitMoves = 0 + func calculateRound() { os_log("Started calculating Round", log: RoundCalculatorService.LOG, type: .info) isCalculating = true @@ -137,4 +140,16 @@ class RoundCalculatorService { //TODO: outsource playermoves } + func resetNumberOfAttacksAndFormats() { + self.numberOfAttacks = 0; + self.numberOfOwnUnitMoves = 0; + } + + func increaseMoveCounter(ownBase: Bool!) { + if ownBase { + self.numberOfOwnUnitMoves = self.numberOfOwnUnitMoves + 1 + } else { + self.numberOfAttacks = self.numberOfAttacks + 1 + } + } } diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index 96be62c..4b0fe8b 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -115,6 +115,9 @@ class GameScene: SKScene{ collisionBase = base // TODO: change interaction based on collision instead of touchlocation if currentDraggedBase!.unitCount > 1 { + if !checkIfMoveIsAble() { + return + } entityManager.add(Modal(modaltype: .BaseAttack, base: currentDraggedBase!, anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), @@ -173,4 +176,12 @@ class GameScene: SKScene{ ])) } } + + func checkIfMoveIsAble() -> Bool{ + if collisionBase?.ownershipPlayer == currentDraggedBase?.ownershipPlayer { + return RoundCalculatorService.sharedInstance.numberOfOwnUnitMoves < 5 + } else { + return RoundCalculatorService.sharedInstance.numberOfAttacks < 2 + } + } } diff --git a/GoldWars/GoldWars/SettingsScene.swift b/GoldWars/GoldWars/SettingsScene.swift index fbd25e2..7d3ad52 100644 --- a/GoldWars/GoldWars/SettingsScene.swift +++ b/GoldWars/GoldWars/SettingsScene.swift @@ -13,10 +13,10 @@ class SettingsScene: SKScene { var entityManager = EntityManager.settingsEMInstance override func sceneDidLoad() { + entityManager.setScene(scene: self) let positionX = self.size.width * 0.1 let positionY = self.size.height * 0.05 - print("SceneDidLoad Setting") entityManager.add(Button(name: "backToMenuScene", textureName: "yellow_button04", text: "Back",