Move adjacency list into base
Fix typo in MapProtocol Improve MapFactory Generalize MapProtocol
This commit is contained in:
parent
54813ab44d
commit
0dbcbe5eb0
@ -35,7 +35,7 @@
|
|||||||
9EA3ABEF245C834B006BC61D /* ModalContentComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */; };
|
9EA3ABEF245C834B006BC61D /* ModalContentComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EA3ABEE245C834B006BC61D /* ModalContentComponent.swift */; };
|
||||||
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; };
|
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.swift */; };
|
||||||
9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; };
|
9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; };
|
||||||
AB1D759C245DD18100671525 /* MapProtocoll.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759A245DD18100671525 /* MapProtocoll.swift */; };
|
AB1D759C245DD18100671525 /* MapProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759A245DD18100671525 /* MapProtocol.swift */; };
|
||||||
AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */; };
|
AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */; };
|
||||||
AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759F245DEC0500671525 /* MapFactory.swift */; };
|
AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759F245DEC0500671525 /* MapFactory.swift */; };
|
||||||
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; };
|
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; };
|
||||||
@ -94,7 +94,7 @@
|
|||||||
9EC86B9E245C88A300796EF3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = "<group>"; };
|
9EC86B9E245C88A300796EF3 /* Modal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Modal.swift; sourceTree = "<group>"; };
|
||||||
9EC86BA5245C8AD000796EF3 /* ModalType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalType.swift; sourceTree = "<group>"; };
|
9EC86BA5245C8AD000796EF3 /* ModalType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModalType.swift; sourceTree = "<group>"; };
|
||||||
9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = "<group>"; };
|
9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = "<group>"; };
|
||||||
AB1D759A245DD18100671525 /* MapProtocoll.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapProtocoll.swift; sourceTree = "<group>"; };
|
AB1D759A245DD18100671525 /* MapProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapProtocol.swift; sourceTree = "<group>"; };
|
||||||
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoPlayerDefaultTestMap.swift; sourceTree = "<group>"; };
|
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoPlayerDefaultTestMap.swift; sourceTree = "<group>"; };
|
||||||
AB1D759F245DEC0500671525 /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = "<group>"; };
|
AB1D759F245DEC0500671525 /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = "<group>"; };
|
||||||
ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; };
|
ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = "<group>"; };
|
||||||
@ -260,7 +260,7 @@
|
|||||||
AB1D759E245DD2EA00671525 /* Map */ = {
|
AB1D759E245DD2EA00671525 /* Map */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
AB1D759A245DD18100671525 /* MapProtocoll.swift */,
|
AB1D759A245DD18100671525 /* MapProtocol.swift */,
|
||||||
AB1D759F245DEC0500671525 /* MapFactory.swift */,
|
AB1D759F245DEC0500671525 /* MapFactory.swift */,
|
||||||
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */,
|
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */,
|
||||||
);
|
);
|
||||||
@ -416,7 +416,7 @@
|
|||||||
9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */,
|
9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */,
|
||||||
9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */,
|
9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */,
|
||||||
3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */,
|
3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */,
|
||||||
AB1D759C245DD18100671525 /* MapProtocoll.swift in Sources */,
|
AB1D759C245DD18100671525 /* MapProtocol.swift in Sources */,
|
||||||
AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */,
|
AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */,
|
||||||
AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */,
|
AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */,
|
||||||
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */,
|
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */,
|
||||||
|
@ -10,11 +10,15 @@ import SpriteKit
|
|||||||
import GameplayKit
|
import GameplayKit
|
||||||
|
|
||||||
class Base : GKEntity {
|
class Base : GKEntity {
|
||||||
var unitCount:Int
|
var unitCount: Int
|
||||||
|
var adjacencyList: Array<Base>
|
||||||
|
|
||||||
init(position: CGPoint, team: Team! = nil) {
|
init(position: CGPoint, team: Team! = nil) {
|
||||||
self.unitCount = 0
|
self.unitCount = 0
|
||||||
|
self.adjacencyList = Array<Base>()
|
||||||
|
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position))
|
addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position))
|
||||||
if(team != nil){
|
if(team != nil){
|
||||||
addComponent(TeamComponent(team: team!, position: position))
|
addComponent(TeamComponent(team: team!, position: position))
|
||||||
@ -22,6 +26,8 @@ class Base : GKEntity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
@ -14,22 +14,29 @@ class MapFactory {
|
|||||||
var entityManager: EntityManager!
|
var entityManager: EntityManager!
|
||||||
var scene: SKScene!
|
var scene: SKScene!
|
||||||
|
|
||||||
|
var twoPlayerMaps: [MapProtocol]!
|
||||||
|
var threePlayerMaps: [MapProtocol]!
|
||||||
|
var fourPlayerMaps: [MapProtocol]!
|
||||||
|
|
||||||
init(scene: SKScene, entityManager: EntityManager) {
|
init(scene: SKScene, entityManager: EntityManager) {
|
||||||
self.entityManager = entityManager
|
self.entityManager = entityManager
|
||||||
self.scene = scene
|
self.scene = scene
|
||||||
}
|
|
||||||
|
|
||||||
func getTwoPlayerMap() -> MapProtocoll {
|
|
||||||
let map = TwoPlayerDefaultTestMap(scene: self.scene, entityManager: self.entityManager)
|
|
||||||
map.create()
|
|
||||||
return map
|
|
||||||
}
|
|
||||||
|
|
||||||
func getThreePlayerMap() {
|
|
||||||
|
|
||||||
|
self.twoPlayerMaps = [
|
||||||
|
TwoPlayerDefaultTestMap(scene: scene, entityManager: entityManager)
|
||||||
|
]
|
||||||
|
|
||||||
|
self.threePlayerMaps = [MapProtocol]()
|
||||||
|
self.fourPlayerMaps = [MapProtocol]()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getFourPlayerMap() {
|
func loadMap(playerCount: Int) {
|
||||||
|
if playerCount == 2 {
|
||||||
|
twoPlayerMaps.randomElement()?.load()
|
||||||
|
} else if playerCount == 3 {
|
||||||
|
threePlayerMaps.randomElement()?.load()
|
||||||
|
} else {
|
||||||
|
fourPlayerMaps.randomElement()?.load()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,12 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import SpriteKit
|
import SpriteKit
|
||||||
|
|
||||||
protocol MapProtocoll {
|
protocol MapProtocol {
|
||||||
|
|
||||||
var size: CGSize! {get set}
|
var size: CGSize! {get set}
|
||||||
|
var entityManager: EntityManager! {get set}
|
||||||
|
|
||||||
func create()
|
init(scene: SKScene, entityManager: EntityManager)
|
||||||
func adjacent(base: Base) -> Array<Base>
|
|
||||||
|
|
||||||
|
func load()
|
||||||
}
|
}
|
@ -9,23 +9,17 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import SpriteKit
|
import SpriteKit
|
||||||
|
|
||||||
class TwoPlayerDefaultTestMap: MapProtocoll {
|
class TwoPlayerDefaultTestMap: MapProtocol {
|
||||||
|
|
||||||
var entityManager: EntityManager!
|
var entityManager: EntityManager!
|
||||||
var size: CGSize!
|
var size: CGSize!
|
||||||
var adjacencyList: Dictionary<Base, Array<Base>>!
|
|
||||||
|
|
||||||
init(scene: SKScene, entityManager: EntityManager) {
|
required init(scene: SKScene, entityManager: EntityManager) {
|
||||||
self.entityManager = entityManager;
|
self.entityManager = entityManager;
|
||||||
self.size = scene.size
|
self.size = scene.size
|
||||||
self.adjacencyList = Dictionary()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func adjacent(base: Base) -> Array<Base> {
|
func load() {
|
||||||
return adjacencyList[base]!
|
|
||||||
}
|
|
||||||
|
|
||||||
func create() {
|
|
||||||
|
|
||||||
// Create Bases
|
// Create Bases
|
||||||
let basePlayerOne = Base(
|
let basePlayerOne = Base(
|
||||||
@ -56,28 +50,24 @@ class TwoPlayerDefaultTestMap: MapProtocoll {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Create adjacency Mapping
|
// Create adjacency Mapping
|
||||||
adjacencyList.updateValue(column1, forKey: basePlayerOne)
|
basePlayerOne.adjacencyList.append(contentsOf: column1)
|
||||||
|
|
||||||
column1.forEach({currBase in
|
column1.forEach({currBase in
|
||||||
adjacencyList[currBase] = Array<Base>()
|
currBase.adjacencyList.append(contentsOf: column2)
|
||||||
adjacencyList[currBase]?.append(contentsOf: column2)
|
currBase.adjacencyList.append(basePlayerOne)
|
||||||
adjacencyList[currBase]?.append(basePlayerOne)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
column2.forEach({currBase in
|
column2.forEach({currBase in
|
||||||
adjacencyList[currBase] = Array<Base>()
|
currBase.adjacencyList.append(contentsOf: column3)
|
||||||
adjacencyList[currBase]?.append(contentsOf: column3)
|
currBase.adjacencyList.append(contentsOf: column1)
|
||||||
adjacencyList[currBase]?.append(contentsOf: column1)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
column3.forEach({currBase in
|
column3.forEach({currBase in
|
||||||
adjacencyList[currBase] = Array<Base>()
|
currBase.adjacencyList.append(basePlayerTwo)
|
||||||
adjacencyList[currBase]?.append(basePlayerTwo)
|
currBase.adjacencyList.append(contentsOf: column3)
|
||||||
adjacencyList[currBase]?.append(contentsOf: column3)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
adjacencyList.updateValue(column3, forKey: basePlayerTwo)
|
basePlayerTwo.adjacencyList.append(contentsOf: column3)
|
||||||
|
|
||||||
|
|
||||||
// Add Bases to GameScene
|
// Add Bases to GameScene
|
||||||
entityManager.add(basePlayerOne)
|
entityManager.add(basePlayerOne)
|
||||||
|
@ -12,7 +12,6 @@ import GameplayKit
|
|||||||
class GameScene: SKScene{
|
class GameScene: SKScene{
|
||||||
|
|
||||||
var entityManager: EntityManager!
|
var entityManager: EntityManager!
|
||||||
var map: MapProtocoll!
|
|
||||||
|
|
||||||
override func sceneDidLoad() {
|
override func sceneDidLoad() {
|
||||||
entityManager = EntityManager(scene: self)
|
entityManager = EntityManager(scene: self)
|
||||||
@ -36,7 +35,7 @@ class GameScene: SKScene{
|
|||||||
|
|
||||||
// TODO: Issue #24 create Map generation Service
|
// TODO: Issue #24 create Map generation Service
|
||||||
func initMap() {
|
func initMap() {
|
||||||
self.map = MapFactory(scene: self, entityManager: self.entityManager).getTwoPlayerMap()
|
MapFactory(scene: self, entityManager: self.entityManager).loadMap(playerCount: 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user