예제 #1
0
        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.AddObjects(randgen.Next(3, level + 3));
            //ObjectMgr.AddObjects(randgen.Next(10, 20));

            ThePlayer.Dirty = true;
            Dirty           = true;
        }