Example #1
0
        public void Load_Level(LevelManagerLoadTypes levelLoadType)
        {
            TimerGenerator.RemoveAllTimerEvents();

            Init_Properties();

            lev = LevelManager.Instance.LoadLevel(levelLoadType);

            lev.MarioObject.OnMarioDied += (() => Load_Level(LevelManagerLoadTypes.RELOAD));

            lev.MarioObject.x = 20;
            lev.MarioObject.y = LevelGenerator.LevelHeight - 16 * 1 - lev.MarioObject.height;
            LevelGenerator.CurrentLevel.Update_ScreensX();
            LevelGenerator.CurrentLevel.Update_ScreensY();

            LevelBeginTime = DateTime.Now;

            Invalidate();
        }
Example #2
0
        public Level LoadLevel(LevelManagerLoadTypes levelLoadType)
        {
            if (LevelFilePaths.Count == 0)
            {
                MessageBox.Show("No levels are configured in the levels file.", "No levels configured.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(null);
            }

            switch (levelLoadType)
            {
            case LevelManagerLoadTypes.FIRST:
            {
                CurrentLevelIndex = 0;
                break;
            }

            case LevelManagerLoadTypes.NEXT:
            {
                CurrentLevelIndex++;
                if (CurrentLevelIndex < 0)
                {
                    CurrentLevelIndex = 0;
                }
                if (CurrentLevelIndex >= LevelFilePaths.Count)
                {
                    CurrentLevelIndex = LevelFilePaths.Count - 1;
                    if (MessageBox.Show("The highest level was reached. Do you want to start from the first level again (Yes)? Otherwise the current level is repeated.", "Highest level reached.", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        CurrentLevelIndex = 0;
                    }
                }
                break;
            }

            case LevelManagerLoadTypes.STARTUP:
            case LevelManagerLoadTypes.RELOAD:
            {
                if (CurrentLevelIndex < 0)
                {
                    CurrentLevelIndex = 0;
                }
                if (CurrentLevelIndex >= LevelFilePaths.Count)
                {
                    CurrentLevelIndex = LevelFilePaths.Count - 1;
                }
                break;
            }
            }

            if (levelLoadType == LevelManagerLoadTypes.RELOAD)
            {
                MarioLives--;
                if (MarioLives == 0)
                {
                    MessageBox.Show("You are out of lives. You start from the first level again.", "Out of lives.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    CurrentLevelIndex = 0;
                    MarioLives        = 500;
                }
            }

            return(MarioEditorXML.Load_Level_From_XML(LevelFilePaths[CurrentLevelIndex]));
        }