33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
using Code.App.AppStates;
|
|
using Code.StateMachine;
|
|
|
|
namespace Code.App.StateMachine
|
|
{
|
|
public class AppStateMachine : AbstractStateMachine<AppState, AppStateMachineContext>
|
|
{
|
|
public override void Initialize()
|
|
{
|
|
States.Add(AppState.MainMenu, new MainMenuState(StateMachineContext));
|
|
States.Add(AppState.Gameplay, new GameplayState(StateMachineContext));
|
|
States.Add(AppState.GameOver, new GameOverState(StateMachineContext));
|
|
|
|
AllowedStates |= AppState.MainMenu;
|
|
AllowedStates |= AppState.Gameplay;
|
|
}
|
|
|
|
protected override bool CheckTransitionAllowed(AppState nextState) => AllowedStates.HasFlag(nextState);
|
|
protected override void ResetAllowedTransitions() => AllowedStates = 0;
|
|
}
|
|
|
|
public static class AppStateMachineExtensions
|
|
{
|
|
public static AbstractStateMachine<AppState, AppStateMachineContext> AllowStateTransition(
|
|
this AbstractStateMachine<AppState, AppStateMachineContext> appStateMachine, AppState state)
|
|
{
|
|
if (appStateMachine == null) return null;
|
|
|
|
appStateMachine.AllowedStates |= state;
|
|
return appStateMachine;
|
|
}
|
|
}
|
|
} |