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 */; };
|
||||
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86B9E245C88A300796EF3 /* Modal.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 */; };
|
||||
AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB1D759F245DEC0500671525 /* MapFactory.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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
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>"; };
|
||||
@ -260,7 +260,7 @@
|
||||
AB1D759E245DD2EA00671525 /* Map */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
AB1D759A245DD18100671525 /* MapProtocoll.swift */,
|
||||
AB1D759A245DD18100671525 /* MapProtocol.swift */,
|
||||
AB1D759F245DEC0500671525 /* MapFactory.swift */,
|
||||
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */,
|
||||
);
|
||||
@ -416,7 +416,7 @@
|
||||
9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */,
|
||||
9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */,
|
||||
3EBD242C245D8044003CECE7 /* GameCenterHelper.swift in Sources */,
|
||||
AB1D759C245DD18100671525 /* MapProtocoll.swift in Sources */,
|
||||
AB1D759C245DD18100671525 /* MapProtocol.swift in Sources */,
|
||||
AB1D75A0245DEC0500671525 /* MapFactory.swift in Sources */,
|
||||
AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */,
|
||||
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */,
|
||||
|
@ -11,10 +11,14 @@ import GameplayKit
|
||||
|
||||
class Base : GKEntity {
|
||||
var unitCount: Int
|
||||
var adjacencyList: Array<Base>
|
||||
|
||||
init(position: CGPoint, team: Team! = nil) {
|
||||
self.unitCount = 0
|
||||
self.adjacencyList = Array<Base>()
|
||||
|
||||
super.init()
|
||||
|
||||
addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position))
|
||||
if(team != nil){
|
||||
addComponent(TeamComponent(team: team!, position: position))
|
||||
@ -22,6 +26,8 @@ class Base : GKEntity {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
@ -14,22 +14,29 @@ class MapFactory {
|
||||
var entityManager: EntityManager!
|
||||
var scene: SKScene!
|
||||
|
||||
var twoPlayerMaps: [MapProtocol]!
|
||||
var threePlayerMaps: [MapProtocol]!
|
||||
var fourPlayerMaps: [MapProtocol]!
|
||||
|
||||
init(scene: SKScene, entityManager: EntityManager) {
|
||||
self.entityManager = entityManager
|
||||
self.scene = scene
|
||||
|
||||
self.twoPlayerMaps = [
|
||||
TwoPlayerDefaultTestMap(scene: scene, entityManager: entityManager)
|
||||
]
|
||||
|
||||
self.threePlayerMaps = [MapProtocol]()
|
||||
self.fourPlayerMaps = [MapProtocol]()
|
||||
}
|
||||
|
||||
func getTwoPlayerMap() -> MapProtocoll {
|
||||
let map = TwoPlayerDefaultTestMap(scene: self.scene, entityManager: self.entityManager)
|
||||
map.create()
|
||||
return map
|
||||
}
|
||||
|
||||
func getThreePlayerMap() {
|
||||
|
||||
}
|
||||
|
||||
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 SpriteKit
|
||||
|
||||
protocol MapProtocoll {
|
||||
protocol MapProtocol {
|
||||
|
||||
var size: CGSize! {get set}
|
||||
var entityManager: EntityManager! {get set}
|
||||
|
||||
func create()
|
||||
func adjacent(base: Base) -> Array<Base>
|
||||
init(scene: SKScene, entityManager: EntityManager)
|
||||
|
||||
func load()
|
||||
}
|
@ -9,23 +9,17 @@
|
||||
import Foundation
|
||||
import SpriteKit
|
||||
|
||||
class TwoPlayerDefaultTestMap: MapProtocoll {
|
||||
class TwoPlayerDefaultTestMap: MapProtocol {
|
||||
|
||||
var entityManager: EntityManager!
|
||||
var size: CGSize!
|
||||
var adjacencyList: Dictionary<Base, Array<Base>>!
|
||||
|
||||
init(scene: SKScene, entityManager: EntityManager) {
|
||||
required init(scene: SKScene, entityManager: EntityManager) {
|
||||
self.entityManager = entityManager;
|
||||
self.size = scene.size
|
||||
self.adjacencyList = Dictionary()
|
||||
}
|
||||
|
||||
func adjacent(base: Base) -> Array<Base> {
|
||||
return adjacencyList[base]!
|
||||
}
|
||||
|
||||
func create() {
|
||||
func load() {
|
||||
|
||||
// Create Bases
|
||||
let basePlayerOne = Base(
|
||||
@ -56,28 +50,24 @@ class TwoPlayerDefaultTestMap: MapProtocoll {
|
||||
)
|
||||
|
||||
// Create adjacency Mapping
|
||||
adjacencyList.updateValue(column1, forKey: basePlayerOne)
|
||||
basePlayerOne.adjacencyList.append(contentsOf: column1)
|
||||
|
||||
column1.forEach({currBase in
|
||||
adjacencyList[currBase] = Array<Base>()
|
||||
adjacencyList[currBase]?.append(contentsOf: column2)
|
||||
adjacencyList[currBase]?.append(basePlayerOne)
|
||||
currBase.adjacencyList.append(contentsOf: column2)
|
||||
currBase.adjacencyList.append(basePlayerOne)
|
||||
})
|
||||
|
||||
column2.forEach({currBase in
|
||||
adjacencyList[currBase] = Array<Base>()
|
||||
adjacencyList[currBase]?.append(contentsOf: column3)
|
||||
adjacencyList[currBase]?.append(contentsOf: column1)
|
||||
currBase.adjacencyList.append(contentsOf: column3)
|
||||
currBase.adjacencyList.append(contentsOf: column1)
|
||||
})
|
||||
|
||||
column3.forEach({currBase in
|
||||
adjacencyList[currBase] = Array<Base>()
|
||||
adjacencyList[currBase]?.append(basePlayerTwo)
|
||||
adjacencyList[currBase]?.append(contentsOf: column3)
|
||||
currBase.adjacencyList.append(basePlayerTwo)
|
||||
currBase.adjacencyList.append(contentsOf: column3)
|
||||
})
|
||||
|
||||
adjacencyList.updateValue(column3, forKey: basePlayerTwo)
|
||||
|
||||
basePlayerTwo.adjacencyList.append(contentsOf: column3)
|
||||
|
||||
// Add Bases to GameScene
|
||||
entityManager.add(basePlayerOne)
|
||||
|
@ -12,7 +12,6 @@ import GameplayKit
|
||||
class GameScene: SKScene{
|
||||
|
||||
var entityManager: EntityManager!
|
||||
var map: MapProtocoll!
|
||||
|
||||
override func sceneDidLoad() {
|
||||
entityManager = EntityManager(scene: self)
|
||||
@ -36,7 +35,7 @@ class GameScene: SKScene{
|
||||
|
||||
// TODO: Issue #24 create Map generation Service
|
||||
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