Compare commits

...

24 Commits

Author SHA1 Message Date
Chauntalle Schüle
7050fd1b8f last changes 2020-06-03 13:19:56 +02:00
Chauntalle Schüle
74a7df551c Resolve rebase problems 2020-06-03 01:18:17 +02:00
Chauntalle Schüle
9ec6a252ee changes after review 2020-06-03 01:09:06 +02:00
Chauntalle Schüle
aee6ec1ac1 adding bigger changes after review, deleted enum und methods enter&changeState 2020-06-03 01:09:06 +02:00
Chauntalle Schüle
9eb06b54fd made smaller changes after review 2020-06-03 01:07:45 +02:00
Chauntalle Schüle
c5867f12e3 removed unnecessary file 2020-06-03 01:06:34 +02:00
Chauntalle Schüle
c4a4a8f755 deleted comments 2020-06-03 01:06:34 +02:00
Chauntalle Schüle
35ff2208fb found right trigger for syncingSt and gameSt after finishing a Round 2020-06-03 01:03:17 +02:00
Chauntalle Schüle
079ae4a6f6 still halting game when syncing 2020-06-03 01:03:17 +02:00
Chauntalle Schüle
b23071bb08 menuSt, syncSt and gameSt now correctly triggered even in MM, menuSc and gameSc loaded in states, still need to find trigger for syncSt after finishing one timer cycle / round 2020-06-03 01:00:34 +02:00
Chauntalle Schüle
f4847e79d7 update the first three states before trying sth different 2020-06-03 01:00:34 +02:00
Chauntalle Schüle
3ea48c399e added info that you're once again entering the same state you're already in 2020-06-03 00:59:56 +02:00
Chauntalle Schüle
0492ab7724 updated update method of menuState 2020-06-03 00:59:56 +02:00
Chauntalle Schüle
78c5016576 new group states 2020-06-03 00:59:56 +02:00
Chauntalle Schüle
8537dee231 game scene and menu scene are now initialized in states, still need to test for 2 player 2020-06-03 00:59:35 +02:00
Chauntalle Schüle
0296edb080 adding var current- and previousState - set in enterState, adding func changeState 2020-06-03 00:59:35 +02:00
Chauntalle Schüle
6be5325d86 added EndGameState, deleted imports from enum StateTypes 2020-06-03 00:59:35 +02:00
Chauntalle Schüle
ce2d847393 added GameState 2020-06-03 00:58:15 +02:00
Chauntalle Schüle
50fa1b6cc6 just changed name of variable allowedState to wantedState for better understanding and correctness 2020-06-03 00:58:15 +02:00
Chauntalle Schüle
f008ecafa7 added SyncingState 2020-06-03 00:58:15 +02:00
Chauntalle Schüle
d7d17dba2b added MenuState, is initial State 2020-06-03 00:58:15 +02:00
Chauntalle Schüle
3bbae779af added Statemanager with Singleton, used to create and enter states, already with logging if entering state is un/successful 2020-06-03 00:57:49 +02:00
Chauntalle Schüle
767548cb82 bulk update, gonna break it up with new files in following commits 2020-06-03 00:56:37 +02:00
Chauntalle Schüle
6b602e6af2 Made first states and initialized them 2020-06-03 00:55:42 +02:00
12 changed files with 270 additions and 34 deletions

View File

@ -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;
}; };

View File

@ -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 {

View File

@ -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
@ -15,19 +14,12 @@ class GameViewController: UIViewController {
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
if let view = self.view as! SKView? { StateManager.sharedInstance.gameVC = self
let scene = MenuScene(size: self.view.bounds.size) StateManager.sharedInstance.stateMachine?.enter(MenuState.self)
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
} }

View File

@ -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]]] {

View File

@ -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){

View File

@ -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,10 +25,9 @@ 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 {
@ -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!)
} }
} }
}

View 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) {
}
}

View 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) {
}
}

View 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) {
}
}

View 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])
}
}

View 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) {
}
}