Ejemplo n.º 1
0
        /// <summary>
        /// Reads the Level specified by the levelNumber
        /// </summary>
        /// <param name="levelNumber">Specifies which Level to read</param>
        /// <returns></returns>
        public Level ReadLevel(int levelNumber)
        {
            StreamReader lvlReader = new StreamReader(@"Level" + levelNumber + ".txt");
            string       line;
            Level        level = new Level();

            line = lvlReader.ReadLine();
            if (line.Contains("Args:") && !line.Contains("//"))
            {
                string[] args;
                line = line.Replace(" ", "");
                args = line.Split(':')[1].Split(',');
                int width       = int.Parse(args[0]) * Global.Instance.GridSize;
                int height      = int.Parse(args[1]) * Global.Instance.GridSize;
                int timerLength = int.Parse(args[2]);
                level = new Level(width, height, timerLength);
            }
            while ((line = lvlReader.ReadLine()) != null)
            {
                if (!string.IsNullOrWhiteSpace(line) && line.Contains(":") && line.Contains(",") && !line.Contains("//"))
                {
                    line = line.Replace(" ", "");
                    try
                    {
                        level.ToAddGameObject(_gameObjectFactory.Fabricate(line.Split(':'), level, _contentManager));
                    }
                    catch (Exception)
                    {
                        throw new FileLoadException("No size detected");
                    }
                }
            }
            lvlReader.Close();
            return(level);
        }
 public void GameObjectFactory_Fabricate()
 {
     string[] args = new string[] { "MysteryBlock", "0,0,Coin" };
     _gameObjectFactory.Fabricate(args, _level, _contentManager);
     bool isTrue = _level.GameObjects.Contains(new MysteryBlock(0, 0, typeof(Coin), _level, _contentManager));
 }