Esempio n. 1
0
        public void HandleKeyEvent(string keyValue, string keyAction)
        {
            switch (keyValue)
            {
            case "KEY_PRESS":
                switch (keyAction)
                {
                case "KEY_UP":
                case "KEY_W":
                    if (activePauseButton == 1)
                    {
                        activePauseButton = 0;
                    }

                    break;

                case "KEY_DOWN":
                case "KEY_S":
                    if (activePauseButton == 0)
                    {
                        activePauseButton = 1;
                    }

                    break;

                case "KEY_ENTER":
                    if (activePauseButton == 0)
                    {
                        SpaceTaxiBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.GameStateEvent,
                                this,
                                "CHANGE_STATE",
                                "GAME_RUNNING", ""));
                    }
                    else
                    {
                        GameRunning.GetInstance0();
                        SpaceTaxiBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.GameStateEvent,
                                this,
                                "CHANGE_STATE",
                                "GAME_MAINMENU", ""));
                    }

                    break;
                }

                break;

            case "KEY_RELEASE":
                break;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Switches between the states
        /// </summary>
        /// <param name="stateType">
        /// Takes a gamestate as a argument and switches the activestate
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        public void SwitchState(StateTransformer.GameStateType stateType)
        {
            switch (stateType)
            {
            case StateTransformer.GameStateType.GameRunning:
                ActiveState = GameRunning.GetInstance();
                break;

            case StateTransformer.GameStateType.GamePaused:
                ActiveState = GamePaused.GetInstance();
                break;

            case StateTransformer.GameStateType.MainMenu:
                ActiveState = MainMenu.GetInstance();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(stateType), stateType, null);
            }
        }
Esempio n. 3
0
 /// <summary>
 ///  Creates a instance of GameRunning is there is not one already
 /// </summary>
 /// <returns>
 /// return an instance of GameRunning
 /// </returns>
 public static GameRunning GetInstance()
 {
     return(GameRunning.instance ?? (GameRunning.instance = new GameRunning()));
 }
Esempio n. 4
0
 /// <summary>
 /// This function is used to reset the gamerunning instance.
 /// </summary>
 /// <returns>
 /// Sets gamerunning to null and returns.
 /// </returns>
 public static GameRunning GetInstance0()
 {
     GameRunning.instance = null;
     return(GameRunning.instance);
 }
Esempio n. 5
0
        public void HandleKeyEvent(string keyValue, string keyAction)
        {
            switch (keyValue)
            {
            case "KEY_PRESS":
                switch (keyAction)
                {
                case "KEY_ESCAPE":
                    SpaceTaxiBus.GetBus().RegisterEvent(
                        GameEventFactory <object> .CreateGameEventForAllProcessors(
                            GameEventType.GameStateEvent,
                            this,
                            "CHANGE_STATE",
                            "GAME_PAUSED", ""));
                    break;

                case "KEY_SPACE":
                    GameRunning.GetInstance0();
                    SpaceTaxiBus.GetBus().RegisterEvent(
                        GameEventFactory <object> .CreateGameEventForAllProcessors(
                            GameEventType.GameStateEvent,
                            this,
                            "CHANGE_STATE",
                            "GAME_MAINMENU", ""));

                    break;

                case "KEY_Q":
                    SpaceTaxiBus.GetBus().RegisterEvent(
                        GameEventFactory <object> .CreateGameEventForAllProcessors(
                            GameEventType.WindowEvent,
                            this,
                            "SAVE_SCREENSHOT",
                            "", ""));

                    break;

                case "KEY_UP":
                case "KEY_W":
                    player.ProcessEvent(GameEventType.PlayerEvent,
                                        GameEventFactory <object> .CreateGameEventForAllProcessors(
                                            GameEventType.PlayerEvent, this,
                                            "BOOSTER_UPWARDS",
                                            "", ""));
                    break;

                case "KEY_LEFT":
                case "KEY_A":
                    player.ProcessEvent(GameEventType.PlayerEvent,
                                        GameEventFactory <object> .CreateGameEventForAllProcessors(
                                            GameEventType.PlayerEvent, this,
                                            "BOOSTER_TO_LEFT",
                                            "", ""));
                    break;

                case "KEY_RIGHT":
                case "KEY_D":
                    player.ProcessEvent(GameEventType.PlayerEvent,
                                        GameEventFactory <object> .CreateGameEventForAllProcessors(
                                            GameEventType.PlayerEvent, this,
                                            "BOOSTER_TO_RIGHT",
                                            "", ""));
                    break;
                }

                break;

            case "KEY_RELEASE":
                switch (keyAction)
                {
                case "KEY_LEFT":
                case "KEY_A":
                    player.ProcessEvent(GameEventType.PlayerEvent,
                                        GameEventFactory <object> .CreateGameEventForAllProcessors(
                                            GameEventType.PlayerEvent, this,
                                            "STOP_ACCELERATE_LEFT",
                                            "", ""));

                    break;

                case "KEY_RIGHT":
                case "KEY_D":
                    player.ProcessEvent(GameEventType.PlayerEvent,
                                        GameEventFactory <object> .CreateGameEventForAllProcessors(
                                            GameEventType.PlayerEvent, this,
                                            "STOP_ACCELERATE_RIGHT",
                                            "", ""));

                    break;

                case "KEY_UP":
                case "KEY_W":
                    player.ProcessEvent(GameEventType.PlayerEvent,
                                        GameEventFactory <object> .CreateGameEventForAllProcessors(
                                            GameEventType.PlayerEvent, this,
                                            "STOP_ACCELERATE_UP",
                                            "", ""));

                    break;
                }

                break;
            }
        }