Merge branch '25-protokoll-fur-map-interaktion' into 'development'

Align test map to MapProtocol

Closes #25

See merge request marcel.schwarz/software-projekt-2!36
This commit is contained in:
Aldin Duraki 2020-05-02 20:18:45 +00:00
commit 1cf0704af0
7 changed files with 227 additions and 173 deletions

View File

@ -35,8 +35,9 @@
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 */; };
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; }; ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
@ -93,8 +94,9 @@
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>"; };
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>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
@ -258,7 +260,8 @@
AB1D759E245DD2EA00671525 /* Map */ = { AB1D759E245DD2EA00671525 /* Map */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
AB1D759A245DD18100671525 /* MapProtocoll.swift */, AB1D759A245DD18100671525 /* MapProtocol.swift */,
AB1D759F245DEC0500671525 /* MapFactory.swift */,
AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */, AB1D759B245DD18100671525 /* TwoPlayerDefaultTestMap.swift */,
); );
path = Map; path = Map;
@ -413,7 +416,8 @@
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 */,
AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */, AB1D759D245DD18100671525 /* TwoPlayerDefaultTestMap.swift in Sources */,
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */, ABA03DA0244BD54F00A66916 /* Base.swift in Sources */,
110360DB244B101A008610AF /* GameViewController.swift in Sources */, 110360DB244B101A008610AF /* GameViewController.swift in Sources */,

View File

@ -9,19 +9,25 @@
import SpriteKit import SpriteKit
import GameplayKit import GameplayKit
class Base : GKEntity{ class Base : GKEntity {
var unitCount:Int var unitCount: Int
var adjacencyList: Array<Base>
init(textureName:String, team: Team?,position: CGPoint ) { init(position: CGPoint, team: Team! = nil) {
self.unitCount = 0 self.unitCount = 0
self.adjacencyList = [Base]()
super.init() super.init()
addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: textureName), 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))
self.unitCount = 100 self.unitCount = 100
} }
} }
required init?(coder: NSCoder) { required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }

View File

@ -0,0 +1,36 @@
//
// MapFactory.swift
// GoldWars
//
// Created by Marcel Schwarz on 02.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation
import SpriteKit
class MapFactory {
var twoPlayerMaps: [MapProtocol]!
var threePlayerMaps: [MapProtocol]!
var fourPlayerMaps: [MapProtocol]!
init(scene: SKScene, entityManager: EntityManager) {
self.twoPlayerMaps = [
TwoPlayerDefaultTestMap(scene: scene, entityManager: entityManager)
]
self.threePlayerMaps = [MapProtocol]()
self.fourPlayerMaps = [MapProtocol]()
}
func loadMap(playerCount: Int) {
if playerCount == 2 {
twoPlayerMaps.randomElement()?.load()
} else if playerCount == 3 {
threePlayerMaps.randomElement()?.load()
} else {
fourPlayerMaps.randomElement()?.load()
}
}
}

View File

@ -0,0 +1,20 @@
//
// 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()
}

View File

@ -1,15 +0,0 @@
//
// MapProtocoll.swift
// GoldWars
//
// Created by Marcel Schwarz on 02.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import Foundation
protocol MapProtocoll {
func adjacent(base: Base) -> Array<Base>
}

View File

@ -7,13 +7,75 @@
// //
import Foundation import Foundation
import SpriteKit
class TwoPlayerDefaultTestMap: MapProtocoll { class TwoPlayerDefaultTestMap: MapProtocol {
var entityManager: EntityManager!
var size: CGSize!
func adjacent(base: Base) -> Array<Base> { required init(scene: SKScene, entityManager: EntityManager) {
return Array() self.entityManager = entityManager;
self.size = scene.size
} }
func load() {
// Create Bases
let basePlayerOne = Base(
position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2),
team: .team1
)
let column1 = [
Base(position: CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.25)),
Base(position: CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.5)),
Base(position: CGPoint(x: self.size.width * 0.25, y: self.size.height * 0.75))
]
let column2 = [
Base(position: CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.333)),
Base(position: CGPoint(x: self.size.width * 0.5, y: self.size.height * 0.666))
]
let column3 = [
Base(position: CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.25)),
Base(position: CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.5)),
Base(position: CGPoint(x: self.size.width * 0.75, y: self.size.height * 0.75))
]
let basePlayerTwo = Base(
position: CGPoint(x: self.size.width * 0.9, y: self.size.height / 2),
team: .team2
)
// Create adjacency Mapping
basePlayerOne.adjacencyList.append(contentsOf: column1)
column1.forEach({currBase in
currBase.adjacencyList.append(contentsOf: column2)
currBase.adjacencyList.append(basePlayerOne)
})
column2.forEach({currBase in
currBase.adjacencyList.append(contentsOf: column3)
currBase.adjacencyList.append(contentsOf: column1)
})
column3.forEach({currBase in
currBase.adjacencyList.append(basePlayerTwo)
currBase.adjacencyList.append(contentsOf: column3)
})
basePlayerTwo.adjacencyList.append(contentsOf: column3)
// Register bases with the EntityManager
entityManager.add(basePlayerOne)
column1.forEach({base in entityManager.add(base)})
column2.forEach({base in entityManager.add(base)})
column3.forEach({base in entityManager.add(base)})
entityManager.add(basePlayerTwo)
}
} }

View File

@ -15,13 +15,6 @@ class GameScene: SKScene{
override func sceneDidLoad() { override func sceneDidLoad() {
entityManager = EntityManager(scene: self) entityManager = EntityManager(scene: self)
entityManager.add(Base(textureName: "Base",
team: .team1 ,
position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2)))
entityManager.add(Base(textureName: "Base",
team: .team2 ,
position: CGPoint(x: self.size.width * 0.9, y: self.size.height / 2)))
entityManager.add(HUD(size: self.size)) entityManager.add(HUD(size: self.size))
initMap() initMap()
createBackground() createBackground()
@ -40,62 +33,10 @@ class GameScene: SKScene{
} }
} }
// TODO: Issue #24 create Map generation Service
func initMap() { func initMap() {
MapFactory(scene: self, entityManager: self.entityManager).loadMap(playerCount: 2)
createVirginBases()
} }
func createVirginBases() {
for i in 0...7 {
let base:Base
var position = CGPoint(x: 0, y: 0)
switch i {
case 0...2:
let width = self.size.width * 0.25
if i == 0 {
position = CGPoint(x: width, y: self.size.height * 0.25)
}
if i == 1 {
position = CGPoint(x: width, y: self.size.height * 0.5)
}
if i == 2{
position = CGPoint(x: width, y: self.size.height * 0.75)
}
case 3...4:
let width = self.size.width * 0.5
if i == 3{
position = CGPoint(x: width, y: self.size.height * 0.333)
}
if i == 4{
position = CGPoint(x: width, y: self.size.height * 0.666)
}
case 5...7:
let width = self.size.width * 0.75
if i == 5{
position = CGPoint(x: width, y: self.size.height * 0.25)
}
if i == 6{
position = CGPoint(x: width, y: self.size.height * 0.5)
}
if i == 7{
position = CGPoint(x: width, y: self.size.height * 0.75)
}
default:
break
}
base = Base(textureName: "Base", team: nil, position: position)
entityManager.add(base)
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else { guard let touch = touches.first else {