Merge branch '71-finish-button' into 'development'
Resolve "Finish Button" Closes #71 See merge request marcel.schwarz/software-projekt-2!91
This commit is contained in:
commit
4d2b7fe6ea
@ -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
|
||||
|
0
GoldWars/GoldWars/Components/TimerComponent.swift
Normal file
0
GoldWars/GoldWars/Components/TimerComponent.swift
Normal file
@ -51,7 +51,7 @@ class EntityManager {
|
||||
scene.addChild(hudEntitiy.atkSkill)
|
||||
scene.addChild(hudEntitiy.spySkill)
|
||||
scene.addChild(hudEntitiy.roundTimerLabel)
|
||||
isModal = true
|
||||
scene.addChild(hudEntitiy.finishButton)
|
||||
}
|
||||
|
||||
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self) {
|
||||
|
@ -27,6 +27,8 @@ class HUD: GKEntity {
|
||||
var roundTimerLabel: SKLabelNode
|
||||
let roundTimer: RoundTimer
|
||||
|
||||
var finishButton: ButtonNode
|
||||
|
||||
init(size: CGSize) {
|
||||
host = GameCenterManager.sharedInstance.hostingPlayer
|
||||
peer = GameCenterManager.sharedInstance.peerPlayer
|
||||
@ -34,11 +36,12 @@ 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)
|
||||
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()
|
||||
|
||||
@ -63,7 +66,24 @@ 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 = SingeClickButtonNode(
|
||||
textureName: "yellow_button04",
|
||||
text: "Done",
|
||||
isEnabled: true,
|
||||
position: CGPoint(
|
||||
x: EntityManager.gameEMInstance.scene.size.width * 0.1,
|
||||
y: EntityManager.gameEMInstance.scene.size.height * 0.1),
|
||||
onButtonPress: { }
|
||||
)
|
||||
finishButton.size = CGSize(width: 80, 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)
|
||||
@ -93,6 +113,13 @@ class HUD: GKEntity {
|
||||
|
||||
func startWithDuration(){
|
||||
roundTimer.startTimer()
|
||||
finishButton.isEnabled = true
|
||||
self.roundTimer.roundEnded = "Syncing"
|
||||
RoundCalculatorService.sharedInstance.isCalculating = false
|
||||
}
|
||||
|
||||
func finishRound() -> () {
|
||||
self.roundTimer.timeLeft = 1;
|
||||
self.roundTimer.roundEnded = "Waiting for other player..."
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ class RoundCalculatorService {
|
||||
var baseSpecificMoves = collectBaseSpecificMoves()
|
||||
|
||||
// TODO: Refactor to a less complex way
|
||||
for (baseId, var playerMovesByBase) in baseSpecificMoves {
|
||||
for (baseId, playerMovesByBase) in baseSpecificMoves {
|
||||
let targetBase = currentSnapshotModel?.baseEntites.filter { $0.baseId == baseId }[0]
|
||||
let possiblyOwnershipMoves = playerMovesByBase.filter { $0.key == targetBase?.ownership}
|
||||
|
||||
@ -50,10 +50,10 @@ class RoundCalculatorService {
|
||||
}
|
||||
}
|
||||
}
|
||||
playerMovesByBase.removeValue(forKey: playerName)
|
||||
baseSpecificMoves[baseId]!.removeValue(forKey: playerName)
|
||||
}
|
||||
|
||||
for (_, playerMoves) in playerMovesByBase {
|
||||
for playerMoves in baseSpecificMoves[baseId]!.values {
|
||||
for playerMove in playerMoves {
|
||||
for base in currentSnapshotModel!.baseEntites {
|
||||
if base.baseId == playerMove.fromBase {
|
||||
@ -201,9 +201,9 @@ class RoundCalculatorService {
|
||||
|
||||
func increaseMoveCounter(ownBase: Bool!) {
|
||||
if ownBase {
|
||||
self.numberOfOwnUnitMoves = self.numberOfOwnUnitMoves + 1
|
||||
self.numberOfOwnUnitMoves += 1
|
||||
} else {
|
||||
self.numberOfAttacks = self.numberOfAttacks + 1
|
||||
self.numberOfAttacks += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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(
|
||||
@ -30,9 +31,9 @@ class RoundTimer: Timer {
|
||||
|
||||
@objc func onTimerFires()
|
||||
{
|
||||
timeLeft = timeLeft - 1
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user