diff --git a/GoldWars/GoldWars/Components/ButtonNode.swift b/GoldWars/GoldWars/Components/ButtonNode.swift index ab92e38..b98164a 100644 --- a/GoldWars/GoldWars/Components/ButtonNode.swift +++ b/GoldWars/GoldWars/Components/ButtonNode.swift @@ -22,7 +22,7 @@ class ButtonNode: SKSpriteNode { } } - let onButtonPress: () -> () + var onButtonPress: () -> () init(textureName: String, text: String, isEnabled: Bool, position: CGPoint, onButtonPress: @escaping () -> ()) { self.onButtonPress = onButtonPress diff --git a/GoldWars/GoldWars/Entities/HUD.swift b/GoldWars/GoldWars/Entities/HUD.swift index 6c08562..aaf2f57 100644 --- a/GoldWars/GoldWars/Entities/HUD.swift +++ b/GoldWars/GoldWars/Entities/HUD.swift @@ -30,12 +30,6 @@ class HUD: GKEntity { var finishButton: ButtonNode init(size: CGSize) { - finishButton = ButtonNode(textureName: "yellow_button04", text: "Finish Round", isEnabled: true, position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.15, y: EntityManager.gameEMInstance.scene.size.height * 0.1), - onButtonPress: { print("Finish Round") } - ) - finishButton.size = CGSize(width: 225, height: 40) - finishButton.zPosition = 4 - host = GameCenterManager.sharedInstance.hostingPlayer peer = GameCenterManager.sharedInstance.peerPlayer hostLabel = SKLabelNode(text: host?.displayName) @@ -46,7 +40,8 @@ class HUD: GKEntity { roundTimerLabel = SKLabelNode(text: "") roundTimerLabel.fontColor = UIColor.black roundTimerLabel.fontSize = CGFloat(45) - roundTimerLabel.position = CGPoint(x: size.width * 0.5, y: size.height * 0.9 - 15) + roundTimerLabel.position = CGPoint(x: size.width * 0.5, y: size.height * 0.9) + roundTimerLabel.horizontalAlignmentMode = .center self.roundTimer = RoundTimer() @@ -71,7 +66,22 @@ class HUD: GKEntity { position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.95, y: EntityManager.gameEMInstance.scene.size.height * 0.1), onButtonPress: {DataService.sharedInstance.localRoundData.hasAttackBoost = true} ) + + finishButton = ButtonNode( + textureName: "yellow_button04", + text: "Finish Round", + isEnabled: true, + position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.15, y: EntityManager.gameEMInstance.scene.size.height * 0.1), + onButtonPress: { } + ) + finishButton.size = CGSize(width: 250, height: 40) + finishButton.zPosition = 4 super.init() + + finishButton.onButtonPress = { [unowned self] in + self.finishRound() + } + hostLabel.position = CGPoint(x: size.width * 0.02, y: size.height * 0.95) hostLabel.horizontalAlignmentMode = .left peerLabel.position = CGPoint(x: size.width * 0.98, y: size.height * 0.95) @@ -101,6 +111,12 @@ class HUD: GKEntity { func startWithDuration(){ roundTimer.startTimer() + self.roundTimer.roundEnded = "Syncing" RoundCalculatorService.sharedInstance.isCalculating = false } + + func finishRound() -> () { + self.roundTimer.timeLeft = 1; + self.roundTimer.roundEnded = "Waiting for other player..." + } } diff --git a/GoldWars/GoldWars/RoundTimer.swift b/GoldWars/GoldWars/RoundTimer.swift index 92dfb28..2faa03a 100644 --- a/GoldWars/GoldWars/RoundTimer.swift +++ b/GoldWars/GoldWars/RoundTimer.swift @@ -13,6 +13,7 @@ class RoundTimer: Timer { var timer: Timer? var timeLeft: Int = 0 var calculate = false + var roundEnded = "Syncing" func initTimer() { timer = Timer.scheduledTimer( @@ -32,7 +33,7 @@ class RoundTimer: Timer { { timeLeft = timeLeft - 1 - EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : "Syncing")) + EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : roundEnded)) if timeLeft == 0 { RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats() @@ -40,6 +41,7 @@ class RoundTimer: Timer { MultiplayerNetwork.sharedInstance.sendPlayerMoves(localRoundData: DataService.sharedInstance.localRoundData) } calculate = true + print("send Player Moves") } if timeLeft <= 0 { if calculate