From e2bd0dc7cf9eb48d308dcca3c638f2dfec11be3b Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Wed, 13 May 2020 22:24:15 +0200 Subject: [PATCH 1/2] Pull protocols in MapFactory Add TwoPlayerMapGenerator Add CenterElementProvider Introduce Logging for MapGenerator --- GoldWars/GoldWars.xcodeproj/project.pbxproj | 5 +- GoldWars/GoldWars/Map/MapFactory.swift | 37 ++++++++++++++- GoldWars/GoldWars/Map/MapProtocol.swift | 20 -------- .../GoldWars/Map/TwoPlayerMapGenerator.swift | 47 +++++++++++++++++++ 4 files changed, 87 insertions(+), 22 deletions(-) delete mode 100644 GoldWars/GoldWars/Map/MapProtocol.swift create mode 100644 GoldWars/GoldWars/Map/TwoPlayerMapGenerator.swift diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index 58ae06f..b3cbfaa 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -49,6 +49,7 @@ 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 */; }; + AB21D7D5246C748A00B09CBA /* TwoPlayerMapGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB21D7D4246C748A00B09CBA /* TwoPlayerMapGenerator.swift */; }; ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; }; AE151589245F18EF001D363E /* MatchmakingHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE151588245F18EF001D363E /* MatchmakingHelper.swift */; }; AEBF3AFF246EB146004F7CD5 /* CancelBtnNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEBF3AFE246EB146004F7CD5 /* CancelBtnNode.swift */; }; @@ -120,6 +121,7 @@ AB1D759A245DD18100671525 /* MapProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapProtocol.swift; sourceTree = ""; }; AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoPlayerDefaultTestMap.swift; sourceTree = ""; }; AB1D759F245DEC0500671525 /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = ""; }; + AB21D7D4246C748A00B09CBA /* TwoPlayerMapGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoPlayerMapGenerator.swift; sourceTree = ""; }; ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = ""; }; AE151588245F18EF001D363E /* MatchmakingHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchmakingHelper.swift; sourceTree = ""; }; AEBF3AFE246EB146004F7CD5 /* CancelBtnNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CancelBtnNode.swift; sourceTree = ""; }; @@ -297,9 +299,9 @@ AB1D759E245DD2EA00671525 /* Map */ = { isa = PBXGroup; children = ( - AB1D759A245DD18100671525 /* MapProtocol.swift */, AB1D759F245DEC0500671525 /* MapFactory.swift */, AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */, + AB21D7D4246C748A00B09CBA /* TwoPlayerMapGenerator.swift */, ); path = Map; sourceTree = ""; @@ -429,6 +431,7 @@ AE151589245F18EF001D363E /* MatchmakingHelper.swift in Sources */, 11036113244B3E30008610AF /* MenuScene.swift in Sources */, C099579C246C5E5C0016AA22 /* DataService.swift in Sources */, + AB21D7D5246C748A00B09CBA /* TwoPlayerMapGenerator.swift in Sources */, 9EA3ABE9245C6DAA006BC61D /* DefaultBaseComponent.swift in Sources */, 9E174C8A245E1A0A00209FF0 /* Background.swift in Sources */, 9EA3ABED245C8143006BC61D /* ModalBackgroundComponent.swift in Sources */, diff --git a/GoldWars/GoldWars/Map/MapFactory.swift b/GoldWars/GoldWars/Map/MapFactory.swift index ab4321a..d305740 100644 --- a/GoldWars/GoldWars/Map/MapFactory.swift +++ b/GoldWars/GoldWars/Map/MapFactory.swift @@ -8,8 +8,30 @@ import Foundation import SpriteKit +import os + +protocol MapProtocol { + var size: CGSize! {get set} + var entityManager: EntityManager! {get set} + + init(scene: SKScene, entityManager: EntityManager) + + func load() +} + +protocol CenterElementProtocol { + + init(frame: CGRect) + + func getAllBases() -> [Base] + func getTopConnection() -> Base + func getRightConnection() -> Base + func getBottomConnection() -> Base + func getLeftConnection() -> Base +} class MapFactory { + let LOG = OSLog.init(subsystem: "MapGenerator", category: "MapFactory") var twoPlayerMaps: [MapProtocol]! var threePlayerMaps: [MapProtocol]! @@ -17,7 +39,7 @@ class MapFactory { init(scene: SKScene, entityManager: EntityManager) { self.twoPlayerMaps = [ - TwoPlayerDefaultTestMap(scene: scene, entityManager: entityManager) + TwoPlayerMapGenerator(scene: scene, entityManager: entityManager) ] self.threePlayerMaps = [MapProtocol]() @@ -26,11 +48,24 @@ class MapFactory { func loadMap(playerCount: Int) { if playerCount == 2 { + os_log("Loading two player map", log: LOG, type: .info) twoPlayerMaps.randomElement()?.load() } else if playerCount == 3 { + os_log("Loading three player map", log: LOG, type: .info) threePlayerMaps.randomElement()?.load() } else { + os_log("Loading four player map", log: LOG, type: .info) fourPlayerMaps.randomElement()?.load() } } } + +class CenterElementProvider { + static let LOG = OSLog.init(subsystem: "MapGenerator", category: "CenterElementProvider") + + static func get(frame: CGRect) -> CenterElementProtocol? { + // TODO: Implemented by Jakob + os_log("Getting new center from provider", log: LOG, type: .info) + return nil + } +} diff --git a/GoldWars/GoldWars/Map/MapProtocol.swift b/GoldWars/GoldWars/Map/MapProtocol.swift deleted file mode 100644 index 2560d39..0000000 --- a/GoldWars/GoldWars/Map/MapProtocol.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// MapProtocoll.swift -// GoldWars -// -// Created by Marcel Schwarz on 02.05.20. -// Copyright © 2020 SP2. All rights reserved. -// - -import Foundation -import SpriteKit - -protocol MapProtocol { - - var size: CGSize! {get set} - var entityManager: EntityManager! {get set} - - init(scene: SKScene, entityManager: EntityManager) - - func load() -} diff --git a/GoldWars/GoldWars/Map/TwoPlayerMapGenerator.swift b/GoldWars/GoldWars/Map/TwoPlayerMapGenerator.swift new file mode 100644 index 0000000..e6271ad --- /dev/null +++ b/GoldWars/GoldWars/Map/TwoPlayerMapGenerator.swift @@ -0,0 +1,47 @@ +// +// TwoPlayerMapGenerator.swift +// GoldWars +// +// Created by Marcel Schwarz on 13.05.20. +// Copyright © 2020 SP2. All rights reserved. +// + +import Foundation +import SpriteKit +import os + +class TwoPlayerMapGenerator: MapProtocol { + let LOG = OSLog.init(subsystem: "MapGenerator", category: "TwoPlayerMapGenerator") + + var size: CGSize! + var entityManager: EntityManager! + + required init(scene: SKScene, entityManager: EntityManager) { + self.size = scene.size + self.entityManager = entityManager + } + + func load() { + os_log("Loading from TwoPlayerMapFactory", log: LOG, type: .info) + getPlayerOneAndStartbases() + getMapCenter() + getPlayerTwoAndStartbases() + } + + private func getPlayerOneAndStartbases() -> [Base]{ + os_log("Get player one and his startbases", log: LOG, type: .info) + return [Base]() + } + + private func getPlayerTwoAndStartbases() -> [Base]{ + os_log("Get player two and his startbases", log: LOG, type: .info) + return [Base]() + } + + private func getMapCenter() -> [Base] { + os_log("Get centered bases", log: LOG, type: .info) + return [Base]() + } + + +} From ee031f71c1e359373b63008ce64216e297afe5d9 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sun, 17 May 2020 19:34:44 +0200 Subject: [PATCH 2/2] Add TwoPlayerMapGenerator --- GoldWars/GoldWars.xcodeproj/project.pbxproj | 6 +- GoldWars/GoldWars/Map/MapFactory.swift | 20 +- GoldWars/GoldWars/Map/SampleCElement.swift | 123 +++++++++++ .../GoldWars/Map/TwoPlayerMapGenerator.swift | 204 ++++++++++++++++-- 4 files changed, 325 insertions(+), 28 deletions(-) create mode 100644 GoldWars/GoldWars/Map/SampleCElement.swift diff --git a/GoldWars/GoldWars.xcodeproj/project.pbxproj b/GoldWars/GoldWars.xcodeproj/project.pbxproj index b3cbfaa..c5fe0d4 100644 --- a/GoldWars/GoldWars.xcodeproj/project.pbxproj +++ b/GoldWars/GoldWars.xcodeproj/project.pbxproj @@ -46,10 +46,10 @@ 9EC86BA6245C8AD000796EF3 /* ModalType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC86BA5245C8AD000796EF3 /* ModalType.swift */; }; 9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */; }; 9EEDE02F246FCD800096C735 /* SpinningLogoComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.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 */; }; AB21D7D5246C748A00B09CBA /* TwoPlayerMapGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB21D7D4246C748A00B09CBA /* TwoPlayerMapGenerator.swift */; }; + AB94038A2471528D004FCD07 /* SampleCElement.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB9403892471528D004FCD07 /* SampleCElement.swift */; }; ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; }; AE151589245F18EF001D363E /* MatchmakingHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE151588245F18EF001D363E /* MatchmakingHelper.swift */; }; AEBF3AFF246EB146004F7CD5 /* CancelBtnNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEBF3AFE246EB146004F7CD5 /* CancelBtnNode.swift */; }; @@ -118,10 +118,10 @@ 9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = GoldWars.entitlements; sourceTree = ""; }; 9EEDE02C246FCD770096C735 /* SpinningLogoEntity.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinningLogoEntity.swift; sourceTree = ""; }; 9EEDE02E246FCD800096C735 /* SpinningLogoComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpinningLogoComponent.swift; sourceTree = ""; }; - AB1D759A245DD18100671525 /* MapProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MapProtocol.swift; sourceTree = ""; }; AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TwoPlayerDefaultTestMap.swift; sourceTree = ""; }; AB1D759F245DEC0500671525 /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = ""; }; AB21D7D4246C748A00B09CBA /* TwoPlayerMapGenerator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TwoPlayerMapGenerator.swift; sourceTree = ""; }; + AB9403892471528D004FCD07 /* SampleCElement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleCElement.swift; sourceTree = ""; }; ABA03D9F244BD54F00A66916 /* Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Base.swift; sourceTree = ""; }; AE151588245F18EF001D363E /* MatchmakingHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchmakingHelper.swift; sourceTree = ""; }; AEBF3AFE246EB146004F7CD5 /* CancelBtnNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CancelBtnNode.swift; sourceTree = ""; }; @@ -302,6 +302,7 @@ AB1D759F245DEC0500671525 /* MapFactory.swift */, AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */, AB21D7D4246C748A00B09CBA /* TwoPlayerMapGenerator.swift */, + AB9403892471528D004FCD07 /* SampleCElement.swift */, ); path = Map; sourceTree = ""; @@ -456,6 +457,7 @@ 9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */, 9E78ACC2245CC9EE00526FF7 /* DefBoostSkillComponent.swift in Sources */, C05FAED62468559D0006AF2E /* SoundManager.swift in Sources */, + AB94038A2471528D004FCD07 /* SampleCElement.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/GoldWars/GoldWars/Map/MapFactory.swift b/GoldWars/GoldWars/Map/MapFactory.swift index d305740..3a6ac77 100644 --- a/GoldWars/GoldWars/Map/MapFactory.swift +++ b/GoldWars/GoldWars/Map/MapFactory.swift @@ -24,10 +24,10 @@ protocol CenterElementProtocol { init(frame: CGRect) func getAllBases() -> [Base] - func getTopConnection() -> Base - func getRightConnection() -> Base - func getBottomConnection() -> Base - func getLeftConnection() -> Base + func getTopConnection() -> Base? + func getRightConnection() -> Base? + func getBottomConnection() -> Base? + func getLeftConnection() -> Base? } class MapFactory { @@ -63,9 +63,15 @@ class MapFactory { class CenterElementProvider { static let LOG = OSLog.init(subsystem: "MapGenerator", category: "CenterElementProvider") - static func get(frame: CGRect) -> CenterElementProtocol? { + static func get(frame: CGRect) -> CenterElementProtocol { // TODO: Implemented by Jakob - os_log("Getting new center from provider", log: LOG, type: .info) - return nil + os_log("Getting new center element from provider", log: LOG, type: .info) + + let centerElements: [CenterElementProtocol.Type] = [ + SampleCElement.self, + CElement7.self + ] + + return centerElements.randomElement()!.init(frame: frame) } } diff --git a/GoldWars/GoldWars/Map/SampleCElement.swift b/GoldWars/GoldWars/Map/SampleCElement.swift new file mode 100644 index 0000000..a15f748 --- /dev/null +++ b/GoldWars/GoldWars/Map/SampleCElement.swift @@ -0,0 +1,123 @@ +// +// CElemente.swift +// GoldWars +// +// Created by Jakob Haag on 14.05.20. +// Copyright © 2020 SP2. All rights reserved. +// + +import Foundation +import SpriteKit + +class SampleCElement : CenterElementProtocol { + var frame: CGRect + var bases: [Base] = [] + var centerBase: Base + + required init(frame: CGRect) { + self.frame = frame + self.centerBase = Base( + position: CGPoint( + x: frame.midX, + y: frame.midY + ) + ) + self.bases.append(centerBase) + } + + func getAllBases() -> [Base] { + return self.bases + } + + func getTopConnection() -> Base? { + return self.centerBase + } + + func getRightConnection() -> Base? { + return self.centerBase + } + + func getBottomConnection() -> Base? { + return self.centerBase + } + + func getLeftConnection() -> Base? { + return self.centerBase + } +} + +// +// CElement7.swift +// GoldWars +// +// Created by Jakob Haag on 14.05.20. +// Copyright © 2020 SP2. All rights reserved. +// + +import Foundation +import SpriteKit + +class CElement7 : CenterElementProtocol { + var frame: CGRect + var bases: [Base] = [] + var topBase: Base + var bottomBase: Base + var leftBase: Base + var rightBase: Base + + required init(frame: CGRect) { + self.frame = frame + self.topBase = Base( + position: CGPoint( + x: frame.midX, + y: frame.minY + ) + ) + + self.bottomBase = Base( + position: CGPoint( + x: frame.midX, + y: frame.maxY + ) + ) + + self.leftBase = Base( + position: CGPoint( + x: frame.minX, + y: frame.midY + ) + ) + + self.rightBase = Base( + position: CGPoint( + x: frame.maxX, + y: frame.midY + ) + ) + self.bases.append(topBase) + self.bases.append(bottomBase) + self.bases.append(leftBase) + self.bases.append(rightBase) + } + + func getAllBases() -> [Base] { + return self.bases + } + + func getTopConnection() -> Base? { + return self.topBase + } + + func getRightConnection() -> Base? { + return self.rightBase + } + + func getBottomConnection() -> Base? { + return self.bottomBase + } + + func getLeftConnection() -> Base? { + return self.leftBase + } +} + diff --git a/GoldWars/GoldWars/Map/TwoPlayerMapGenerator.swift b/GoldWars/GoldWars/Map/TwoPlayerMapGenerator.swift index e6271ad..f6cd9b1 100644 --- a/GoldWars/GoldWars/Map/TwoPlayerMapGenerator.swift +++ b/GoldWars/GoldWars/Map/TwoPlayerMapGenerator.swift @@ -8,6 +8,7 @@ import Foundation import SpriteKit +import GameKit import os class TwoPlayerMapGenerator: MapProtocol { @@ -23,25 +24,190 @@ class TwoPlayerMapGenerator: MapProtocol { func load() { os_log("Loading from TwoPlayerMapFactory", log: LOG, type: .info) - getPlayerOneAndStartbases() - getMapCenter() - getPlayerTwoAndStartbases() + + // Generate bases structure + os_log("Get player one base", log: LOG, type: .info) + let basePlayerOne = Base( + position: CGPoint(x: self.size.width * 0.07, y: self.size.height / 2), + player: (MatchmakingHelper.sharedInstance.isServer) ? GKLocalPlayer.local : MatchmakingHelper.sharedInstance.mpMatch?.players[0], + team: .team1 + ) + + os_log("Get player one's startbases", log: LOG, type: .info) + + let p1StartBaseCount = Int.random(in: 1...3) + var p1StartBases = [String: Base]() + + if (p1StartBaseCount == 1) { + p1StartBases["mid"] = Base(position: CGPoint(x: self.size.width * 0.2, y: self.size.height * 0.5)) + } else if (p1StartBaseCount == 2) { + p1StartBases["top"] = Base(position: CGPoint(x: self.size.width * 0.2, y: self.size.height * 0.333)) + p1StartBases["bot"] = Base(position: CGPoint(x: self.size.width * 0.2, y: self.size.height * 0.666)) + } else { + p1StartBases["top"] = Base(position: CGPoint(x: self.size.width * 0.2, y: self.size.height * 0.25)) + p1StartBases["mid"] = Base(position: CGPoint(x: self.size.width * 0.2, y: self.size.height * 0.5)) + p1StartBases["bot"] = Base(position: CGPoint(x: self.size.width * 0.2, y: self.size.height * 0.75)) + } + + os_log("Generate Map center", log: LOG, type: .info) + let gridCellWidth = self.size.width * 0.2 + let gridCellHeight = self.size.height * 0.4 + let cellInsetX = CGFloat(self.size.width * 0.05) + let cellInsetY = CGFloat(self.size.height * 0.07) + + let gridTopLeft = CGRect( + x: self.size.width * 0.3, + y: self.size.height * 0.1, + width: gridCellWidth, + height: gridCellHeight + ).insetBy(dx: cellInsetX, dy: cellInsetY) + + let gridTopRight = CGRect( + x: self.size.width * 0.3, + y: self.size.height * 0.5, + width: gridCellWidth, + height: gridCellHeight + ).insetBy(dx: cellInsetX, dy: cellInsetY) + + let gridBottomLeft = CGRect( + x: self.size.width * 0.5, + y: self.size.height * 0.1, + width: gridCellWidth, + height: gridCellHeight + ).insetBy(dx: cellInsetX, dy: cellInsetY) + + let gridBottomRight = CGRect( + x: self.size.width * 0.5, + y: self.size.height * 0.5, + width: gridCellWidth, + height: gridCellHeight + ).insetBy(dx: cellInsetX, dy: cellInsetY) + + let topLeft = CenterElementProvider.get(frame: gridTopLeft) + let topRight = CenterElementProvider.get(frame: gridTopRight) + let bottomLeft = CenterElementProvider.get(frame: gridBottomLeft) + let bottomRight = CenterElementProvider.get(frame: gridBottomRight) + + os_log("Get player two base", log: LOG, type: .info) + let basePlayerTwo = Base( + position: CGPoint(x: self.size.width * 0.93, y: self.size.height / 2), + player: (!MatchmakingHelper.sharedInstance.isServer) ? GKLocalPlayer.local : MatchmakingHelper.sharedInstance.mpMatch?.players[0], + team: .team2 + ) + + os_log("Get player two's startbases", log: LOG, type: .info) + let p2StartBaseCount = Int.random(in: 1...3) + var p2StartBases = [String: Base]() + + if (p2StartBaseCount == 1) { + p2StartBases["mid"] = Base(position: CGPoint(x: self.size.width * 0.8, y: self.size.height * 0.5)) + } else if (p1StartBaseCount == 2) { + p2StartBases["top"] = Base(position: CGPoint(x: self.size.width * 0.8, y: self.size.height * 0.333)) + p2StartBases["bot"] = Base(position: CGPoint(x: self.size.width * 0.8, y: self.size.height * 0.666)) + } else { + p2StartBases["top"] = Base(position: CGPoint(x: self.size.width * 0.8, y: self.size.height * 0.25)) + p2StartBases["mid"] = Base(position: CGPoint(x: self.size.width * 0.8, y: self.size.height * 0.5)) + p2StartBases["bot"] = Base(position: CGPoint(x: self.size.width * 0.8, y: self.size.height * 0.75)) + } + + // Create adjacency mapping + os_log("Connecting base p1 and start bases", log: LOG, type: .info) + basePlayerOne.adjacencyList.append(contentsOf: p1StartBases.values) + p1StartBases.values.forEach({base in base.adjacencyList.append(basePlayerOne)}) + + if (p1StartBases["top"] != nil && topLeft.getLeftConnection() != nil) { + os_log("Connecting p1 startbase top with topLeft segment", log: LOG, type: .info) + p1StartBases["top"]!.adjacencyList.append(topLeft.getLeftConnection()!) + topLeft.getLeftConnection()!.adjacencyList.append(p1StartBases["top"]!) + } + + if (p1StartBases["mid"] != nil) { + if (topLeft.getLeftConnection() != nil) { + os_log("Connecting p1 startbase mid with topLeft segment", log: LOG, type: .info) + p1StartBases["mid"]!.adjacencyList.append(topLeft.getLeftConnection()!) + topLeft.getLeftConnection()!.adjacencyList.append(p1StartBases["mid"]!) + } + + if (bottomLeft.getLeftConnection() != nil) { + os_log("Connecting p1 startbase mid with bottomLeft segment", log: LOG, type: .info) + p1StartBases["mid"]!.adjacencyList.append(bottomLeft.getLeftConnection()!) + bottomLeft.getLeftConnection()!.adjacencyList.append(p1StartBases["mid"]!) + } + } + + if (p1StartBases["bot"] != nil && bottomLeft.getLeftConnection() != nil) { + os_log("Connecting p1 startbase bot with bottomLeft segment", log: LOG, type: .info) + p1StartBases["bot"]!.adjacencyList.append(bottomLeft.getLeftConnection()!) + bottomLeft.getLeftConnection()!.adjacencyList.append(p1StartBases["bot"]!) + } + + if (topLeft.getRightConnection() != nil && topRight.getLeftConnection() != nil) { + os_log("Connecting topLeft with topRight segment horizontally", log: LOG, type: .info) + topLeft.getRightConnection()!.adjacencyList.append(topRight.getLeftConnection()!) + topRight.getLeftConnection()!.adjacencyList.append(topLeft.getRightConnection()!) + } + + if (bottomLeft.getRightConnection() != nil && bottomRight.getLeftConnection() != nil) { + os_log("Connecting bottomLeft with bottomRight segment horizontally", log: LOG, type: .info) + bottomLeft.getRightConnection()!.adjacencyList.append(bottomRight.getLeftConnection()!) + bottomRight.getLeftConnection()!.adjacencyList.append(bottomLeft.getRightConnection()!) + } + + if (topLeft.getBottomConnection() != nil && bottomLeft.getTopConnection() != nil) { + os_log("Connecting topLeft with bottomLeft segment vertically", log: LOG, type: .info) + topLeft.getBottomConnection()!.adjacencyList.append(bottomLeft.getTopConnection()!) + bottomLeft.getTopConnection()!.adjacencyList.append(topLeft.getBottomConnection()!) + } + + if (topRight.getBottomConnection() != nil && bottomRight.getTopConnection() != nil) { + os_log("Connecting topRight with bottomRight segment vertically", log: LOG, type: .info) + topRight.getBottomConnection()!.adjacencyList.append(bottomRight.getTopConnection()!) + bottomRight.getTopConnection()!.adjacencyList.append(topRight.getBottomConnection()!) + } + + os_log("Connecting base p2 and start bases", log: LOG, type: .info) + basePlayerTwo.adjacencyList.append(contentsOf: p2StartBases.values) + p2StartBases.values.forEach({base in base.adjacencyList.append(basePlayerTwo)}) + + if (p2StartBases["top"] != nil && topRight.getRightConnection() != nil) { + os_log("Connecting p2 startbase top with topRight segment", log: LOG, type: .info) + p2StartBases["top"]!.adjacencyList.append(topRight.getRightConnection()!) + topRight.getRightConnection()!.adjacencyList.append(p2StartBases["top"]!) + } + + if (p2StartBases["mid"] != nil) { + if (topRight.getRightConnection() != nil) { + os_log("Connecting p2 startbase mid with topRight segment", log: LOG, type: .info) + p2StartBases["mid"]!.adjacencyList.append(topRight.getRightConnection()!) + topRight.getRightConnection()!.adjacencyList.append(p2StartBases["mid"]!) + } + + if (bottomRight.getRightConnection() != nil) { + os_log("Connecting p2 startbase mid with bottomRight segment", log: LOG, type: .info) + p2StartBases["mid"]!.adjacencyList.append(bottomRight.getRightConnection()!) + bottomRight.getRightConnection()!.adjacencyList.append(p2StartBases["mid"]!) + } + } + + if (p2StartBases["bot"] != nil && bottomRight.getRightConnection() != nil) { + os_log("Connecting p2 startbase bot with bottomRight segment", log: LOG, type: .info) + p2StartBases["bot"]!.adjacencyList.append(bottomRight.getRightConnection()!) + bottomRight.getRightConnection()!.adjacencyList.append(p2StartBases["bot"]!) + } + + + // Add all bases to the scene + entityManager.add(basePlayerOne) + p1StartBases.forEach({(key, base) in entityManager.add(base)}) + + topLeft.getAllBases().forEach({base in entityManager.add(base)}) + topRight.getAllBases().forEach({base in entityManager.add(base)}) + bottomLeft.getAllBases().forEach({base in entityManager.add(base)}) + bottomRight.getAllBases().forEach({base in entityManager.add(base)}) + + entityManager.add(basePlayerTwo) + p2StartBases.forEach({(key, base) in entityManager.add(base)}) + } - private func getPlayerOneAndStartbases() -> [Base]{ - os_log("Get player one and his startbases", log: LOG, type: .info) - return [Base]() - } - - private func getPlayerTwoAndStartbases() -> [Base]{ - os_log("Get player two and his startbases", log: LOG, type: .info) - return [Base]() - } - - private func getMapCenter() -> [Base] { - os_log("Get centered bases", log: LOG, type: .info) - return [Base]() - } - - }