From c0153d43d4566b709dc14f10610882723ca3ccb3 Mon Sep 17 00:00:00 2001 From: Daniel Steckert <71stda1bif@hft-stuttgart.de> Date: Sun, 31 May 2020 21:36:55 +0200 Subject: [PATCH 1/2] Add function to button --- GoldWars/GoldWars/Entities/Base.swift | 1 + GoldWars/GoldWars/Entities/HUD.swift | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/GoldWars/GoldWars/Entities/Base.swift b/GoldWars/GoldWars/Entities/Base.swift index e01ba62..b4247e2 100644 --- a/GoldWars/GoldWars/Entities/Base.swift +++ b/GoldWars/GoldWars/Entities/Base.swift @@ -15,6 +15,7 @@ class Base: GKEntity{ var unitCount: Int var hasAttackBoost = false var hasDefenseBoost = false + var hasSpyBoost = false var adjacencyList: Array var changeOwnership: Bool var ownershipPlayer: GKPlayer? diff --git a/GoldWars/GoldWars/Entities/HUD.swift b/GoldWars/GoldWars/Entities/HUD.swift index 04b0c60..d1fcd89 100644 --- a/GoldWars/GoldWars/Entities/HUD.swift +++ b/GoldWars/GoldWars/Entities/HUD.swift @@ -56,10 +56,10 @@ class HUD: GKEntity { isEnabled: true, position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.75, y: EntityManager.gameEMInstance.scene.size.height * 0.1), onButtonPress: { - print("Not implemented") + EntityManager.gameEMInstance.getBasesByTeam(for: .team2).forEach({base in base.hasSpyBoost = true}) GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.first.time", increasePercentComplete: 100) GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.spy.ten", increasePercentComplete: 10) - } + } ) defSkill = SingeClickButtonNode( textureName: "yellow_circle", From 97d51411dc1686f72881a1285e17d89a20b42e69 Mon Sep 17 00:00:00 2001 From: Daniel Steckert <71stda1bif@hft-stuttgart.de> Date: Tue, 2 Jun 2020 22:56:43 +0200 Subject: [PATCH 2/2] Enable ability for both player and change trigger to current round --- GoldWars/GoldWars/Entities/Base.swift | 1 - GoldWars/GoldWars/Entities/EntityManager.swift | 12 ++++++++++++ GoldWars/GoldWars/Entities/HUD.swift | 14 +++++++------- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/GoldWars/GoldWars/Entities/Base.swift b/GoldWars/GoldWars/Entities/Base.swift index b4247e2..e01ba62 100644 --- a/GoldWars/GoldWars/Entities/Base.swift +++ b/GoldWars/GoldWars/Entities/Base.swift @@ -15,7 +15,6 @@ class Base: GKEntity{ var unitCount: Int var hasAttackBoost = false var hasDefenseBoost = false - var hasSpyBoost = false var adjacencyList: Array var changeOwnership: Bool var ownershipPlayer: GKPlayer? diff --git a/GoldWars/GoldWars/Entities/EntityManager.swift b/GoldWars/GoldWars/Entities/EntityManager.swift index 78e63bf..6987fb9 100644 --- a/GoldWars/GoldWars/Entities/EntityManager.swift +++ b/GoldWars/GoldWars/Entities/EntityManager.swift @@ -217,6 +217,14 @@ class EntityManager { return entities.filter{$0 is Base && ($0 as! Base).component(ofType: TeamComponent.self)?.team == team } as! Set } + func getOpponentBases(for team: Team) -> Set { + if(team == .team1){ + return getBasesByTeam(for: .team2) + }else { + return getBasesByTeam(for: .team1) + } + } + func getBasesByPlayer(for player: GKPlayer) -> Set { return entities.filter{$0 is Base && ($0 as! Base).component(ofType: TeamComponent.self)?.player == player } as! Set } @@ -238,6 +246,10 @@ class EntityManager { return entities.filter { $0 is Base && ($0 as! Base).component(ofType: TeamComponent.self)?.player.displayName == playerName }[0].component(ofType: TeamComponent.self)!.team } + func getTeam() -> Team { + return entities.filter { $0 is Base && ($0 as! Base).component(ofType: TeamComponent.self)?.player.displayName == GKLocalPlayer.local.displayName }[0].component(ofType: TeamComponent.self)!.team + } + func getBasebyID(id: Int) -> Base?{ for entity in entities { if entity is Base && (entity as! Base).baseID == id { diff --git a/GoldWars/GoldWars/Entities/HUD.swift b/GoldWars/GoldWars/Entities/HUD.swift index d1fcd89..ed34eb6 100644 --- a/GoldWars/GoldWars/Entities/HUD.swift +++ b/GoldWars/GoldWars/Entities/HUD.swift @@ -41,7 +41,7 @@ class HUD: GKEntity { hostUnitsLabel = SKLabelNode(text: "500" ) peerLabel = SKLabelNode(text: peer?.displayName) peerUnitsLabel = SKLabelNode(text: "500") - + roundTimerLabel = SKLabelNode(text: "") roundTimerLabel.fontColor = UIColor.black roundTimerLabel.fontSize = CGFloat(45) @@ -56,10 +56,10 @@ class HUD: GKEntity { isEnabled: true, position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.75, y: EntityManager.gameEMInstance.scene.size.height * 0.1), onButtonPress: { - EntityManager.gameEMInstance.getBasesByTeam(for: .team2).forEach({base in base.hasSpyBoost = true}) + EntityManager.gameEMInstance.getOpponentBases(for: EntityManager.gameEMInstance.getTeam()).forEach({base in base.component(ofType: DefaultBaseComponent.self)?.labelNode.text = "\(base.unitCount)"}) GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.first.time", increasePercentComplete: 100) GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.spy.ten", increasePercentComplete: 10) - } + } ) defSkill = SingeClickButtonNode( textureName: "yellow_circle", @@ -70,7 +70,7 @@ class HUD: GKEntity { DataService.sharedInstance.localRoundData.hasDefenceBoost = true GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.first.time", increasePercentComplete: 100) GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.def.ten", increasePercentComplete: 10) - } + } ) atkSkill = SingeClickButtonNode( textureName: "yellow_circle", @@ -78,10 +78,10 @@ class HUD: GKEntity { isEnabled: true, position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.95, y: EntityManager.gameEMInstance.scene.size.height * 0.1), onButtonPress: { - DataService.sharedInstance.localRoundData.hasAttackBoost = true - GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.first.time", increasePercentComplete: 100) + DataService.sharedInstance.localRoundData.hasAttackBoost = true + GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.first.time", increasePercentComplete: 100) GameCenterManager.sharedInstance.addAchievementProgress(identifier: "de.hft.stuttgart.ip2.goldwars.skill.atk.ten", increasePercentComplete: 10) - } + } ) finishButton = SingeClickButtonNode(