Made first states and initialized them

This commit is contained in:
Chauntalle Schüle 2020-05-28 21:27:32 +02:00
parent fbc6a63232
commit 6b602e6af2
3 changed files with 74 additions and 6 deletions

View File

@ -404,6 +404,7 @@
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 */,
AE6BB1C0248030720063ECAE /* States.swift in Sources */,
9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */, 9EEDE02D246FCD770096C735 /* SpinningLogoEntity.swift in Sources */,
9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */, 9E174C86245DD91500209FF0 /* ButtonComponent.swift in Sources */,
11036113244B3E30008610AF /* MenuScene.swift in Sources */, 11036113244B3E30008610AF /* MenuScene.swift in Sources */,
@ -589,8 +590,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 +602,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 +613,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 +625,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

@ -12,9 +12,15 @@ import GameplayKit
class GameViewController: UIViewController { class GameViewController: UIViewController {
var stateMachine: GKStateMachine?
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
createStates()
failedEnteringStates()
self.stateMachine?.enter(MenuState.self)
if let view = self.view as! SKView? { if let view = self.view as! SKView? {
let scene = MenuScene(size: self.view.bounds.size) let scene = MenuScene(size: self.view.bounds.size)
EntityManager.menuEMInstance.setScene(scene: scene) EntityManager.menuEMInstance.setScene(scene: scene)
@ -43,4 +49,24 @@ class GameViewController: UIViewController {
override var prefersStatusBarHidden: Bool { override var prefersStatusBarHidden: Bool {
return true return true
} }
func createStates(){
let menuSt = MenuState()
let syncingSt = SyncingState()
let playingSt = GameState()
stateMachine = GKStateMachine(states: [menuSt, syncingSt, playingSt])
}
func failedEnteringStates(){
if stateMachine?.enter(MenuState.self) == false {
print("failed to enter MenuState")
}
if stateMachine?.enter(SyncingState.self) == false {
print("failed to enter Syncing")
}
if stateMachine?.enter(GameState.self) == false {
print("failed to enter Game")
}
}
} }

View File

@ -0,0 +1,41 @@
//
// States.swift
// GoldWars
//
// Created by Chauntalle Schüle on 28.05.20.
// Copyright © 2020 SP2. All rights reserved.
//
import GameKit
class MenuState: GKState {
override func isValidNextState(_ stateClass: AnyClass) -> Bool {
return stateClass is SyncingState.Type
}
override func didEnter(from previousState: GKState?) {
print("Entered MenuState")
}
}
class SyncingState: GKState {
override func isValidNextState(_ stateClass: AnyClass) -> Bool {
return stateClass is GameState.Type
}
override func didEnter(from previousState: GKState?) {
print("Entered Syncing State")
}
}
class GameState: GKState {
override func isValidNextState(_ stateClass: AnyClass) -> Bool {
return stateClass is SyncingState.Type
}
override func didEnter(from previousState: GKState?) {
print("Entered Game State")
}
}