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:
Aldin Duraki 2020-06-02 09:22:40 +00:00
commit 4d2b7fe6ea
6 changed files with 39 additions and 11 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

@ -51,7 +51,7 @@ class EntityManager {
scene.addChild(hudEntitiy.atkSkill) scene.addChild(hudEntitiy.atkSkill)
scene.addChild(hudEntitiy.spySkill) scene.addChild(hudEntitiy.spySkill)
scene.addChild(hudEntitiy.roundTimerLabel) scene.addChild(hudEntitiy.roundTimerLabel)
isModal = true scene.addChild(hudEntitiy.finishButton)
} }
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self) { if let spriteNode = entity.component(ofType: DefaultBaseComponent.self) {

View File

@ -27,6 +27,8 @@ class HUD: GKEntity {
var roundTimerLabel: SKLabelNode var roundTimerLabel: SKLabelNode
let roundTimer: RoundTimer let roundTimer: RoundTimer
var finishButton: ButtonNode
init(size: CGSize) { init(size: CGSize) {
host = GameCenterManager.sharedInstance.hostingPlayer host = GameCenterManager.sharedInstance.hostingPlayer
peer = GameCenterManager.sharedInstance.peerPlayer peer = GameCenterManager.sharedInstance.peerPlayer
@ -38,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()
@ -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), 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 = 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() 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)
@ -93,6 +113,13 @@ class HUD: GKEntity {
func startWithDuration(){ func startWithDuration(){
roundTimer.startTimer() roundTimer.startTimer()
finishButton.isEnabled = true
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

@ -35,7 +35,7 @@ class RoundCalculatorService {
var baseSpecificMoves = collectBaseSpecificMoves() var baseSpecificMoves = collectBaseSpecificMoves()
// TODO: Refactor to a less complex way // 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 targetBase = currentSnapshotModel?.baseEntites.filter { $0.baseId == baseId }[0]
let possiblyOwnershipMoves = playerMovesByBase.filter { $0.key == targetBase?.ownership} 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 playerMove in playerMoves {
for base in currentSnapshotModel!.baseEntites { for base in currentSnapshotModel!.baseEntites {
if base.baseId == playerMove.fromBase { if base.baseId == playerMove.fromBase {
@ -201,9 +201,9 @@ class RoundCalculatorService {
func increaseMoveCounter(ownBase: Bool!) { func increaseMoveCounter(ownBase: Bool!) {
if ownBase { if ownBase {
self.numberOfOwnUnitMoves = self.numberOfOwnUnitMoves + 1 self.numberOfOwnUnitMoves += 1
} else { } else {
self.numberOfAttacks = self.numberOfAttacks + 1 self.numberOfAttacks += 1
} }
} }
} }

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(
@ -30,9 +31,9 @@ class RoundTimer: Timer {
@objc func onTimerFires() @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 { if timeLeft == 0 {
RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats() RoundCalculatorService.sharedInstance.resetNumberOfAttacksAndFormats()