Exemplo n.º 1
0
        /// <summary>
        /// This function updates the screen state.
        /// </summary>
        /// <param name="gameTime">current game time</param>
        /// <param name="currentKey">current key press</param>
        public void Update(GameTime gameTime, KeyboardState currentKey)
        {
            this.currentKey = currentKey; //initialise current key press

            switch (screenState)
            {
                case ScreenState.Title:
                    title.Update(currentKey);
                    if (title.exit)
                    {
                        title = null;
                        setScreen("MainMenu");
                    }
                    break;

                case ScreenState.MainMenu:
                    mainMenu.Update(currentKey);
                    if (mainMenu.exit)
                    {
                        switch (mainMenu.selection)
                        {
                            case 0:
                                mainMenu = null;
                                setScreen("Difficulty");
                                break;

                            case 1:
                                mainMenu = null;
                                setScreen("Controls");
                                break;

                            case 2:
                                mainMenu = null;
                                setScreen("Title");
                                break;
                        }
                    }
                    break;

                case ScreenState.Difficulty:
                    difficulty.Update(currentKey);
                    if (difficulty.back)
                    {
                        difficulty = null;
                        setScreen("MainMenu");
                    }
                    else if (difficulty.exit)
                    {
                        int setting = difficulty.selection;
                        difficulty = null;
                        setScreen("Gameplay", setting);
                        break;
                    }
                    break;

                case ScreenState.Gameplay:
                    gameplay.Update(gameTime, currentKey);
                    if (gameplay.exit)
                    {
                        if (gameplay.wins)
                        {
                            TimeSpan time = gameplay.TimeCount;
                            gameplay = null;
                            setScreen("Win", time);
                        }
                        else
                        {
                            int score = gameplay.Score;
                            gameplay = null;
                            setScreen("Lose", score);
                        }
                    }
                    break;

                case ScreenState.Lose:
                    lose.Update(currentKey);
                    if (lose.exit)
                    {
                        lose = null;
                        setScreen("MainMenu");
                    }
                    break;

                case ScreenState.Win:
                    win.Update(currentKey);
                    if (win.exit)
                    {
                        win = null;
                        setScreen("MainMenu");
                    }
                    break;

                case ScreenState.Controls:
                    controls.Update(currentKey);
                    if (controls.exit)
                    {
                        controls = null;
                        setScreen("MainMenu");
                    }
                    break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This function sets the screen state.
        /// </summary>
        /// <param name="stateString">state name</param>
        public void setScreen(String stateString)
        {
            switch (stateString)
            {
                case "Title":
                    screenState = ScreenState.Title;
                    title = new Title();
                    title.LoadContent(titleTexture);
                    break;

                case "MainMenu":
                    screenState = ScreenState.MainMenu;
                    mainMenu = new MainMenu();
                    mainMenu.LoadContent(mainMenuTexture, toggleTexture);
                    break;

                case "Difficulty":
                    screenState = ScreenState.Difficulty;
                    difficulty = new Difficulty();
                    difficulty.LoadContent(difficultyTexture, toggleTexture);
                    break;

                case "Controls":
                    screenState = ScreenState.Controls;
                    controls = new Controls();
                    controls.LoadContent(controlsTexture);
                    break;
            }
        }