static public void StartSavedLevel(int level) { Width = CurrentLevel.Width; Height = CurrentLevel.Height; Random randgen = new Random(); MonsterMgr.ClearMonsters(); MonsterMgr.AddMonsters(randgen.Next(2, level + 3)); ObjectMgr.AddObjectsToMap(randgen.Next(3, level + 13)); ThePlayer.Dirty = true; Dirty = true; }
static public void StartLevel(int level) { CurrentLevel = Levels.Where(p => p.Level == level).SingleOrDefault(); if (CurrentLevel == null) { string msg = $"Failed to Start Level {level}."; Log.Fatal(msg); throw new Exception(msg); //we need to stop here since the game is unplayable if this happens } Width = CurrentLevel.Width; Height = CurrentLevel.Height; Tiles = null; Tiles = new MapTile[CurrentLevel.Height, CurrentLevel.Width]; for (int yPos = 0; yPos < CurrentLevel.Height; yPos++) { //create the Map 2d array data from the current line char by char for (int xPos = 0; xPos < CurrentLevel.Width; xPos++) { //this calculates row * width of row + column (+1 per row [0 indexed] to adjust for spaces at the end of rows from yaml deserialization) int strpos = yPos * CurrentLevel.Width + xPos + (yPos); CreateTile(CurrentLevel.Map[strpos], xPos, yPos); } } Random randgen = new Random(); MonsterMgr.ClearMonsters(); MonsterMgr.AddMonsters(randgen.Next(2, level + 3)); ObjectMgr.AddObjectsToMap(randgen.Next(3, level + 13)); ThePlayer.Dirty = true; Dirty = true; }