Merge branch 'development' into 36-runde-beenden-mit-berechnetem-angriff
# Conflicts: # GoldWars/GoldWars/Entities/Base.swift # GoldWars/GoldWars/Entities/EntityManager.swift # GoldWars/GoldWars/MatchmakingHelper.swift
This commit is contained in:
commit
d949f57a87
@ -8,12 +8,14 @@
|
|||||||
|
|
||||||
import SpriteKit
|
import SpriteKit
|
||||||
import GameplayKit
|
import GameplayKit
|
||||||
|
import GameKit
|
||||||
|
|
||||||
class TeamComponent: GKComponent {
|
class TeamComponent: GKComponent {
|
||||||
let team: Team
|
let team: Team
|
||||||
let fire: SKEmitterNode
|
let fire: SKEmitterNode
|
||||||
|
let player: GKPlayer
|
||||||
|
|
||||||
init(team: Team, position: CGPoint) {
|
init(team: Team, player: GKPlayer, position: CGPoint) {
|
||||||
fire = SKEmitterNode(fileNamed: "Fire")!
|
fire = SKEmitterNode(fileNamed: "Fire")!
|
||||||
fire.zPosition = -1
|
fire.zPosition = -1
|
||||||
fire.position = position
|
fire.position = position
|
||||||
@ -29,6 +31,7 @@ class TeamComponent: GKComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.team = team
|
self.team = team
|
||||||
|
self.player = player
|
||||||
super.init()
|
super.init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,29 +8,39 @@
|
|||||||
|
|
||||||
import SpriteKit
|
import SpriteKit
|
||||||
import GameplayKit
|
import GameplayKit
|
||||||
|
import GameKit
|
||||||
|
|
||||||
class Base: GKEntity{
|
class Base: GKEntity{
|
||||||
static var BASE_ID_COUNT: Int = 0
|
static var BASE_ID_COUNT: Int = 0
|
||||||
var unitCount: Int
|
var unitCount: Int
|
||||||
var adjacencyList: Array<Base>
|
var adjacencyList: Array<Base>
|
||||||
var changeOwnerShip: Bool
|
var changeOwnership: Bool
|
||||||
|
var ownershipPlayer: GKPlayer?
|
||||||
var baseID: Int
|
var baseID: Int
|
||||||
|
|
||||||
init(position: CGPoint, team: Team! = nil) {
|
init(position: CGPoint, player: GKPlayer! = nil, team: Team! = nil) {
|
||||||
self.unitCount = 0
|
self.unitCount = 0
|
||||||
self.adjacencyList = [Base]()
|
self.adjacencyList = [Base]()
|
||||||
self.changeOwnerShip = false
|
self.changeOwnership = false
|
||||||
baseID = Base.BASE_ID_COUNT
|
self.ownershipPlayer = player
|
||||||
Base.BASE_ID_COUNT += 1
|
Base.BASE_ID_COUNT += 1
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position))
|
addComponent(DefaultBaseComponent(texture: SKTexture(imageNamed: "Base"), position: position))
|
||||||
if(team != nil){
|
if(team != nil && player != nil){
|
||||||
addComponent(TeamComponent(team: team!, position: position))
|
addComponent(TeamComponent(team: team!, player: player!, position: position))
|
||||||
self.unitCount = 500
|
self.unitCount = 500
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func attackBase(base: Base, units:Int) -> [GKEntity]{
|
||||||
|
base.changeOwnership = true
|
||||||
|
base.ownershipPlayer = self.ownershipPlayer
|
||||||
|
self.unitCount -= units
|
||||||
|
base.unitCount += units
|
||||||
|
DataService.sharedInstance.addMove(playerMove: PlayerMove(fromBase: self.baseID, toBase: base.baseID, unitCount: units))
|
||||||
|
return [self, base]
|
||||||
|
}
|
||||||
func attackBase(base: Base, units: Int) -> [GKEntity]{
|
func attackBase(base: Base, units: Int) -> [GKEntity]{
|
||||||
base.changeOwnerShip = true
|
base.changeOwnerShip = true
|
||||||
self.unitCount -= units
|
self.unitCount -= units
|
||||||
@ -38,7 +48,7 @@ class Base: GKEntity{
|
|||||||
DataService.sharedInstance.addMove(playerMove: PlayerMove(fromBase: self.baseID, toBase: base.baseID, unitCount: units))
|
DataService.sharedInstance.addMove(playerMove: PlayerMove(fromBase: self.baseID, toBase: base.baseID, unitCount: units))
|
||||||
return [self, base]
|
return [self, base]
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
@ -8,62 +8,63 @@
|
|||||||
|
|
||||||
import SpriteKit
|
import SpriteKit
|
||||||
import GameplayKit
|
import GameplayKit
|
||||||
|
import GameKit
|
||||||
|
|
||||||
class EntityManager {
|
class EntityManager {
|
||||||
|
|
||||||
var entities = Set<GKEntity>()
|
var entities = Set<GKEntity>()
|
||||||
let scene: SKScene
|
let scene: SKScene
|
||||||
var isModal: Bool
|
var isModal: Bool
|
||||||
|
|
||||||
init(scene: SKScene) {
|
init(scene: SKScene) {
|
||||||
self.scene = scene
|
self.scene = scene
|
||||||
isModal = false
|
isModal = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func add(_ entity: GKEntity) {
|
func add(_ entity: GKEntity) {
|
||||||
entities.insert(entity)
|
entities.insert(entity)
|
||||||
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
||||||
scene.addChild(spriteNode)
|
scene.addChild(spriteNode)
|
||||||
}
|
}
|
||||||
if let fire = entity.component(ofType: TeamComponent.self)?.fire{
|
if let fire = entity.component(ofType: TeamComponent.self)?.fire{
|
||||||
scene.addChild(fire)
|
scene.addChild(fire)
|
||||||
}
|
}
|
||||||
if let spriteNode = entity.component(ofType: ModalBackgroundComponent.self)?.spriteNode {
|
if let spriteNode = entity.component(ofType: ModalBackgroundComponent.self)?.spriteNode {
|
||||||
scene.addChild(spriteNode)
|
scene.addChild(spriteNode)
|
||||||
isModal = true
|
}
|
||||||
}
|
if let modal = entity.component(ofType: ModalContentComponent.self) {
|
||||||
if let modal = entity.component(ofType: ModalContentComponent.self) {
|
scene.addChild(modal.header)
|
||||||
scene.addChild(modal.header)
|
scene.addChild(modal.body)
|
||||||
scene.addChild(modal.body)
|
scene.addChild(modal.footer)
|
||||||
scene.addChild(modal.footer)
|
}
|
||||||
}
|
if let skill = entity.component(ofType: AtkBoostSkillComponent.self) {
|
||||||
if let skill = entity.component(ofType: AtkBoostSkillComponent.self) {
|
scene.addChild(skill.shapeNode)
|
||||||
scene.addChild(skill.shapeNode)
|
scene.addChild(skill.labelNode)
|
||||||
scene.addChild(skill.labelNode)
|
}
|
||||||
}
|
if let skill = entity.component(ofType: DefBoostSkillComponent.self) {
|
||||||
if let skill = entity.component(ofType: DefBoostSkillComponent.self) {
|
scene.addChild(skill.shapeNode)
|
||||||
scene.addChild(skill.shapeNode)
|
scene.addChild(skill.labelNode)
|
||||||
scene.addChild(skill.labelNode)
|
}
|
||||||
}
|
if let skill = entity.component(ofType: SpySkillComponent.self) {
|
||||||
if let skill = entity.component(ofType: SpySkillComponent.self) {
|
scene.addChild(skill.shapeNode)
|
||||||
scene.addChild(skill.shapeNode)
|
scene.addChild(skill.labelNode)
|
||||||
scene.addChild(skill.labelNode)
|
}
|
||||||
}
|
|
||||||
if let timer = entity.component(ofType: TimerComponent.self) {
|
if let timer = entity.component(ofType: TimerComponent.self) {
|
||||||
scene.addChild(timer.labelNode)
|
scene.addChild(timer.labelNode)
|
||||||
}
|
}
|
||||||
if let buttonNode = entity.component(ofType: ButtonComponent.self)?.buttonNode {
|
if let buttonNode = entity.component(ofType: ButtonComponent.self)?.buttonNode {
|
||||||
scene.addChild(buttonNode)
|
scene.addChild(buttonNode)
|
||||||
|
isModal = true
|
||||||
}
|
}
|
||||||
if let nodes = entity.component(ofType: BackgroundComponent.self)?.nodes {
|
if let nodes = entity.component(ofType: BackgroundComponent.self)?.nodes {
|
||||||
for node in nodes {
|
for node in nodes {
|
||||||
scene.addChild(node)
|
scene.addChild(node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
|
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
|
||||||
scene.addChild(sliderNode.sliderKnob)
|
scene.addChild(sliderNode.sliderKnob)
|
||||||
scene.addChild(sliderNode.sliderLine)
|
scene.addChild(sliderNode.sliderLine)
|
||||||
}
|
}
|
||||||
if let labelNode = entity.component(ofType: LabelComponent.self)?.labelNode {
|
if let labelNode = entity.component(ofType: LabelComponent.self)?.labelNode {
|
||||||
scene.addChild(labelNode)
|
scene.addChild(labelNode)
|
||||||
}
|
}
|
||||||
@ -73,65 +74,88 @@ class EntityManager {
|
|||||||
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
if let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
||||||
spriteNode.removeFromParent()
|
spriteNode.removeFromParent()
|
||||||
}
|
}
|
||||||
if let spriteNode = entity.component(ofType: ModalBackgroundComponent.self)?.spriteNode {
|
if let spriteNode = entity.component(ofType: ModalBackgroundComponent.self)?.spriteNode {
|
||||||
spriteNode.removeFromParent()
|
spriteNode.removeFromParent()
|
||||||
isModal = false
|
}
|
||||||
}
|
if let modal = entity.component(ofType: ModalContentComponent.self) {
|
||||||
if let modal = entity.component(ofType: ModalContentComponent.self) {
|
modal.header.removeFromParent()
|
||||||
modal.header.removeFromParent()
|
modal.body.removeFromParent()
|
||||||
modal.body.removeFromParent()
|
modal.footer.removeFromParent()
|
||||||
modal.footer.removeFromParent()
|
}
|
||||||
}
|
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
|
||||||
if let sliderNode = entity.component(ofType: SliderComponent.self)?.sliderNode {
|
sliderNode.sliderKnob.removeFromParent()
|
||||||
sliderNode.sliderKnob.removeFromParent()
|
sliderNode.sliderLine.removeFromParent()
|
||||||
sliderNode.sliderLine.removeFromParent()
|
}
|
||||||
}
|
if let modalButton = entity.component(ofType: ButtonComponent.self) {
|
||||||
|
modalButton.buttonNode.removeFromParent()
|
||||||
|
isModal = false
|
||||||
|
}
|
||||||
entities.remove(entity)
|
entities.remove(entity)
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(_ entities: [GKEntity]){
|
func update(_ entities: [GKEntity]){
|
||||||
for entity in entities {
|
for entity in entities {
|
||||||
self.entities.update(with: entity)
|
self.entities.update(with: entity)
|
||||||
let base = (entity as! Base)
|
let base = (entity as! Base)
|
||||||
|
|
||||||
if base.changeOwnerShip {
|
if base.changeOwnership {
|
||||||
base.addComponent(TeamComponent(team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team, position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!))
|
base.addComponent(TeamComponent(
|
||||||
base.changeOwnerShip = false
|
team: (entities[0] as! Base).component(ofType: TeamComponent.self)!.team,
|
||||||
scene.addChild(base.component(ofType: TeamComponent.self)!.fire)
|
player: (entities[0] as! Base).component(ofType: TeamComponent.self)!.player,
|
||||||
}
|
position: (base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position)!
|
||||||
}
|
)
|
||||||
|
)
|
||||||
|
base.changeOwnership = false
|
||||||
|
scene.addChild(base.component(ofType: TeamComponent.self)!.fire)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBaseByTeam(for team: Team) -> GKEntity? {
|
func getBaseByPlayer(for player: GKPlayer) -> GKEntity? {
|
||||||
for entity in entities {
|
for entity in entities {
|
||||||
if let teamComponent = entity.component(ofType: TeamComponent.self),
|
if let teamComponent = entity.component(ofType: TeamComponent.self),
|
||||||
let _ = entity.component(ofType: DefaultBaseComponent.self) {
|
let _ = entity.component(ofType: DefaultBaseComponent.self) {
|
||||||
|
if teamComponent.player == player {
|
||||||
|
return entity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getBaseByTeam(for team: Team) -> GKEntity? {
|
||||||
|
for entity in entities {
|
||||||
|
if let teamComponent = entity.component(ofType: TeamComponent.self),
|
||||||
|
let _ = entity.component(ofType: DefaultBaseComponent.self) {
|
||||||
if teamComponent.team == team {
|
if teamComponent.team == team {
|
||||||
return entity
|
return entity
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBasesByTeam(for team: Team) -> Set<Base> {
|
func getBasesByTeam(for team: Team) -> Set<Base> {
|
||||||
return entities.filter{$0 is Base && ($0 as! Base).component(ofType: TeamComponent.self)?.team == team } as! Set<Base>
|
return entities.filter{$0 is Base && ($0 as! Base).component(ofType: TeamComponent.self)?.team == team } as! Set<Base>
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTeamByBase(base: Base) -> Team? {
|
func getBasesByPlayer(for player: GKPlayer) -> Set<Base> {
|
||||||
for entity in entities {
|
return entities.filter{$0 is Base && ($0 as! Base).component(ofType: TeamComponent.self)?.player == player } as! Set<Base>
|
||||||
if entity is Base && entity == base{
|
}
|
||||||
for component in entity.components{
|
|
||||||
if component is TeamComponent {
|
|
||||||
return entity.component(ofType: TeamComponent.self)!.team
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
|
func getTeamByBase(base: Base) -> Team? {
|
||||||
|
for entity in entities {
|
||||||
|
if entity is Base && entity == base{
|
||||||
|
for component in entity.components{
|
||||||
|
if component is TeamComponent {
|
||||||
|
return entity.component(ofType: TeamComponent.self)!.team
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func getBasebyID(id: Int) -> Base?{
|
func getBasebyID(id: Int) -> Base?{
|
||||||
for entity in entities {
|
for entity in entities {
|
||||||
@ -141,13 +165,14 @@ class EntityManager {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBackground() -> GKEntity? {
|
func getBackground() -> GKEntity? {
|
||||||
return entities.filter{$0 is Background}[0]
|
return entities.filter{$0 is Background}[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
func getBaseNodeByTeam(for team: Team) -> SKSpriteNode? {
|
func getBaseNodeByTeam(for team: Team) -> SKSpriteNode? {
|
||||||
return getBaseByTeam(for: team)?.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
return getBaseByTeam(for: team)?.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
||||||
}
|
}
|
||||||
|
|
||||||
func getButtonByName(buttonName:String) -> Button {
|
func getButtonByName(buttonName:String) -> Button {
|
||||||
return entities.filter{$0 is Button && ($0 as! Button).name == buttonName }[0] as! Button
|
return entities.filter{$0 is Button && ($0 as! Button).name == buttonName }[0] as! Button
|
||||||
|
@ -9,31 +9,44 @@
|
|||||||
import GameplayKit
|
import GameplayKit
|
||||||
|
|
||||||
class Modal: GKEntity{
|
class Modal: GKEntity{
|
||||||
|
|
||||||
var unitCount:Int
|
|
||||||
|
|
||||||
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint) {
|
var unitCount:Int
|
||||||
unitCount = base.unitCount
|
|
||||||
super.init()
|
init(modaltype: ModalType, base: Base, anchorPoint: CGPoint, entityManager: EntityManager, gameScene: SKScene) {
|
||||||
switch modaltype{
|
unitCount = base.unitCount
|
||||||
case .BaseDetails:
|
super.init()
|
||||||
addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint))
|
switch modaltype{
|
||||||
addComponent(ModalContentComponent(header: "Basis Information",
|
case .BaseDetails:
|
||||||
body: "Diese Basis enthält \(base.unitCount) Einheiten",
|
addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint))
|
||||||
footer: "",
|
addComponent(ModalContentComponent(header: "Basis Information", body: "Diese Basis enthält \(base.unitCount) Einheiten", footer: "", anchorPoint: anchorPoint))
|
||||||
anchorPoint: anchorPoint))
|
addComponent(ButtonComponent(iconName: "", text: "Zurück", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: {
|
||||||
case .BaseAttack:
|
self.removeModalEntities(entityManager: entityManager, gameScene: gameScene)
|
||||||
addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint))
|
}))
|
||||||
addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 80)))
|
case .BaseAttack:
|
||||||
addComponent(ModalContentComponent(header: "Angriff",
|
addComponent(ModalBackgroundComponent(anchorPoint: anchorPoint))
|
||||||
body: "Schicke \(unitCount / 2) Einheiten",
|
addComponent(SliderComponent(width: 300, position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 50)))
|
||||||
footer: "",
|
addComponent(ModalContentComponent(header: "Angriff", body: "Schicke \(unitCount / 2) Einheiten",
|
||||||
anchorPoint: anchorPoint))
|
footer: "", anchorPoint: anchorPoint))
|
||||||
}
|
addComponent(ButtonComponent(iconName: "", text: "Senden", position: CGPoint(x: anchorPoint.x , y: anchorPoint.y - 120), isEnabled: true, onButtonPress: {
|
||||||
}
|
self.removeModalEntities(entityManager: entityManager, gameScene: gameScene)
|
||||||
|
}))
|
||||||
required init?(coder: NSCoder) {
|
}
|
||||||
fatalError("init(coder:) has not been implemented")
|
}
|
||||||
}
|
|
||||||
|
required init?(coder: NSCoder) {
|
||||||
|
fatalError("init(coder:) has not been implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func removeModalEntities(entityManager: EntityManager, gameScene: SKScene){
|
||||||
|
for entity in entityManager.entities {
|
||||||
|
if entityManager.isModal && entity.isMember(of: Modal.self) {
|
||||||
|
entityManager.remove(entity)
|
||||||
|
}
|
||||||
|
for child in gameScene.children {
|
||||||
|
if(child.name != "fire"){
|
||||||
|
child.alpha = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import SpriteKit
|
import SpriteKit
|
||||||
|
import GameKit
|
||||||
|
|
||||||
class TwoPlayerDefaultTestMap: MapProtocol {
|
class TwoPlayerDefaultTestMap: MapProtocol {
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ class TwoPlayerDefaultTestMap: MapProtocol {
|
|||||||
// Create Bases
|
// Create Bases
|
||||||
let basePlayerOne = Base(
|
let basePlayerOne = Base(
|
||||||
position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2),
|
position: CGPoint(x: self.size.width * 0.1, y: self.size.height / 2),
|
||||||
|
player: (MatchmakingHelper.sharedInstance.isServer) ? GKLocalPlayer.local : MatchmakingHelper.sharedInstance.mpMatch?.players[0],
|
||||||
team: .team1
|
team: .team1
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,6 +48,7 @@ class TwoPlayerDefaultTestMap: MapProtocol {
|
|||||||
|
|
||||||
let basePlayerTwo = 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),
|
||||||
|
player: (!MatchmakingHelper.sharedInstance.isServer) ? GKLocalPlayer.local : MatchmakingHelper.sharedInstance.mpMatch?.players[0],
|
||||||
team: .team2
|
team: .team2
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -72,15 +72,15 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Der User hat die Verbindung mit "Abbrechen" unterbrochen. GameCenter MatchMaking wird beendet.
|
Der User hat die Verbindung mit "Abbrechen" unterbrochen. GameCenter MatchMaking wird beendet.
|
||||||
*/
|
*/
|
||||||
func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) {
|
func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) {
|
||||||
viewController.dismiss(animated: true, completion: nil)
|
viewController.dismiss(animated: true, completion: nil)
|
||||||
delegate?.matchEnded()
|
delegate?.matchEnded()
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Wenn GameCenter kein match erstellen kann, wird der viewcontroller dismissed.
|
Wenn GameCenter kein match erstellen kann, wird der viewcontroller dismissed.
|
||||||
*/
|
*/
|
||||||
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFailWithError error: Error) {
|
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFailWithError error: Error) {
|
||||||
viewController.dismiss(animated: true, completion: nil)
|
viewController.dismiss(animated: true, completion: nil)
|
||||||
print("Error finding match", error.localizedDescription)
|
print("Error finding match", error.localizedDescription)
|
||||||
@ -91,7 +91,7 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
Gamecenter hat erfolgreich ein Match gefunden, das Spiel kann gestartet werden.
|
Gamecenter hat erfolgreich ein Match gefunden, das Spiel kann gestartet werden.
|
||||||
expectedPlayerCount: Die verbleibende Anzahl von Spielern, die sich noch nicht mit dem Spiel verbunden haben
|
expectedPlayerCount: Die verbleibende Anzahl von Spielern, die sich noch nicht mit dem Spiel verbunden haben
|
||||||
z.B 0 gibt an, dass keine weiteren Spieler benötigt werden um das Match zu starten
|
z.B 0 gibt an, dass keine weiteren Spieler benötigt werden um das Match zu starten
|
||||||
*/
|
*/
|
||||||
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) {
|
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) {
|
||||||
viewController.dismiss(animated: true, completion: nil)
|
viewController.dismiss(animated: true, completion: nil)
|
||||||
mpMatch = match
|
mpMatch = match
|
||||||
@ -101,22 +101,18 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Vom match erhaltene Spielerdaten
|
Vom match erhaltene Spielerdaten
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func match(_ match: GKMatch, didReceive data: Data, fromRemotePlayer player: GKPlayer) {
|
func match(_ match: GKMatch, didReceive data: Data, fromRemotePlayer player: GKPlayer) {
|
||||||
if mpMatch != match { return }
|
if mpMatch != match { return }
|
||||||
|
|
||||||
let jsonDecoder = JSONDecoder()
|
let jsonDecoder = JSONDecoder()
|
||||||
|
|
||||||
if let playerMoves = try? jsonDecoder.decode([PlayerMove].self, from: data) {
|
if let playerMoves = try? jsonDecoder.decode([PlayerMove].self, from: data) {
|
||||||
DataService.sharedInstance.addRemotePlayerMoves(playerID: player.displayName, playerMoves: playerMoves)
|
DataService.sharedInstance.addRemotePlayerMoves(playerID: player.displayName, playerMoves: playerMoves)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let message = try? jsonDecoder.decode(Host.self, from: data) {
|
if let message = try? jsonDecoder.decode(Host.self, from: data) {
|
||||||
DataService.sharedInstance.gameHost = message
|
DataService.sharedInstance.gameHost = message
|
||||||
}
|
}
|
||||||
@ -137,7 +133,6 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
/*
|
/*
|
||||||
Wird beim ändern des States/Zustands des Spielers aufgerufen udn gibt dessen Zustand zurück.
|
Wird beim ändern des States/Zustands des Spielers aufgerufen udn gibt dessen Zustand zurück.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func match(_ match: GKMatch, player: GKPlayer, didChange state: GKPlayerConnectionState) {
|
func match(_ match: GKMatch, player: GKPlayer, didChange state: GKPlayerConnectionState) {
|
||||||
if mpMatch != match {
|
if mpMatch != match {
|
||||||
return
|
return
|
||||||
@ -157,31 +152,29 @@ class MatchmakingHelper: NSObject, GKMatchmakerViewControllerDelegate, GKMatchDe
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Ein Spieler wird als Host für das Match gewählt. Dieser ist Spieler 1. Im Anschluss wird die GameScene geladen.
|
Ein Spieler wird als Host für das Match gewählt. Dieser ist Spieler 1. Im Anschluss wird die GameScene geladen.
|
||||||
*/
|
*/
|
||||||
func startMatch() {
|
func startMatch() {
|
||||||
|
|
||||||
mpMatch!.chooseBestHostingPlayer(completionHandler: {
|
mpMatch!.chooseBestHostingPlayer(completionHandler: {
|
||||||
(player) in
|
(player) in
|
||||||
|
|
||||||
self.mpMatchStarted = true
|
self.mpMatchStarted = true
|
||||||
|
|
||||||
if player == GKLocalPlayer.local {
|
if player == GKLocalPlayer.local {
|
||||||
print("ich bin host")
|
|
||||||
self.isServer = true
|
self.isServer = true
|
||||||
self.spieler1 = player
|
self.spieler1 = player
|
||||||
self.nameSpieler1 = self.spieler1!.displayName
|
self.nameSpieler1 = self.spieler1!.displayName
|
||||||
DataService.sharedInstance.setGameHost(host: Host(playerID: player!.displayName))
|
|
||||||
} else {
|
} else {
|
||||||
self.isServer = false
|
self.isServer = false
|
||||||
}
|
}
|
||||||
|
|
||||||
self.delegate?.matchStarted()
|
self.delegate?.matchStarted()
|
||||||
self.menusc!.loadScene(scene: GameScene(size: self.menusc!.size))
|
self.menusc!.loadScene(scene: GameScene(size: self.menusc!.size))
|
||||||
MultiplayerNetwork.sharedInstance.sendHostIdentifier()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Trennt die Verbindung vom Match
|
Trennt die Verbindung vom Match
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
import SpriteKit
|
import SpriteKit
|
||||||
import GameplayKit
|
import GameplayKit
|
||||||
|
import GameKit
|
||||||
|
|
||||||
class GameScene: SKScene{
|
class GameScene: SKScene{
|
||||||
|
|
||||||
@ -22,54 +23,47 @@ class GameScene: SKScene{
|
|||||||
entityManager.add(Background(size: self.size))
|
entityManager.add(Background(size: self.size))
|
||||||
initMap()
|
initMap()
|
||||||
}
|
}
|
||||||
|
|
||||||
func initMap() {
|
func initMap() {
|
||||||
MapFactory(scene: self, entityManager: self.entityManager).loadMap(playerCount: 2)
|
MapFactory(scene: self, entityManager: self.entityManager).loadMap(playerCount: 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
guard let touch = touches.first else {
|
guard let touch = touches.first else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let touchLocation = touch.location(in: self)
|
let touchLocation = touch.location(in: self)
|
||||||
|
|
||||||
if isMoveTouch{
|
if isMoveTouch{
|
||||||
isMoveTouch = false
|
isMoveTouch = false
|
||||||
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos
|
currentDraggedBase!.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = currentDraggedBasePos
|
||||||
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
|
currentDraggedBase!.component(ofType: TeamComponent.self)?.fire.position = currentDraggedBasePos
|
||||||
|
|
||||||
for base in currentDraggedBase!.adjacencyList {
|
for base in currentDraggedBase!.adjacencyList {
|
||||||
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode {
|
||||||
// TODO: change interaction based on collision instead of touchlocation
|
// TODO: change interaction based on collision instead of touchlocation
|
||||||
|
|
||||||
if !(entityManager.getTeamByBase(base: currentDraggedBase!) == entityManager.getTeamByBase(base: base)){
|
if !(entityManager.getTeamByBase(base: currentDraggedBase!) == entityManager.getTeamByBase(base: base)){
|
||||||
entityManager.add(Modal(modaltype: .BaseAttack,
|
entityManager.add(Modal(modaltype: .BaseAttack,
|
||||||
base: currentDraggedBase!,
|
base: currentDraggedBase!,
|
||||||
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2)))
|
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
||||||
entityManager.update((currentDraggedBase?.attackBase(base: base, units: 100))!)
|
entityManager: entityManager, gameScene: self))
|
||||||
}else {
|
entityManager.update((currentDraggedBase?.attackBase(base: base, units: 100))!)
|
||||||
entityManager.add(Modal(modaltype: .BaseAttack,
|
}else {
|
||||||
base: currentDraggedBase!,
|
entityManager.add(Modal(modaltype: .BaseAttack,
|
||||||
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2)))
|
base: currentDraggedBase!,
|
||||||
}
|
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
||||||
|
entityManager: entityManager, gameScene: self))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
for entity in entityManager.entities {
|
for entity in entityManager.entities {
|
||||||
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
let spriteNode = entity.component(ofType: DefaultBaseComponent.self)?.spriteNode
|
||||||
|
|
||||||
if entityManager.isModal && entity.isMember(of: Modal.self) {
|
|
||||||
entityManager.remove(entity)
|
|
||||||
for child in self.children {
|
|
||||||
if(child.name != "fire"){
|
|
||||||
child.alpha = 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
|
if atPoint(touchLocation) == spriteNode && !entityManager.isModal {
|
||||||
spriteNode?.touchesBegan(touches, with: event)
|
spriteNode?.touchesBegan(touches, with: event)
|
||||||
if !entityManager.isModal {
|
if !entityManager.isModal {
|
||||||
@ -80,33 +74,34 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
entityManager.add(Modal(modaltype: .BaseDetails,
|
entityManager.add(Modal(modaltype: .BaseDetails,
|
||||||
base: entity as! Base,
|
base: entity as! Base,
|
||||||
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2)))
|
anchorPoint: CGPoint(x: self.size.width / 2 , y: self.size.height / 2),
|
||||||
|
entityManager: entityManager, gameScene: self))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
guard let touch = touches.first else {
|
guard let touch = touches.first else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let touchLocation = touch.location(in: self)
|
let touchLocation = touch.location(in: self)
|
||||||
|
|
||||||
for child in children {
|
for child in children {
|
||||||
if atPoint(touchLocation) == child {
|
if atPoint(touchLocation) == child {
|
||||||
child.touchesMoved(touches, with: event)
|
child.touchesMoved(touches, with: event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for e in entityManager.entities{
|
for e in entityManager.entities{
|
||||||
if let body = e.component(ofType: ModalContentComponent.self)?.body{
|
if let body = e.component(ofType: ModalContentComponent.self)?.body{
|
||||||
body.text = "Schicke \( ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)) Einheiten "
|
body.text = "Schicke \( ((e.component(ofType: SliderComponent.self)?.sliderNode.getValue ?? 0) * CGFloat((e as! Modal).unitCount)).rounded(.up)) Einheiten "
|
||||||
} }
|
} }
|
||||||
|
|
||||||
let bases = entityManager.getBasesByTeam(for: .team1)
|
let bases = entityManager.getBasesByPlayer(for: GKLocalPlayer.local)
|
||||||
|
|
||||||
for base in bases {
|
for base in bases {
|
||||||
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{
|
if atPoint(touchLocation) == base.component(ofType: DefaultBaseComponent.self)?.spriteNode{
|
||||||
if !isMoveTouch {
|
if !isMoveTouch {
|
||||||
@ -114,7 +109,7 @@ class GameScene: SKScene{
|
|||||||
currentDraggedBase = base
|
currentDraggedBase = base
|
||||||
}
|
}
|
||||||
isMoveTouch = true
|
isMoveTouch = true
|
||||||
|
|
||||||
base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation
|
base.component(ofType: DefaultBaseComponent.self)?.spriteNode.position = touchLocation
|
||||||
base.component(ofType: TeamComponent.self)?.fire.position = touchLocation
|
base.component(ofType: TeamComponent.self)?.fire.position = touchLocation
|
||||||
for adjacencyBase in base.adjacencyList {
|
for adjacencyBase in base.adjacencyList {
|
||||||
|
Loading…
Reference in New Issue
Block a user