public void Load_Level_XML() { List <LevelEditorObject> list = MarioEditorXML.Load_From_XML("lev1.xml"); Mario MTemp = null; foreach (LevelEditorObject le in list) { GraphicObject g = ObjectGenerator.SetEditorObject(le); if (g != null && g.OT != ObjectType.OT_Mario) { lev.AddObject(g); } else if (g.OT == ObjectType.OT_Mario) { MTemp = (Mario)g; } } lev.AddObject(MTemp); for (int i = 0; i < lev.Objects.Count; i++) { if (lev.Objects[i].OT == ObjectType.OT_Mario) { lev.MarioObject = (Mario)lev.Objects[i]; break; } } }
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])); }