From 6c68a569b991f93efa1945a347dd2158b1e03365 Mon Sep 17 00:00:00 2001 From: 72haja Date: Wed, 22 Apr 2020 18:14:27 +0200 Subject: [PATCH 1/3] Change struct Unit to enum Unit --- GoldWars/GoldWars/Unit/Unit.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/GoldWars/GoldWars/Unit/Unit.swift b/GoldWars/GoldWars/Unit/Unit.swift index f01eba3..a4fa851 100644 --- a/GoldWars/GoldWars/Unit/Unit.swift +++ b/GoldWars/GoldWars/Unit/Unit.swift @@ -6,8 +6,8 @@ // Copyright © 2020 SP2. All rights reserved. // -struct Unit{ - var strength: Float - var health: Float - var defence: Float +enum Unit{ + case General + case Defence + case Attack } From d8adce88d220c7b5c9e7a44d70e6635fef073c34 Mon Sep 17 00:00:00 2001 From: 72haja Date: Wed, 22 Apr 2020 18:16:25 +0200 Subject: [PATCH 2/3] add attributes to Base for unitCount and unitType. Init attributes in constructor with default parameters --- GoldWars/GoldWars/Base/Base.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/GoldWars/GoldWars/Base/Base.swift b/GoldWars/GoldWars/Base/Base.swift index 57bd7bb..06d7071 100644 --- a/GoldWars/GoldWars/Base/Base.swift +++ b/GoldWars/GoldWars/Base/Base.swift @@ -13,8 +13,10 @@ class Base : SKSpriteNode{ public static let colorSelected = SKColor.yellow var availableBases = [Base]() var defaultColor = SKColor.green + var unitType: Unit = Unit.General; + var unitCount: Int = 0; - init(color: UIColor, position: CGPoint, name: String) { + init(color: UIColor, position: CGPoint, name: String, unitCount: Int = 0, unitType: Unit = Unit.General) { super.init(texture: SKTexture(imageNamed: "Base"), color: color, size: CGSize(width: 50.0, height: 50.0) @@ -26,6 +28,8 @@ class Base : SKSpriteNode{ self.position = position self.zPosition = 2 self.isUserInteractionEnabled = true + self.unitCount = unitCount + self.unitType = unitType } required init?(coder aDecoder: NSCoder) { @@ -45,8 +49,7 @@ class Base : SKSpriteNode{ ] ) ) - - } + } override func touchesMoved(_ touches: Set, with event: UIEvent?) { self.color = SKColor.yellow From 31143265f686a87323f5bd41c608a157f62f6434 Mon Sep 17 00:00:00 2001 From: 72haja Date: Wed, 22 Apr 2020 18:17:07 +0200 Subject: [PATCH 3/3] add unitCount and unitType for basePlayer1 and basePlayer2 --- GoldWars/GoldWars/Game/GameScene.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/GoldWars/GoldWars/Game/GameScene.swift b/GoldWars/GoldWars/Game/GameScene.swift index 00b152a..8dcdebf 100644 --- a/GoldWars/GoldWars/Game/GameScene.swift +++ b/GoldWars/GoldWars/Game/GameScene.swift @@ -34,8 +34,8 @@ class GameScene: SKScene, SKPhysicsContactDelegate { let maxX = self.size.width let midY = self.size.height / 2 - let basePlayer1 = Base(color: SKColor.red, position: CGPoint(x: maxX * 0.1, y: midY), name: "Player1" ) - let basePlayer2 = Base(color: SKColor.blue, position: CGPoint(x: maxX * 0.9, y: midY), name: "Player2" ) + let basePlayer1 = Base(color: SKColor.red, position: CGPoint(x: maxX * 0.1, y: midY), name: "Player1", unitCount: 100, unitType: Unit.General) + let basePlayer2 = Base(color: SKColor.blue, position: CGPoint(x: maxX * 0.9, y: midY), name: "Player2", unitCount: 100, unitType: Unit.General) basePlayer2.physicsBody = SKPhysicsBody(circleOfRadius: 50) basePlayer2.physicsBody?.categoryBitMask = physicsBodyNumber.basePlayer2Number basePlayer2.physicsBody?.collisionBitMask = physicsBodyNumber.emptyNumber