Merge branch '70-anzahl-zuege-pro-runde' into 'development'

Resolve "Anzahl Zuege pro Runde"

Closes #70

See merge request marcel.schwarz/software-projekt-2!80
This commit is contained in:
Marcel Schwarz 2020-05-26 18:11:56 +00:00
commit 23707cb1d9
5 changed files with 29 additions and 2 deletions

View File

@ -55,6 +55,7 @@ class TimerComponent: GKComponent {
if(isFinished()){ if(isFinished()){
self.labelNode.text = "Synching" self.labelNode.text = "Synching"
RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats()
if !MultiplayerNetwork.sharedInstance.isSending { if !MultiplayerNetwork.sharedInstance.isSending {
MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.localPlayerMoves) MultiplayerNetwork.sharedInstance.sendPlayerMoves(playerMoves: DataService.sharedInstance.localPlayerMoves)
} }

View File

@ -23,7 +23,6 @@ class Modal: GKEntity{
var body: SKLabelNode var body: SKLabelNode
var footer: SKLabelNode var footer: SKLabelNode
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint, collisionBase: Base?) { init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint, collisionBase: Base?) {
unitCount = base.unitCount unitCount = base.unitCount
@ -105,6 +104,7 @@ class Modal: GKEntity{
func sendUnits(currentDraggedBase: Base?, touchLocation: CGPoint, gameScene: GameScene, collisionBase: Base?){ func sendUnits(currentDraggedBase: Base?, touchLocation: CGPoint, gameScene: GameScene, collisionBase: Base?){
for base in currentDraggedBase!.adjacencyList { for base in currentDraggedBase!.adjacencyList {
if base == collisionBase { if base == collisionBase {
RoundCalculatorService.sharedInstance.increaseMoveCounter(ownBase: currentDraggedBase?.ownershipPlayer == base.ownershipPlayer)
entityManager.update((currentDraggedBase?.doPlayerMoveTypeToBase(base: base, playerMoveType: PlayerMoveType.AtkMove, units: Int(GameScene.sendUnits)))!) entityManager.update((currentDraggedBase?.doPlayerMoveTypeToBase(base: base, playerMoveType: PlayerMoveType.AtkMove, units: Int(GameScene.sendUnits)))!)
GameScene.sendUnits = 0 GameScene.sendUnits = 0
} }

View File

@ -19,6 +19,9 @@ class RoundCalculatorService {
var isCalculating = false var isCalculating = false
var numberOfAttacks = 0
var numberOfOwnUnitMoves = 0
func calculateRound() { func calculateRound() {
os_log("Started calculating Round", log: RoundCalculatorService.LOG, type: .info) os_log("Started calculating Round", log: RoundCalculatorService.LOG, type: .info)
isCalculating = true isCalculating = true
@ -137,4 +140,16 @@ class RoundCalculatorService {
//TODO: outsource playermoves //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 collisionBase = base
// TODO: change interaction based on collision instead of touchlocation // TODO: change interaction based on collision instead of touchlocation
if currentDraggedBase!.unitCount > 1 { if currentDraggedBase!.unitCount > 1 {
if !checkIfMoveIsAble() {
return
}
entityManager.add(Modal(modaltype: .BaseAttack, entityManager.add(Modal(modaltype: .BaseAttack,
base: currentDraggedBase!, base: currentDraggedBase!,
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), 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 var entityManager = EntityManager.settingsEMInstance
override func sceneDidLoad() { override func sceneDidLoad() {
entityManager.setScene(scene: self) entityManager.setScene(scene: self)
let positionX = self.size.width * 0.1 let positionX = self.size.width * 0.1
let positionY = self.size.height * 0.05 let positionY = self.size.height * 0.05
print("SceneDidLoad Setting")
entityManager.add(Button(name: "backToMenuScene", entityManager.add(Button(name: "backToMenuScene",
textureName: "yellow_button04", textureName: "yellow_button04",
text: "Back", text: "Back",