private void Start() { CountdownState countDownState = new CountdownState(); State game = new TriggeringLambdaState <Trigger>( name: "game", onStateEnter: () => { GameManager.Instance.ShowScoreUI(); GameManager.Instance.RestartGame(); return(null); }); State scoreScreen = new LambdaState( name: "score screen", onStateEnter: () => { int score = GameManager.Instance.Score; GameManager.Instance.HideScoreUI(); GameManager.Instance.Reset(); GameManager.Instance.gameObject.SetActive(false); this.scoreScreen.SetScore(score); this.scoreScreen.gameObject.SetActive(true); }); countDownState.Text = scoreText; sm.AddEntryState(countDownState); sm.AddState(game); sm.AddState(scoreScreen); sm.AddTransition(countDownState, game, sm.CreateTriggerCondition(Trigger.NextState)); sm.AddTransition(game, scoreScreen, sm.CreateTriggerCondition(Trigger.NextState)); sm.Start(); }
private void Start() { //GameState gameState = new GameState(); stateMachine = new StateMachine <StateBool, StateTrigger>(); stateMachine.AddEntryState(menuState.State); stateMachine.Start(); }
private void ConstructStateMachine() { sm = new StateMachine <GameBool, GameTrigger>(verbose: false); GenerateLevelState generateLevelState = new GenerateLevelState(blackBoard); ReadGameFlowState readGameFlowState = new ReadGameFlowState(blackBoard); InstructionState instructionState = new InstructionState(blackBoard); LevelBeatenState levelBeatenState = new LevelBeatenState(blackBoard); CountDownState countDownState = new CountDownState(blackBoard); GameOverState gameOverState = new GameOverState(blackBoard); EndGameState endGameState = new EndGameState(blackBoard); LoadingState loadingState = new LoadingState(blackBoard); ConfigState configState = new ConfigState(blackBoard); DeathState deathState = new DeathState(blackBoard); MenuState menuState = new MenuState(blackBoard); PlayState playState = new PlayState(blackBoard); EmptyState emptyState = new EmptyState(); sm.AddEntryState(emptyState); sm.AddState(generateLevelState); sm.AddState(readGameFlowState); sm.AddState(instructionState); sm.AddState(levelBeatenState); sm.AddState(countDownState); sm.AddState(gameOverState); sm.AddState(endGameState); sm.AddState(loadingState); sm.AddState(configState); sm.AddState(deathState); sm.AddState(menuState); sm.AddState(playState); // start by going to the loading sm.AddTransition( emptyState, loadingState, sm.CreateTriggerCondition(GameTrigger.NextState)); // loading state always goes to the menu state sm.AddTransition( loadingState, menuState, sm.CreateTriggerCondition(GameTrigger.NextState)); // menu to config sm.AddTransition( menuState, configState, sm.CreateTriggerCondition(GameTrigger.GotoConfig)); // config back to menu sm.AddTransition( configState, menuState, sm.CreateTriggerCondition(GameTrigger.GotoMainMenu)); // menu straight to game if the player has already seen the instructions sm.AddTransition( menuState, readGameFlowState, sm.CreateTriggerCondition(GameTrigger.GotoGame), sm.CreateBoolCondition(GameBool.HasSeenInstructions, true)); // menu to instructions sm.AddTransition( menuState, instructionState, sm.CreateTriggerCondition(GameTrigger.GotoGame), sm.CreateBoolCondition(GameBool.HasSeenInstructions, false)); // instruction to start game state sm.AddTransition( instructionState, readGameFlowState, sm.CreateTriggerCondition(GameTrigger.NextState)); // reading game to config to set up variables sm.AddTransition( readGameFlowState, configState, sm.CreateTriggerCondition(GameTrigger.SetUpConfig)); // config back to read game flow sm.AddTransition( configState, readGameFlowState, sm.CreateTriggerCondition(GameTrigger.NextState)); // reading game to generating a level sm.AddTransition( readGameFlowState, generateLevelState, sm.CreateTriggerCondition(GameTrigger.GotoGame)); // on generation fail, go back to main menu sm.AddTransition( generateLevelState, menuState, sm.CreateTriggerCondition(GameTrigger.GotoMainMenu)); // generating game to countdown sm.AddTransition( generateLevelState, countDownState, sm.CreateTriggerCondition(GameTrigger.NextState)); // countdown to play state sm.AddTransition( countDownState, playState, sm.CreateTriggerCondition(GameTrigger.NextState)); // play state to death sm.AddTransition( playState, deathState, sm.CreateTriggerCondition(GameTrigger.PlayerDied)); // death back to generating level sm.AddTransition( deathState, generateLevelState, sm.CreateTriggerCondition(GameTrigger.NextState)); // death state back to main menu sm.AddTransition( deathState, menuState, sm.CreateTriggerCondition(GameTrigger.GotoMainMenu)); // play to level beaten sm.AddTransition( playState, levelBeatenState, sm.CreateTriggerCondition(GameTrigger.PlayerWon)); // level beating to replay sm.AddTransition( levelBeatenState, generateLevelState, sm.CreateTriggerCondition(GameTrigger.ReplayLevel)); // level beaten back to read game flow to figure out what is next sm.AddTransition( levelBeatenState, readGameFlowState, sm.CreateTriggerCondition(GameTrigger.NextState)); // level beaten back to the main menu sm.AddTransition( levelBeatenState, menuState, sm.CreateTriggerCondition(GameTrigger.GotoMainMenu)); // game is over since read game flow state can't find anything else sm.AddTransition( readGameFlowState, gameOverState, sm.CreateTriggerCondition(GameTrigger.GotoGameOver)); // in the game over state, the only option is to go back to the main menu sm.AddTransition( gameOverState, menuState, sm.CreateTriggerCondition(GameTrigger.GotoMainMenu)); }