Compare commits
24 Commits
developmen
...
61-gkstate
Author | SHA1 | Date | |
---|---|---|---|
|
7050fd1b8f | ||
|
74a7df551c | ||
|
9ec6a252ee | ||
|
aee6ec1ac1 | ||
|
9eb06b54fd | ||
|
c5867f12e3 | ||
|
c4a4a8f755 | ||
|
35ff2208fb | ||
|
079ae4a6f6 | ||
|
b23071bb08 | ||
|
f4847e79d7 | ||
|
3ea48c399e | ||
|
0492ab7724 | ||
|
78c5016576 | ||
|
8537dee231 | ||
|
0296edb080 | ||
|
6be5325d86 | ||
|
ce2d847393 | ||
|
50fa1b6cc6 | ||
|
f008ecafa7 | ||
|
d7d17dba2b | ||
|
3bbae779af | ||
|
767548cb82 | ||
|
6b602e6af2 |
@ -46,6 +46,11 @@
|
|||||||
AB21D7D5246C748A00B09CBA /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB21D7D4246C748A00B09CBA /* MapFactory.swift */; };
|
AB21D7D5246C748A00B09CBA /* MapFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB21D7D4246C748A00B09CBA /* MapFactory.swift */; };
|
||||||
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; };
|
ABA03DA0244BD54F00A66916 /* Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABA03D9F244BD54F00A66916 /* Base.swift */; };
|
||||||
ABC0C3732481509300387B8F /* MapUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC0C3722481509300387B8F /* MapUtils.swift */; };
|
ABC0C3732481509300387B8F /* MapUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = ABC0C3722481509300387B8F /* MapUtils.swift */; };
|
||||||
|
AE57F11D248713D7003F0802 /* StateManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE57F118248713D7003F0802 /* StateManager.swift */; };
|
||||||
|
AE57F11E248713D7003F0802 /* SyncingState.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE57F119248713D7003F0802 /* SyncingState.swift */; };
|
||||||
|
AE57F11F248713D7003F0802 /* EndGameState.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE57F11A248713D7003F0802 /* EndGameState.swift */; };
|
||||||
|
AE57F120248713D7003F0802 /* GameState.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE57F11B248713D7003F0802 /* GameState.swift */; };
|
||||||
|
AE57F121248713D7003F0802 /* MenuState.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE57F11C248713D7003F0802 /* MenuState.swift */; };
|
||||||
C04783EE2468583F004961FB /* intro-music.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = C04783ED2468583F004961FB /* intro-music.mp3 */; };
|
C04783EE2468583F004961FB /* intro-music.mp3 in Resources */ = {isa = PBXBuildFile; fileRef = C04783ED2468583F004961FB /* intro-music.mp3 */; };
|
||||||
C04783F024685995004961FB /* SettingsScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04783EF24685995004961FB /* SettingsScene.swift */; };
|
C04783F024685995004961FB /* SettingsScene.swift in Sources */ = {isa = PBXBuildFile; fileRef = C04783EF24685995004961FB /* SettingsScene.swift */; };
|
||||||
C05BB9C4247D890C00411249 /* SliderComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05BB9C3247D890C00411249 /* SliderComponent.swift */; };
|
C05BB9C4247D890C00411249 /* SliderComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = C05BB9C3247D890C00411249 /* SliderComponent.swift */; };
|
||||||
@ -111,6 +116,11 @@
|
|||||||
AB21D7D4246C748A00B09CBA /* MapFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapFactory.swift; sourceTree = "<group>"; };
|
AB21D7D4246C748A00B09CBA /* 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>"; };
|
||||||
ABC0C3722481509300387B8F /* MapUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapUtils.swift; sourceTree = "<group>"; };
|
ABC0C3722481509300387B8F /* MapUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapUtils.swift; sourceTree = "<group>"; };
|
||||||
|
AE57F118248713D7003F0802 /* StateManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StateManager.swift; sourceTree = "<group>"; };
|
||||||
|
AE57F119248713D7003F0802 /* SyncingState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SyncingState.swift; sourceTree = "<group>"; };
|
||||||
|
AE57F11A248713D7003F0802 /* EndGameState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EndGameState.swift; sourceTree = "<group>"; };
|
||||||
|
AE57F11B248713D7003F0802 /* GameState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GameState.swift; sourceTree = "<group>"; };
|
||||||
|
AE57F11C248713D7003F0802 /* MenuState.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuState.swift; sourceTree = "<group>"; };
|
||||||
C04783ED2468583F004961FB /* intro-music.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = "intro-music.mp3"; sourceTree = "<group>"; };
|
C04783ED2468583F004961FB /* intro-music.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = "intro-music.mp3"; sourceTree = "<group>"; };
|
||||||
C04783EF24685995004961FB /* SettingsScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScene.swift; sourceTree = "<group>"; };
|
C04783EF24685995004961FB /* SettingsScene.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsScene.swift; sourceTree = "<group>"; };
|
||||||
C05BB9C3247D890C00411249 /* SliderComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderComponent.swift; sourceTree = "<group>"; };
|
C05BB9C3247D890C00411249 /* SliderComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SliderComponent.swift; sourceTree = "<group>"; };
|
||||||
@ -162,6 +172,7 @@
|
|||||||
110360D1244B101A008610AF /* GoldWars */ = {
|
110360D1244B101A008610AF /* GoldWars */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
AE6BB1CB2481941D0063ECAE /* States */,
|
||||||
C04783ED2468583F004961FB /* intro-music.mp3 */,
|
C04783ED2468583F004961FB /* intro-music.mp3 */,
|
||||||
9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */,
|
9ECD3699245C91F7008DEEBD /* GoldWars.entitlements */,
|
||||||
9E11FF74245CD79100EED3BE /* Partikels */,
|
9E11FF74245CD79100EED3BE /* Partikels */,
|
||||||
@ -286,6 +297,18 @@
|
|||||||
path = Map;
|
path = Map;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
AE6BB1CB2481941D0063ECAE /* States */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
AE57F11A248713D7003F0802 /* EndGameState.swift */,
|
||||||
|
AE57F11B248713D7003F0802 /* GameState.swift */,
|
||||||
|
AE57F11C248713D7003F0802 /* MenuState.swift */,
|
||||||
|
AE57F118248713D7003F0802 /* StateManager.swift */,
|
||||||
|
AE57F119248713D7003F0802 /* SyncingState.swift */,
|
||||||
|
);
|
||||||
|
path = States;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
/* End PBXGroup section */
|
/* End PBXGroup section */
|
||||||
|
|
||||||
/* Begin PBXNativeTarget section */
|
/* Begin PBXNativeTarget section */
|
||||||
@ -404,7 +427,11 @@
|
|||||||
9E174C88245DF1FF00209FF0 /* BackgroundComponent.swift in Sources */,
|
9E174C88245DF1FF00209FF0 /* BackgroundComponent.swift in Sources */,
|
||||||
9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */,
|
9E78ACBA245CBDAF00526FF7 /* HUD.swift in Sources */,
|
||||||
9EC2FBA72476B1EC00ABF11F /* PlayerInfoComponent.swift in Sources */,
|
9EC2FBA72476B1EC00ABF11F /* PlayerInfoComponent.swift in Sources */,
|
||||||
|
AE57F11F248713D7003F0802 /* EndGameState.swift in Sources */,
|
||||||
9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */,
|
9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */,
|
||||||
|
AE57F11D248713D7003F0802 /* StateManager.swift in Sources */,
|
||||||
|
AE57F11E248713D7003F0802 /* SyncingState.swift in Sources */,
|
||||||
|
AE57F120248713D7003F0802 /* GameState.swift in Sources */,
|
||||||
9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */,
|
9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */,
|
||||||
11036113244B3E30008610AF /* MenuScene.swift in Sources */,
|
11036113244B3E30008610AF /* MenuScene.swift in Sources */,
|
||||||
C099579C246C5E5C0016AA22 /* DataService.swift in Sources */,
|
C099579C246C5E5C0016AA22 /* DataService.swift in Sources */,
|
||||||
@ -428,6 +455,7 @@
|
|||||||
C05BB9C4247D890C00411249 /* SliderComponent.swift in Sources */,
|
C05BB9C4247D890C00411249 /* SliderComponent.swift in Sources */,
|
||||||
110360D3244B101A008610AF /* AppDelegate.swift in Sources */,
|
110360D3244B101A008610AF /* AppDelegate.swift in Sources */,
|
||||||
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */,
|
9EC86B9F245C88A300796EF3 /* Modal.swift in Sources */,
|
||||||
|
AE57F121248713D7003F0802 /* MenuState.swift in Sources */,
|
||||||
C05FAED62468559D0006AF2E /* SoundManager.swift in Sources */,
|
C05FAED62468559D0006AF2E /* SoundManager.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
@ -589,8 +617,8 @@
|
|||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGN_ENTITLEMENTS = GoldWars/GoldWars.entitlements;
|
CODE_SIGN_ENTITLEMENTS = GoldWars/GoldWars.entitlements;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "iPhone Developer";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Manual;
|
||||||
CURRENT_PROJECT_VERSION = 3;
|
CURRENT_PROJECT_VERSION = 3;
|
||||||
DEVELOPMENT_TEAM = DDKFQG46BQ;
|
DEVELOPMENT_TEAM = DDKFQG46BQ;
|
||||||
INFOPLIST_FILE = GoldWars/Info.plist;
|
INFOPLIST_FILE = GoldWars/Info.plist;
|
||||||
@ -601,7 +629,7 @@
|
|||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = de.hft.stuttgart.ip2.goldwars;
|
PRODUCT_BUNDLE_IDENTIFIER = de.hft.stuttgart.ip2.goldwars;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "Developer Profile";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
TARGETED_DEVICE_FAMILY = 2;
|
TARGETED_DEVICE_FAMILY = 2;
|
||||||
};
|
};
|
||||||
@ -612,8 +640,8 @@
|
|||||||
buildSettings = {
|
buildSettings = {
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||||
CODE_SIGN_ENTITLEMENTS = GoldWars/GoldWars.entitlements;
|
CODE_SIGN_ENTITLEMENTS = GoldWars/GoldWars.entitlements;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "iPhone Developer";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Manual;
|
||||||
CURRENT_PROJECT_VERSION = 3;
|
CURRENT_PROJECT_VERSION = 3;
|
||||||
DEVELOPMENT_TEAM = DDKFQG46BQ;
|
DEVELOPMENT_TEAM = DDKFQG46BQ;
|
||||||
INFOPLIST_FILE = GoldWars/Info.plist;
|
INFOPLIST_FILE = GoldWars/Info.plist;
|
||||||
@ -624,7 +652,7 @@
|
|||||||
MARKETING_VERSION = 1.0;
|
MARKETING_VERSION = 1.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = de.hft.stuttgart.ip2.goldwars;
|
PRODUCT_BUNDLE_IDENTIFIER = de.hft.stuttgart.ip2.goldwars;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "Developer Profile";
|
||||||
SWIFT_VERSION = 5.0;
|
SWIFT_VERSION = 5.0;
|
||||||
TARGETED_DEVICE_FAMILY = 2;
|
TARGETED_DEVICE_FAMILY = 2;
|
||||||
};
|
};
|
||||||
|
@ -147,10 +147,14 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
|
|||||||
os_log("State 2 erhalten", log: LOG, type: .info)
|
os_log("State 2 erhalten", log: LOG, type: .info)
|
||||||
sendStateToPeers(state: State(state: 3))
|
sendStateToPeers(state: State(state: 3))
|
||||||
initIsFinish = true
|
initIsFinish = true
|
||||||
|
print("entered gameSt in case 2 match")
|
||||||
|
StateManager.sharedInstance.stateMachine?.enter(GameState.self)
|
||||||
os_log("Spiel startet", log: LOG, type: .info)
|
os_log("Spiel startet", log: LOG, type: .info)
|
||||||
case 3:
|
case 3:
|
||||||
os_log("State 3 erhalten", log: LOG, type: .info)
|
os_log("State 3 erhalten", log: LOG, type: .info)
|
||||||
initIsFinish = true
|
initIsFinish = true
|
||||||
|
print("entered gameSt in case 3 match")
|
||||||
|
StateManager.sharedInstance.stateMachine?.enter(GameState.self)
|
||||||
os_log("Spiel startet", log: LOG, type: .info)
|
os_log("Spiel startet", log: LOG, type: .info)
|
||||||
case 4:
|
case 4:
|
||||||
os_log("State 4 erhalten, Peer hat verloren", log: LOG, type: .info)
|
os_log("State 4 erhalten, Peer hat verloren", log: LOG, type: .info)
|
||||||
@ -166,11 +170,13 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
|
|||||||
DataService.sharedInstance.addRemotePlayerMoves(playerName: player.displayName, localRoundData: roundData)
|
DataService.sharedInstance.addRemotePlayerMoves(playerName: player.displayName, localRoundData: roundData)
|
||||||
}
|
}
|
||||||
if let snapshotModel = try? jsonDecoder.decode(SnapshotModel.self, from: data) {
|
if let snapshotModel = try? jsonDecoder.decode(SnapshotModel.self, from: data) {
|
||||||
|
StateManager.sharedInstance.stateMachine?.enter(SyncingState.self)
|
||||||
DataService.sharedInstance.snapshotModel = snapshotModel
|
DataService.sharedInstance.snapshotModel = snapshotModel
|
||||||
RoundCalculatorService.sharedInstance.currentRound += 1
|
RoundCalculatorService.sharedInstance.currentRound += 1
|
||||||
entityManager.getHUD()?.setCurrentRound(round: RoundCalculatorService.sharedInstance.currentRound)
|
entityManager.getHUD()?.setCurrentRound(round: RoundCalculatorService.sharedInstance.currentRound)
|
||||||
entityManager.updateSnapshotModel(snapshotModel: snapshotModel)
|
entityManager.updateSnapshotModel(snapshotModel: snapshotModel)
|
||||||
entityManager.getHUD()?.startWithDuration()
|
entityManager.getHUD()?.startWithDuration()
|
||||||
|
StateManager.sharedInstance.stateMachine?.enter(GameState.self)
|
||||||
}
|
}
|
||||||
if let mapModel = try? jsonDecoder.decode(MapGenerationModel.self, from: data) {
|
if let mapModel = try? jsonDecoder.decode(MapGenerationModel.self, from: data) {
|
||||||
os_log("Peer hat Map erhalten", log: LOG, type: .info)
|
os_log("Peer hat Map erhalten", log: LOG, type: .info)
|
||||||
@ -180,10 +186,9 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
|
|||||||
os_log("Map model wurde gesetzt", log: LOG, type: .info)
|
os_log("Map model wurde gesetzt", log: LOG, type: .info)
|
||||||
GameCenterManager.sharedInstance.isMatchStarted = true
|
GameCenterManager.sharedInstance.isMatchStarted = true
|
||||||
self.gameScene = scene
|
self.gameScene = scene
|
||||||
|
StateManager.sharedInstance.gameSc = scene
|
||||||
sendStateToPeers(state: State(state: 2))
|
sendStateToPeers(state: State(state: 2))
|
||||||
os_log("State 2 wurde an Host gesendet", log: LOG, type: .info)
|
os_log("State 2 wurde an Host gesendet", log: LOG, type: .info)
|
||||||
initIsFinish = true
|
|
||||||
os_log("Peer startet Spiel", log: LOG, type: .info)
|
|
||||||
}
|
}
|
||||||
MultiplayerNetwork.sharedInstance.isSending = false
|
MultiplayerNetwork.sharedInstance.isSending = false
|
||||||
}
|
}
|
||||||
@ -192,6 +197,7 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
|
|||||||
self.gameScene = GameScene(size: self.menusc!.size)
|
self.gameScene = GameScene(size: self.menusc!.size)
|
||||||
let mapModel = MapFactory(scene: self.gameScene!, entityManager: entityManager).load()
|
let mapModel = MapFactory(scene: self.gameScene!, entityManager: entityManager).load()
|
||||||
os_log("Map wurde erstellt", log: LOG, type: .info)
|
os_log("Map wurde erstellt", log: LOG, type: .info)
|
||||||
|
StateManager.sharedInstance.gameSc = gameScene
|
||||||
MultiplayerNetwork.sharedInstance.sendMapModelToPlayers(mapModel: mapModel)
|
MultiplayerNetwork.sharedInstance.sendMapModelToPlayers(mapModel: mapModel)
|
||||||
os_log("Map wurde an Peer gesendet", log: LOG, type: .info)
|
os_log("Map wurde an Peer gesendet", log: LOG, type: .info)
|
||||||
DataService.sharedInstance.setSnapshotModel(snapshotModel: entityManager.getSnapshotModel())
|
DataService.sharedInstance.setSnapshotModel(snapshotModel: entityManager.getSnapshotModel())
|
||||||
@ -232,13 +238,16 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
|
|||||||
}
|
}
|
||||||
func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) {
|
func matchmakerViewControllerWasCancelled(_ viewController: GKMatchmakerViewController) {
|
||||||
viewController.dismiss(animated: true, completion: nil)
|
viewController.dismiss(animated: true, completion: nil)
|
||||||
|
StateManager.sharedInstance.stateMachine?.enter(MenuState.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
StateManager.sharedInstance.stateMachine?.enter(MenuState.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) {
|
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) {
|
||||||
|
StateManager.sharedInstance.stateMachine?.enter(SyncingState.self)
|
||||||
viewController.dismiss(animated: true, completion: nil)
|
viewController.dismiss(animated: true, completion: nil)
|
||||||
myMatch = match
|
myMatch = match
|
||||||
if !isMatchStarted && match.expectedPlayerCount == 0 {
|
if !isMatchStarted && match.expectedPlayerCount == 0 {
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
// Copyright © 2020 SP2. All rights reserved.
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
|
||||||
import SpriteKit
|
import SpriteKit
|
||||||
import GameplayKit
|
import GameplayKit
|
||||||
|
|
||||||
@ -14,20 +13,13 @@ class GameViewController: UIViewController {
|
|||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
|
StateManager.sharedInstance.gameVC = self
|
||||||
|
StateManager.sharedInstance.stateMachine?.enter(MenuState.self)
|
||||||
|
|
||||||
if let view = self.view as! SKView? {
|
|
||||||
let scene = MenuScene(size: self.view.bounds.size)
|
|
||||||
EntityManager.menuEMInstance.setScene(scene: scene)
|
|
||||||
scene.scaleMode = .aspectFill
|
|
||||||
view.presentScene(scene)
|
|
||||||
//TODO: create dev profile or remove on delivery
|
|
||||||
view.showsFPS = true
|
|
||||||
view.showsNodeCount = true
|
|
||||||
}
|
|
||||||
GameCenterManager.sharedInstance.viewController = self
|
GameCenterManager.sharedInstance.viewController = self
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override var shouldAutorotate: Bool {
|
override var shouldAutorotate: Bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -23,14 +23,16 @@ class RoundCalculatorService {
|
|||||||
let MAX_ROUNDS = 20
|
let MAX_ROUNDS = 20
|
||||||
var currentRound = 1
|
var currentRound = 1
|
||||||
var isCalculating = false
|
var isCalculating = false
|
||||||
|
|
||||||
var numberOfAttacks = 0
|
var numberOfAttacks = 0
|
||||||
var numberOfOwnUnitMoves = 0
|
var numberOfOwnUnitMoves = 0
|
||||||
|
|
||||||
func calculateRound() {
|
func calculateRound() {
|
||||||
|
StateManager.sharedInstance.stateMachine?.enter(SyncingState.self)
|
||||||
os_log("Started calculating Round", log: RoundCalculatorService.LOG, type: .info)
|
os_log("Started calculating Round", log: RoundCalculatorService.LOG, type: .info)
|
||||||
|
|
||||||
isCalculating = true
|
isCalculating = true
|
||||||
let currentSnapshotModel = DataService.sharedInstance.snapshotModel
|
let currentSnapshotModel = DataService.sharedInstance.snapshotModel
|
||||||
|
|
||||||
var baseSpecificMoves = collectBaseSpecificMoves()
|
var baseSpecificMoves = collectBaseSpecificMoves()
|
||||||
|
|
||||||
// TODO: Refactor to a less complex way
|
// TODO: Refactor to a less complex way
|
||||||
@ -169,6 +171,7 @@ class RoundCalculatorService {
|
|||||||
entityManager.updateSnapshotModel(snapshotModel: currentSnapshotModel!)
|
entityManager.updateSnapshotModel(snapshotModel: currentSnapshotModel!)
|
||||||
entityManager.getHUD()?.startWithDuration()
|
entityManager.getHUD()?.startWithDuration()
|
||||||
os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info)
|
os_log("Finished calculating Round", log: RoundCalculatorService.LOG, type: .info)
|
||||||
|
StateManager.sharedInstance.stateMachine?.enter(GameState.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func collectBaseSpecificMoves() -> [Int: [String: [PlayerMove]]] {
|
func collectBaseSpecificMoves() -> [Int: [String: [PlayerMove]]] {
|
||||||
|
@ -72,7 +72,7 @@ class GameScene: SKScene{
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func update(_ currentTime: TimeInterval) {
|
override func update(_ currentTime: TimeInterval) {
|
||||||
entityManager.getBackground()?.update(deltaTime: currentTime)
|
StateManager.sharedInstance.stateMachine!.update(deltaTime: currentTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
func addBaseDetails(touchLocation: CGPoint, spriteNode: SKNode?, touches: Set<UITouch>, event: UIEvent?, entity: GKEntity){
|
func addBaseDetails(touchLocation: CGPoint, spriteNode: SKNode?, touches: Set<UITouch>, event: UIEvent?, entity: GKEntity){
|
||||||
|
@ -8,12 +8,14 @@
|
|||||||
|
|
||||||
import SpriteKit
|
import SpriteKit
|
||||||
import SceneKit
|
import SceneKit
|
||||||
|
|
||||||
class MenuScene: SKScene {
|
class MenuScene: SKScene {
|
||||||
|
|
||||||
var entityManager = EntityManager.menuEMInstance
|
var entityManager = EntityManager.menuEMInstance
|
||||||
|
|
||||||
override func sceneDidLoad() {
|
override func sceneDidLoad() {
|
||||||
GameCenterManager.sharedInstance.menusc = self
|
GameCenterManager.sharedInstance.menusc = self
|
||||||
|
StateManager.sharedInstance.menuSc = self
|
||||||
entityManager.setScene(scene: self)
|
entityManager.setScene(scene: self)
|
||||||
let midX = self.size.width / 2
|
let midX = self.size.width / 2
|
||||||
let midY = self.size.height / 2
|
let midY = self.size.height / 2
|
||||||
@ -23,12 +25,11 @@ class MenuScene: SKScene {
|
|||||||
position: CGPoint(x: midX, y: midY),
|
position: CGPoint(x: midX, y: midY),
|
||||||
onButtonPress: {
|
onButtonPress: {
|
||||||
if CommandLine.arguments.contains("--no-matchmaking") {
|
if CommandLine.arguments.contains("--no-matchmaking") {
|
||||||
self.loadScene(scene: GameScene(size: self.size))
|
StateManager.sharedInstance.stateMachine?.enter(GameState.self)
|
||||||
SoundManager.sharedInstance.stopMenuMusic()
|
SoundManager.sharedInstance.stopMenuMusic()
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if GameCenterManager.isAuthenticated {
|
if GameCenterManager.isAuthenticated {
|
||||||
GameCenterManager.sharedInstance.presentMatchmaker()
|
GameCenterManager.sharedInstance.presentMatchmaker()
|
||||||
}else {
|
}else {
|
||||||
GameCenterManager.sharedInstance.authUser()
|
GameCenterManager.sharedInstance.authUser()
|
||||||
}
|
}
|
||||||
@ -68,14 +69,7 @@ class MenuScene: SKScene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override func update(_ currentTime: TimeInterval) {
|
override func update(_ currentTime: TimeInterval) {
|
||||||
if entityManager.entities.count != 0 {
|
StateManager.sharedInstance.stateMachine!.update(deltaTime: currentTime)
|
||||||
entityManager.getBackground()!.update(deltaTime: currentTime)
|
|
||||||
entityManager.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterManager.isAuthenticated
|
|
||||||
}
|
|
||||||
|
|
||||||
if GameCenterManager.sharedInstance.initIsFinish {
|
|
||||||
self.loadScene(scene: GameCenterManager.sharedInstance.gameScene!)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
37
GoldWars/GoldWars/States/EndGameState.swift
Normal file
37
GoldWars/GoldWars/States/EndGameState.swift
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
//
|
||||||
|
// EndGameState.swift
|
||||||
|
// GoldWars
|
||||||
|
//
|
||||||
|
// Created by Chauntalle Schüle on 29.05.20.
|
||||||
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import GameKit
|
||||||
|
import os
|
||||||
|
|
||||||
|
class EndGameState: GKState {
|
||||||
|
|
||||||
|
let LOG = OSLog.init(subsystem: "EndGameState", category: "EndGameState")
|
||||||
|
|
||||||
|
override func isValidNextState(_ stateClass: AnyClass) -> Bool {
|
||||||
|
if stateMachine?.currentState is EndGameState && stateClass is EndGameState.Type {
|
||||||
|
os_log("Already in EndGame State", log: LOG, type: .info)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if stateClass is SyncingState.Type || stateClass is GameState.Type {
|
||||||
|
os_log("Failed: Entering SyncingState and GameState after EndGameState is not allowed", log: LOG, type: .info)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return stateClass is MenuState.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
override func update(deltaTime seconds: TimeInterval) {
|
||||||
|
}
|
||||||
|
|
||||||
|
override func didEnter(from previousState: GKState?) {
|
||||||
|
os_log("Entered EndGame State", log: LOG, type: .info)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func willExit(to nextState: GKState) {
|
||||||
|
}
|
||||||
|
}
|
43
GoldWars/GoldWars/States/GameState.swift
Normal file
43
GoldWars/GoldWars/States/GameState.swift
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
//
|
||||||
|
// GameState.swift
|
||||||
|
// GoldWars
|
||||||
|
//
|
||||||
|
// Created by Chauntalle Schüle on 29.05.20.
|
||||||
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import GameKit
|
||||||
|
import os
|
||||||
|
|
||||||
|
class GameState: GKState {
|
||||||
|
|
||||||
|
let LOG = OSLog.init(subsystem: "GameState", category: "GameState")
|
||||||
|
|
||||||
|
override func isValidNextState(_ stateClass: AnyClass) -> Bool {
|
||||||
|
if stateMachine?.currentState is GameState && stateClass is GameState.Type {
|
||||||
|
os_log("Already in Game State", log: LOG, type: .info)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if stateClass is MenuState.Type || stateClass is EndGameState.Type {
|
||||||
|
os_log("Failed: Entering MenuState and EndgameState after GameState is not allowed", log: LOG, type: .info)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return stateClass is SyncingState.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
override func didEnter(from previousState: GKState?) {
|
||||||
|
os_log("Entered Game State", log: LOG, type: .info)
|
||||||
|
if CommandLine.arguments.contains("--no-matchmaking") {
|
||||||
|
StateManager.sharedInstance.menuSc!.loadScene(scene: GameScene(size: StateManager.sharedInstance.menuSc!.size))
|
||||||
|
} else if RoundCalculatorService.sharedInstance.currentRound == 1 {
|
||||||
|
StateManager.sharedInstance.menuSc!.loadScene(scene: StateManager.sharedInstance.gameSc!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override func update(deltaTime seconds: TimeInterval) {
|
||||||
|
EntityManager.gameEMInstance.getBackground()?.update(deltaTime: seconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
override func willExit(to nextState: GKState) {
|
||||||
|
}
|
||||||
|
}
|
57
GoldWars/GoldWars/States/MenuState.swift
Normal file
57
GoldWars/GoldWars/States/MenuState.swift
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
//
|
||||||
|
// MenuState.swift
|
||||||
|
// GoldWars
|
||||||
|
//
|
||||||
|
// Created by Chauntalle Schüle on 29.05.20.
|
||||||
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import GameKit
|
||||||
|
import os
|
||||||
|
|
||||||
|
class MenuState: GKState {
|
||||||
|
|
||||||
|
let LOG = OSLog.init(subsystem: "MenuState", category: "MenuState")
|
||||||
|
|
||||||
|
override func isValidNextState(_ stateClass: AnyClass) -> Bool {
|
||||||
|
if stateMachine?.currentState is MenuState && stateClass is MenuState.Type {
|
||||||
|
os_log("Already in Menu State", log: LOG, type: .info)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if stateClass is EndGameState.Type {
|
||||||
|
os_log("Entering EndGameState after MenuState is not allowed", log: LOG, type: .info)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if CommandLine.arguments.contains("--no-matchmaking") {
|
||||||
|
return stateClass is GameState.Type
|
||||||
|
}
|
||||||
|
return stateClass is SyncingState.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
override func update(deltaTime seconds: TimeInterval) {
|
||||||
|
if EntityManager.menuEMInstance.entities.count != 0 {
|
||||||
|
EntityManager.menuEMInstance.getBackground()!.update(deltaTime: seconds)
|
||||||
|
EntityManager.menuEMInstance.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterManager.isAuthenticated
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override func didEnter(from previousState: GKState?) {
|
||||||
|
os_log("Entered Menu State", log: LOG, type: .info)
|
||||||
|
// UIApplication.shared.windows[0].rootViewController
|
||||||
|
if (previousState == nil){
|
||||||
|
if let view = StateManager.sharedInstance.gameVC!.view as! SKView? {
|
||||||
|
let scene = MenuScene(size: StateManager.sharedInstance.gameVC!.view.bounds.size)
|
||||||
|
EntityManager.menuEMInstance.setScene(scene: scene)
|
||||||
|
scene.scaleMode = .aspectFill
|
||||||
|
view.presentScene(scene)
|
||||||
|
//TODO: create dev profile or remove on delivery
|
||||||
|
view.showsFPS = true
|
||||||
|
view.showsNodeCount = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override func willExit(to nextState: GKState) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
32
GoldWars/GoldWars/States/StateManager.swift
Normal file
32
GoldWars/GoldWars/States/StateManager.swift
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
//
|
||||||
|
// StateManager.swift
|
||||||
|
// GoldWars
|
||||||
|
//
|
||||||
|
// Created by Chauntalle Schüle on 29.05.20.
|
||||||
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import GameKit
|
||||||
|
import os
|
||||||
|
|
||||||
|
class StateManager{
|
||||||
|
|
||||||
|
static let sharedInstance = StateManager()
|
||||||
|
|
||||||
|
var stateMachine: GKStateMachine?
|
||||||
|
|
||||||
|
var menuSc: MenuScene?
|
||||||
|
var gameVC: GameViewController?
|
||||||
|
var gameSc: GameScene?
|
||||||
|
|
||||||
|
let LOG = OSLog.init(subsystem: "StateManager", category: "StateManager")
|
||||||
|
|
||||||
|
init() {
|
||||||
|
let menuState = MenuState()
|
||||||
|
let syncingState = SyncingState()
|
||||||
|
let playingState = GameState()
|
||||||
|
let endGameState = EndGameState()
|
||||||
|
|
||||||
|
stateMachine = GKStateMachine(states: [menuState, syncingState, playingState, endGameState])
|
||||||
|
}
|
||||||
|
}
|
41
GoldWars/GoldWars/States/SyncingState.swift
Normal file
41
GoldWars/GoldWars/States/SyncingState.swift
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
//
|
||||||
|
// SyncingState.swift
|
||||||
|
// GoldWars
|
||||||
|
//
|
||||||
|
// Created by Chauntalle Schüle on 29.05.20.
|
||||||
|
// Copyright © 2020 SP2. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import GameKit
|
||||||
|
import os
|
||||||
|
|
||||||
|
class SyncingState: GKState {
|
||||||
|
|
||||||
|
let LOG = OSLog.init(subsystem: "SyncingState", category: "SyncingState")
|
||||||
|
var previousState: GKState?
|
||||||
|
|
||||||
|
override func isValidNextState(_ stateClass: AnyClass) -> Bool {
|
||||||
|
if stateMachine?.currentState is SyncingState && stateClass is SyncingState.Type {
|
||||||
|
os_log("Already in Syncing State", log: LOG, type: .info)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return stateClass is GameState.Type || stateClass is EndGameState.Type || stateClass is MenuState.Type
|
||||||
|
}
|
||||||
|
|
||||||
|
override func didEnter(from previousState: GKState?) {
|
||||||
|
os_log("Entered Syncing State", log: LOG, type: .info)
|
||||||
|
self.previousState = previousState
|
||||||
|
}
|
||||||
|
|
||||||
|
override func update(deltaTime seconds: TimeInterval) {
|
||||||
|
if previousState is MenuState {
|
||||||
|
if EntityManager.menuEMInstance.entities.count != 0 {
|
||||||
|
EntityManager.menuEMInstance.getBackground()!.update(deltaTime: seconds)
|
||||||
|
EntityManager.menuEMInstance.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterManager.isAuthenticated
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override func willExit(to nextState: GKState) {
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user