Exemple #1
0
        public override void Update(GameTime gameTime)
        {
            keyboard = Keyboard.GetState();

            //Force the user to make a selection of difficulty.
            if (!difficultySet)
            {
                //Make the selection here.

                DifficultyMenu();

                //If the user doesn't actually want to play the game, let him go back to the title screen.
                if (CheckKeystroke(Keys.Escape))
                {
                    Sounds.SoundBank.PlayCue("MenuBack");
                    screenEvent.Invoke(this, new EventArgs());
                }
            }
            else if (difficultySet && !nameSet)
            {
                ChooseName();

                if (CheckKeystroke(Keys.Escape))
                {
                    Sounds.SoundBank.PlayCue("MenuBack");
                    screenEvent.Invoke(this, new EventArgs());
                }
            }
            else
            {
                if (!isPaused)
                {
                    //Checks if the stage is none = player has died.
                    if (currentLevel != null && currentLevel.stage == CurrentLevelStage.none)
                    {
                        if (currentLevel != null)
                        {
                            currentLevel = null;
                            Thread.Sleep(1500);
                        }
                    }
                    //If the level is null, this means that the player has died. Present a death screen with retry and exit options.
                    else if (currentLevel == null)
                    {
                        if (CheckKeystroke(Keys.R))
                        {
                            Sounds.SoundBank.PlayCue("MenuHit");
                            if (level == CurrentLevel.level1)
                            {
                                currentLevel = new Level1(content, _game);
                            }
                            else
                                currentLevel = new Level2(content, _game);
                            playerScore = 0;
                        }
                        else if (CheckKeystroke(Keys.Escape))
                        {
                            Sounds.SoundBank.PlayCue("MenuBack");
                            screenEvent.Invoke(this, new EventArgs());
                            playerScore = 0;
                            difficulty = Difficulty.easy;
                            return;
                        }
                    }
                    else
                    {
                        // The player won the level or game, wait for the enter key then continue on.
                        if (currentLevel.stage == CurrentLevelStage.playerWonStage)
                        {
                            if (CheckKeystroke(Keys.Enter))
                            {
                                switch (level)
                                {
                                    case CurrentLevel.level2:
                                        currentLevel = new Level2(content, _game);
                                        break;
                                    case CurrentLevel.level3:
                                        screenEvent.Invoke(this, new EventArgs());
                                        break;
                                    case CurrentLevel.bonusLevel:
                                        break;
                                    default:
                                        break;
                                }
                            }
                        }
                        currentLevel.Update(gameTime);
                    }
                }
                CheckPauseKey(keyboard);
            }

            prevKeyboard = keyboard;
            base.Update(gameTime);
        }
Exemple #2
0
        private void DifficultyMenu()
        {
            if (CheckKeystroke(Keys.Enter))
            {
                Sounds.SoundBank.PlayCue("MenuHit");
                switch (difficulty)
                {
                    case Difficulty.easy :
                        difficulty = Difficulty.easy;
                        break;
                    case Difficulty.normal :
                        difficulty = Difficulty.normal;
                        break;
                    case Difficulty.hard :
                        difficulty = Difficulty.hard;
                        break;
                }
                //InGameScreen.playerScore = 0; // Make sure the score is set to 0 when the player starts a new game.
                difficultySet = true;

                //Sets the current level to 1 and initializes it as the player has chosen a dificulty, we can create the level now.
                currentLevel = new Level1(content, _game);

                //Sets the max ship life in order to draw life correctly for all ships.
                maxShipLife = Level.ship.Life;
            }

            //Change difficulty
            if (CheckKeystroke(Keys.Down) && (int)difficulty < 3)
            {
                Sounds.SoundBank.PlayCue("MenuChoiceChange");
                SetAllRed();
                difficulty += 1;
            }
            else if (CheckKeystroke(Keys.Up) == true && (int)difficulty > 1)
            {
                Sounds.SoundBank.PlayCue("MenuChoiceChange");
                SetAllRed();
                difficulty -= 1;
            }

            //Changes the color of the difficulty currently marked.
            switch (difficulty)
            {
                case Difficulty.easy:
                    easyColor = Color.White;
                    break;
                case Difficulty.normal:
                    normalColor = Color.White;
                    break;
                case Difficulty.hard:
                    hardColor = Color.White;
                    break;
                default:
                    break;
            }
        }
Exemple #3
0
 //Changes the level. Used in cheats.
 public string ChangeLevel()
 {
     if (currentLevel != null)
     {
         switch (level)
         {
             case CurrentLevel.level2:
                 currentLevel = new Level2(content, _game);
                 return "The level was changed to level 2";
             case CurrentLevel.level3:
                 break;
             case CurrentLevel.bonusLevel:
                 break;
             default:
                 break;
         }
     }
     var wrongLevel = (int)level;
     level -= 1;
     return string.Format("There is no level initiated or level {0} does not exist.", wrongLevel); // Currently not used as i have no way to display messages.
 }