예제 #1
0
        /// <summary>
        /// Handles the key events. For key up, key down and enter.
        /// </summary>
        /// <param name="keyValue">The given key pressed</param>
        /// <param name="keyAction">Registers if a certain button is pressed or released</param>
        public void HandleKeyEvent(string keyValue, string keyAction)
        {
            if (keyAction == "KEY_PRESS")
            {
                switch (keyValue)
                {
                case "KEY_UP":
                    if (activeMenuButton == 0)
                    {
                        activeMenuButton = maxMenuButtons - 1;
                    }
                    else
                    {
                        activeMenuButton -= 1;
                    }

                    break;

                case "KEY_DOWN":
                    if (activeMenuButton == maxMenuButtons - 1)
                    {
                        activeMenuButton = 0;
                    }
                    else
                    {
                        activeMenuButton += 1;
                    }

                    break;

                case "KEY_ENTER":
                    switch (activeMenuButton)
                    {
                    case 0:
                        GameRunning.ResetGameRunning();
                        GameLevels.Levelcount = 0;
                        SpaceBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.GameStateEvent, this, "GAME_RUNNING", "", ""));
                        break;

                    case 1:
                        SpaceBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.GameStateEvent, this, "MAIN_MENU", "", ""));

                        break;

                    default:
                        break;
                    }

                    break;

                default:
                    break;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Handles the key events. Such as the key enter, sets the player back to main menu.
        /// </summary>
        /// <param name="keyValue">The given key pressed</param>
        /// <param name="keyAction">Registers if a certain button is pressed or released</param>
        public void HandleKeyEvent(string keyValue, string keyAction)
        {
            if (keyAction == "KEY_PRESS")
            {
                switch (keyValue)
                {
                case "KEY_UP":
                    if (activeMenuButton == 0)
                    {
                        activeMenuButton = maxMenuButtons - 1;
                    }
                    else
                    {
                        activeMenuButton -= 1;
                    }

                    break;

                case "KEY_DOWN":
                    if (activeMenuButton == maxMenuButtons - 1)
                    {
                        activeMenuButton = 0;
                    }
                    else
                    {
                        activeMenuButton += 1;
                    }

                    break;

                case "KEY_ENTER":
                    switch (activeMenuButton)
                    {
                    case 0:
                        GameRunning.ResetGameRunning();
                        SpaceBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.GameStateEvent, this, "GAME_LEVELS", "", ""));
                        break;

                    case 1:
                        GameRunning.ResetGameRunning();
                        SpaceBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.GameStateEvent, this, "GAME_CONTROLS", "", ""));
                        break;

                    case 2:
                        SpaceBus.GetBus().RegisterEvent(
                            GameEventFactory <object> .CreateGameEventForAllProcessors(
                                GameEventType.WindowEvent, this, "CLOSE_WINDOW", "", ""));
                        break;
                    }

                    break;
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Sets the GameState features and the entities as new.
 /// </summary>
 public void InitializeGameState()
 {
     backGroundImage = new Entity(new StationaryShape(0.0f, 0.0f, 1.0f, 1.0f),
                                  new Image(Path.Combine("Assets", "Images", "GameSpaceBaground.png")));
     gameVictory = new Entity(new StationaryShape(0.0f, 0.2f, 1.1f, 0.65f),
                              new Image(Path.Combine("Assets", "Images", "GameVictory.png")));
     button = new Text("Main Menu", new Vec2F(0.31f, 0.0f), new Vec2F(0.4f, 0.3f));
     button.SetColor(Color.Yellow);
     cash = new Text($"Total Cash: {GameRunning.GetCash()}", new Vec2F(0.31f, 0.1f), new Vec2F(0.4f, 0.3f));
     cash.SetColor(Color.Red);
 }
        /// <summary>
        /// Swicthes state depending on which stateType given by the GameStateType.
        /// </summary>
        /// <param name="stateType">The state to switch to</param>
        private void SwitchState(GameStateType stateType)
        {
            switch (stateType)
            {
            case GameStateType.MainMenu:
                ActiveState = MainMenu.GetInstance();
                ActiveState.InitializeGameState();
                break;

            case GameStateType.Gamelevels:
                ActiveState = GameLevels.GetInstance();
                ActiveState.InitializeGameState();
                break;

            case GameStateType.GameControls:
                ActiveState = GameControls.GetInstance();
                ActiveState.InitializeGameState();
                break;

            case GameStateType.GameRunning:
                ActiveState = GameRunning.GetInstance();
                break;

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

            case GameStateType.GameOver:
                ActiveState = GameOver.GetInstance();
                ActiveState.InitializeGameState();
                break;

            case GameStateType.GameVictory:
                ActiveState = GameVictory.GetInstance();
                ActiveState.InitializeGameState();
                break;
            }
        }
예제 #5
0
 /// <summary>
 /// Resets the Game instance of GameRunning
 /// </summary>
 public static void ResetGameRunning()
 {
     GameRunning.instance = null;
 }
예제 #6
0
 /// <summary>
 ///GetInstance looks if there is any control instance. If it's not the case it returns
 /// new GameControls
 /// </summary>
 /// <returns>Either the game instance or a new if its null</returns>
 public static GameRunning GetInstance()
 {
     return(GameRunning.instance ?? (GameRunning.instance = new GameRunning()));
 }
예제 #7
0
 /// <summary>
 ///GetInstance looks if there is any control instance. If it's not the case it returns
 /// new GameControls
 /// </summary>
 /// <returns>Either the game instance or a new if its null</returns>
 public static void ResetGameInstance()
 {
     GameRunning.instance = new GameRunning();
 }