Exemple #1
0
    void Internal_TransitionToState(GameStateDefinition gameStateSettings, GameStateParam[] parameters)
    {
        if (gameStateSettings == null)
        {
            Log.Error("[GameStateManager] Trying to transition to a null GameState");
            return;
        }

        _parameters = parameters;

        GameState newGameState = _gameStateFactory.CreateGameState(gameStateSettings);

        newGameState.SetDefinition(gameStateSettings);

        if (newGameState == null)
        {
            Log.Error("[GameStateManager] Failed to create a GameState from gameStateSettings: " + gameStateSettings.GetType()
                      + ". You may have forgot to register it in the factory.");
            return;
        }

        _targetGameState = newGameState;

        if (log)
#pragma warning disable CS0162 // Unreachable code detected
        {
            Log.Info("[GameStateManager] Transitioning from " + GetPrintGameStateName(_currentGameState) + " to " + GetPrintGameStateName(_targetGameState) + "...");
        }
#pragma warning restore CS0162 // Unreachable code detected
        _currentGameState?.BeginExit(_parameters);
    }
Exemple #2
0
    void CreateGameStates()
    {
        GameStateFactory gsf = new GameStateFactory();

        // Create only a SINGLE STATE per state type
        foreach (GAME_STATE_TYPE gs in Enum.GetValues(typeof(GAME_STATE_TYPE)))
        {
            IState <CKGameManager> state = gsf.CreateGameState(gs);
            //stateGraph.AddNode(ref state);
            gameStateMap.Add(gs, state);
        }
    }
Exemple #3
0
        static void Main()
        {
            var state = GameStateFactory.CreateGameState();

            StateEventDispatcher stateEventDispatcher = new StateEventDispatcher();

            stateEventDispatcher.Register(new StateEventHandler());

            GameStartDispatcher gameStartDispatcher = new GameStartDispatcher();

            gameStartDispatcher.Register(new GameStartHandler(stateEventDispatcher));

            GameWonDispatcher gameWonDispatcher = new GameWonDispatcher();

            gameWonDispatcher.Register(new GameWonHandler());

            GameOverDispatcher gameOverDispatcher = new GameOverDispatcher();

            gameOverDispatcher.Register(new GameOverHandler());

            KeyEventDispatcher keyEventDispatcher = new KeyEventDispatcher();

            keyEventDispatcher.Register(new KeyEventHandler(stateEventDispatcher,
                                                            gameWonDispatcher,
                                                            gameOverDispatcher));

            bool stop = false;

            gameStartDispatcher.NotifyAll(state);

            while (!stop)
            {
                var info = Console.ReadKey(true);
                if (info.Key == ConsoleKey.Escape)
                {
                    stop = true;
                }
                else
                {
                    keyEventDispatcher.NotifyAll(new GameKeyEventData {
                        KeyInfo = info, GameState = state
                    });
                }
            }
        }
Exemple #4
0
 private void Start()
 {
     State = GameStateFactory.CreateGameState(Constants);
 }