init function of finish button

This commit is contained in:
Jakob Haag 2020-06-01 16:33:52 +02:00 committed by Aldin Duraki
parent 99b57cc4cd
commit eadcec10d8
3 changed files with 27 additions and 9 deletions

View File

@ -22,7 +22,7 @@ class ButtonNode: SKSpriteNode {
} }
} }
let onButtonPress: () -> () var onButtonPress: () -> ()
init(textureName: String, text: String, isEnabled: Bool, position: CGPoint, onButtonPress: @escaping () -> ()) { init(textureName: String, text: String, isEnabled: Bool, position: CGPoint, onButtonPress: @escaping () -> ()) {
self.onButtonPress = onButtonPress self.onButtonPress = onButtonPress

View File

@ -30,12 +30,6 @@ class HUD: GKEntity {
var finishButton: ButtonNode var finishButton: ButtonNode
init(size: CGSize) { 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 host = GameCenterManager.sharedInstance.hostingPlayer
peer = GameCenterManager.sharedInstance.peerPlayer peer = GameCenterManager.sharedInstance.peerPlayer
hostLabel = SKLabelNode(text: host?.displayName) hostLabel = SKLabelNode(text: host?.displayName)
@ -46,7 +40,8 @@ class HUD: GKEntity {
roundTimerLabel = SKLabelNode(text: "") roundTimerLabel = SKLabelNode(text: "")
roundTimerLabel.fontColor = UIColor.black roundTimerLabel.fontColor = UIColor.black
roundTimerLabel.fontSize = CGFloat(45) 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() 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), position: CGPoint(x: EntityManager.gameEMInstance.scene.size.width * 0.95, y: EntityManager.gameEMInstance.scene.size.height * 0.1),
onButtonPress: {DataService.sharedInstance.localRoundData.hasAttackBoost = true} 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() super.init()
finishButton.onButtonPress = { [unowned self] in
self.finishRound()
}
hostLabel.position = CGPoint(x: size.width * 0.02, y: size.height * 0.95) hostLabel.position = CGPoint(x: size.width * 0.02, y: size.height * 0.95)
hostLabel.horizontalAlignmentMode = .left hostLabel.horizontalAlignmentMode = .left
peerLabel.position = CGPoint(x: size.width * 0.98, y: size.height * 0.95) peerLabel.position = CGPoint(x: size.width * 0.98, y: size.height * 0.95)
@ -101,6 +111,12 @@ class HUD: GKEntity {
func startWithDuration(){ func startWithDuration(){
roundTimer.startTimer() roundTimer.startTimer()
self.roundTimer.roundEnded = "Syncing"
RoundCalculatorService.sharedInstance.isCalculating = false RoundCalculatorService.sharedInstance.isCalculating = false
} }
func finishRound() -> () {
self.roundTimer.timeLeft = 1;
self.roundTimer.roundEnded = "Waiting for other player..."
}
} }

View File

@ -13,6 +13,7 @@ class RoundTimer: Timer {
var timer: Timer? var timer: Timer?
var timeLeft: Int = 0 var timeLeft: Int = 0
var calculate = false var calculate = false
var roundEnded = "Syncing"
func initTimer() { func initTimer() {
timer = Timer.scheduledTimer( timer = Timer.scheduledTimer(
@ -32,7 +33,7 @@ class RoundTimer: Timer {
{ {
timeLeft = timeLeft - 1 timeLeft = timeLeft - 1
EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : "Syncing")) EntityManager.gameEMInstance.updateTime(time: (timeLeft > 0 ? String(timeLeft) : roundEnded))
if timeLeft == 0 { if timeLeft == 0 {
RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats() RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats()
@ -40,6 +41,7 @@ class RoundTimer: Timer {
MultiplayerNetwork.sharedInstance.sendPlayerMoves(localRoundData: DataService.sharedInstance.localRoundData) MultiplayerNetwork.sharedInstance.sendPlayerMoves(localRoundData: DataService.sharedInstance.localRoundData)
} }
calculate = true calculate = true
print("send Player Moves")
} }
if timeLeft <= 0 { if timeLeft <= 0 {
if calculate if calculate