From 04170eb886fd3e2e266ddc862c89285b99935f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chauntalle=20Schu=CC=88le?= Date: Mon, 18 May 2020 21:31:32 +0200 Subject: [PATCH] cleaned up code --- GoldWars/GoldWars/Entities/Modal.swift | 35 +----------------------- GoldWars/GoldWars/Scenes/GameScene.swift | 33 ++++++---------------- 2 files changed, 10 insertions(+), 58 deletions(-) diff --git a/GoldWars/GoldWars/Entities/Modal.swift b/GoldWars/GoldWars/Entities/Modal.swift index c775179..aadd374 100644 --- a/GoldWars/GoldWars/Entities/Modal.swift +++ b/GoldWars/GoldWars/Entities/Modal.swift @@ -13,9 +13,6 @@ class Modal: GKEntity{ var unitCount:Int init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, gameScene: GameScene, currentDraggedBase: Base?, touchLocation: CGPoint, collisionBase: Base?) { - if currentDraggedBase == nil{ - print("nil") - } unitCount = base.unitCount super.init() switch modaltype{ @@ -31,11 +28,7 @@ class Modal: GKEntity{ addComponent(ModalContentComponent(header: "Angriff", body: "Schicke \(unitCount / 2) Einheiten", footer: "", anchorPoint: anchorPoint)) addComponent(ButtonComponent(iconName: "", text: "Senden", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: { - if currentDraggedBase == nil{ - print("nil") - } self.sendUnits(currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, gameScene: gameScene, collisionBase: collisionBase) - print("send units") self.removeModalEntities(gameScene: gameScene) })) addComponent(CancelBtnComponent(iconName: "", text: "", position: CGPoint(x: anchorPoint.x + 160, y: anchorPoint.y + 140), isEnabled: true, onButtonPress: { @@ -62,36 +55,10 @@ class Modal: GKEntity{ } func sendUnits(currentDraggedBase: Base?, touchLocation: CGPoint, gameScene: GameScene, collisionBase: Base?){ - print("sendUnits: sendunits \(GameScene.sendUnits)") for base in currentDraggedBase!.adjacencyList { - print("sendUnits: in here") - //print(base.component(ofType: DefaultBaseComponent.self)?.spriteNode) if base == collisionBase { - print("sendUnits: in here 1") - print("sendUnits: sendunits \(GameScene.sendUnits)") - EntityManager.sharedInstance.update((currentDraggedBase?.attackBase(base: base, units: Int(GameScene.sendUnits)))!) - } - } - /* if currentDraggedBase == nil{ - print("nil") - } - print(touchLocation.x) - print(touchLocation.y) - print("sendUnits: sendunits \(GameScene.sendUnits)") - for base in currentDraggedBase!.adjacencyList { - print("sendUnits: in here") - //print(base.component(ofType: DefaultBaseComponent.self)?.spriteNode) - if gameScene.atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode { - // if !(EntityManager.sharedInstance.getTeamByBase(base: currentDraggedBase!) == EntityManager.sharedInstance.getTeamByBase(base: base)){ - print("sendUnits: in here 1") - print("sendUnits: sendunits \(GameScene.sendUnits)") - EntityManager.sharedInstance.update((currentDraggedBase?.attackBase(base: base, units: Int(GameScene.sendUnits)))!) - // } - } else if gameScene.atPoint(touchLocation) == currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode{ - print("sendUnits: in here 2") - print("sendUnits: sendunits \(GameScene.sendUnits)") EntityManager.sharedInstance.update((currentDraggedBase?.attackBase(base: base, units: Int(GameScene.sendUnits)))!) } - }*/ + } } } diff --git a/GoldWars/GoldWars/Scenes/GameScene.swift b/GoldWars/GoldWars/Scenes/GameScene.swift index 6d790df..fb229f8 100644 --- a/GoldWars/GoldWars/Scenes/GameScene.swift +++ b/GoldWars/GoldWars/Scenes/GameScene.swift @@ -30,7 +30,6 @@ class GameScene: SKScene{ } override func touchesEnded(_ touches: Set, with event: UIEvent?) { - print("touches ended") guard let touch = touches.first else { return } @@ -39,7 +38,6 @@ class GameScene: SKScene{ if isMoveTouch{ isMoveTouch = false - print("touches Ended: isMoveTouch false") currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos @@ -88,34 +86,27 @@ class GameScene: SKScene{ } } EntityManager.sharedInstance.add(Modal(modaltype: .BaseDetails, - base: entity as! Base, - anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), - gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) + base: entity as! Base, + anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), + gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) } } } func addAttackDetails(touchLocation: CGPoint){ - print("addAttackDetails") for base in currentDraggedBase!.adjacencyList { - print("base attack for") if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode { collisionBase = base - print(touchLocation.x) - print(touchLocation.y) - print("add Modal BaseAttack") - print("add AttackDetails: sendunits \(GameScene.sendUnits)") // TODO: change interaction based on collision instead of touchlocation EntityManager.sharedInstance.add(Modal(modaltype: .BaseAttack, - base: currentDraggedBase!, - anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), - gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) + base: currentDraggedBase!, + anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2), + gameScene: self, currentDraggedBase: currentDraggedBase, touchLocation: touchLocation, collisionBase: collisionBase)) } } } func checkSlider(){ - print("slider") for e in EntityManager.sharedInstance.entities{ if let body = e.component(ofType: ModalContentComponent.self)?.body{ GameScene.sendUnits = ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up) @@ -125,17 +116,12 @@ class GameScene: SKScene{ } func checkBases(bases: Set, touchLocation: CGPoint){ - print("checkbases") for base in bases { - if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{ - print("checkbases: touched base") - if !isMoveTouch { - currentDraggedBasePos = base.component(ofType: DefaultBaseComponent.self)!.spriteNode.position - currentDraggedBase = base - print("checkbases: isMoveTouch false") + if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{ if !isMoveTouch { + currentDraggedBasePos = base.component(ofType: DefaultBaseComponent.self)!.spriteNode.position + currentDraggedBase = base } isMoveTouch = true - print("checkbases: isMoveTouch true") moveFireAndBase(base: base, touchLocation: touchLocation) showNearestBases(base: base) } @@ -148,7 +134,6 @@ class GameScene: SKScene{ } func showNearestBases(base: Base){ - print("show nearest Bases") for adjacencyBase in base.adjacencyList { let node = adjacencyBase.component(ofType: DefaultBaseComponent.self)?.spriteNode node?.run(SKAction.sequence([