using Code.App.AppStates; using Code.StateMachine; namespace Code.App.StateMachine { public class AppStateMachine : AbstractStateMachine { public override void Initialize() { States.Add(AppState.Bootstrap, new BootstrapState(StateMachineContext)); States.Add(AppState.MainMenu, new MainMenuState(StateMachineContext)); States.Add(AppState.Gameplay, new GameplayState(StateMachineContext)); States.Add(AppState.GameOver, new GameOverState(StateMachineContext)); //TODO: Для теста States.Add(AppState.MovementDev, new MovementDevState(StateMachineContext)); AllowedStates |= AppState.MainMenu; AllowedStates |= AppState.Gameplay; AllowedStates |= AppState.MovementDev; CurrentBaseState = States[AppState.Bootstrap]; } protected override bool CheckTransitionAllowed(AppState nextState) => AllowedStates.HasFlag(nextState); protected override void ResetAllowedTransitions() => AllowedStates = 0; } public static class AppStateMachineExtensions { public static AbstractStateMachine AllowStateTransition( this AbstractStateMachine appStateMachine, AppState state) { if (appStateMachine == null) return null; appStateMachine.AllowedStates |= state; return appStateMachine; } } }