Pull getMapModel in the MapModelStruct

This commit is contained in:
Marcel Schwarz 2020-05-29 16:32:17 +02:00
parent 08dfe6a922
commit 387303af3a
2 changed files with 14 additions and 16 deletions

View File

@ -18,28 +18,13 @@ class MapFactory {
var size: CGSize! var size: CGSize!
var entityManager: EntityManager! var entityManager: EntityManager!
static func getNewMapModel() -> MapGenerationModel {
let noOfCElements = CenterElementProvider.centerElements.count - 1
return MapGenerationModel(
numBasesP1: Int.random(in: 1...3),
numBasesP2: Int.random(in: 1...3),
topLeftId: Int.random(in: 0...noOfCElements),
topRightId: Int.random(in: 0...noOfCElements),
bottomLeftId: Int.random(in: 0...noOfCElements),
bottomRightId: Int.random(in: 0...noOfCElements)
)
}
required init(scene: SKScene, entityManager: EntityManager) { required init(scene: SKScene, entityManager: EntityManager) {
self.size = scene.size self.size = scene.size
self.entityManager = entityManager self.entityManager = entityManager
} }
func load() -> MapGenerationModel { func load() -> MapGenerationModel {
let mapModel = MapFactory.getNewMapModel() let mapModel = MapGenerationModel.new()
load(fromModel: mapModel) load(fromModel: mapModel)
return mapModel return mapModel
} }

View File

@ -34,6 +34,19 @@ struct MapGenerationModel: Codable {
let bottomLeftId: Int let bottomLeftId: Int
let bottomRightId: Int let bottomRightId: Int
static func new() -> MapGenerationModel {
let noOfCElements = CenterElementProvider.centerElements.count - 1
return MapGenerationModel(
numBasesP1: Int.random(in: 1...3),
numBasesP2: Int.random(in: 1...3),
topLeftId: Int.random(in: 0...noOfCElements),
topRightId: Int.random(in: 0...noOfCElements),
bottomLeftId: Int.random(in: 0...noOfCElements),
bottomRightId: Int.random(in: 0...noOfCElements)
)
}
} }
class CenterElementProvider { class CenterElementProvider {