Add limit of moves

* set limit of moves. 1 attack and 5 own unit moves
* update move-limiter after submit button of modal
* increase number of attack to two able attacks
This commit is contained in:
Jakob Haag 2020-05-23 11:23:54 +02:00 committed by Marcel Schwarz
parent 23e53effd4
commit f7e4188143
5 changed files with 29 additions and 2 deletions

View File

@ -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)
}

View File

@ -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
}

View File

@ -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
}
}
}

View File

@ -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
}
}
}

View File

@ -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",