From 67a345e9bf835b4cf280b33237c42d790a4da89c Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sat, 2 May 2020 20:47:17 +0200 Subject: [PATCH] Add adjacency mapping --- .../Map/TwoPlayerDefaultTestMap.swift | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift b/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift index 74a46d3..0dbcace 100644 --- a/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift +++ b/GoldWars/GoldWars/Map/TwoPlayerDefaultTestMap.swift @@ -18,6 +18,7 @@ class TwoPlayerDefaultTestMap: MapProtocoll { init(scene: SKScene, entityManager: EntityManager) { self.entityManager = entityManager; self.size = scene.size + self.adjacencyList = Dictionary() } func adjacent(base: Base) -> Array { @@ -25,7 +26,8 @@ class TwoPlayerDefaultTestMap: MapProtocoll { } func create() { - // Player one (leftest base) + + // Create Bases let basePlayerOne = Base( position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2), team: .team1 @@ -48,12 +50,36 @@ class TwoPlayerDefaultTestMap: MapProtocoll { Base(position: CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.75)) ] - // Player two (rightest base) let basePlayerTwo = Base( - position: CGPoint(x: self.size.width * 0.9, y: self.size.height / 2), + position: CGPoint(x: self.size.width * 0.9, y: self.size.height / 2), team: .team2 ) + // Create adjacency Mapping + adjacencyList.updateValue(column1, forKey: basePlayerOne) + + column1.forEach({currBase in + adjacencyList[currBase] = Array() + adjacencyList[currBase]?.append(contentsOf: column2) + adjacencyList[currBase]?.append(basePlayerOne) + }) + + column2.forEach({currBase in + adjacencyList[currBase] = Array() + adjacencyList[currBase]?.append(contentsOf: column3) + adjacencyList[currBase]?.append(contentsOf: column1) + }) + + column3.forEach({currBase in + adjacencyList[currBase] = Array() + adjacencyList[currBase]?.append(basePlayerTwo) + adjacencyList[currBase]?.append(contentsOf: column3) + }) + + adjacencyList.updateValue(column3, forKey: basePlayerTwo) + + + // Add Bases to GameScene entityManager.add(basePlayerOne) column1.forEach({base in entityManager.add(base)})