Ejemplo n.º 1
0
        public void Parse()
        {
            XElement root = XElement.Load(fileName);

            IEnumerable <XElement> terrain     = from el in root.Elements(GenericParser.terrainString) select el;
            IEnumerable <XElement> collectable = from el in root.Elements(GenericParser.collectableString) select el;
            IEnumerable <XElement> item        = from el in root.Elements(GenericParser.itemString) select el;
            IEnumerable <XElement> enemy       = from el in root.Elements(GenericParser.enemyString) select el;
            IEnumerable <XElement> character   = from el in root.Elements(GenericParser.characterString) select el;
            IEnumerable <XElement> camera      = from el in root.Elements(GenericParser.cameraString) select el;
            IEnumerable <XElement> properties  = from el in root.Elements(GenericParser.propertiesString) select el;
            IEnumerable <XElement> itemSets    = from el in root.Elements(GenericParser.itemSetString) select el;

            IEnumerable <XElement> terrains         = terrain.Elements <XElement>();
            IEnumerable <XElement> collectables     = collectable.Elements <XElement>();
            IEnumerable <XElement> items            = item.Elements <XElement>();
            IEnumerable <XElement> enemies          = enemy.Elements <XElement>();
            IEnumerable <XElement> characters       = character.Elements <XElement>();
            IEnumerable <XElement> cameras          = camera.Elements <XElement>();
            IEnumerable <XElement> propertyElements = properties.Elements <XElement>();
            IEnumerable <XElement> itemSetsElements = itemSets.Elements <XElement>();

            ICollectableParser collectableParser = new ICollectableParser();

            collectableParser.Parse(collectables);
            CollectablesList = collectableParser.CollectablesList;

            IItemParser itemParser = new IItemParser();

            itemParser.Parse(items);
            ItemsList = itemParser.ItemList;

            IEnemyParser enemyParser = new IEnemyParser();

            enemyParser.Parse(enemies);
            EnemiesList = enemyParser.EnemiesList;

            CharacterParser characterParser = new CharacterParser();

            characterParser.Parse(characters, controllers);
            CharactersList = characterParser.CharacterList;

            CameraParser cameraParser = new CameraParser();

            cameraParser.Parse(cameras, CharactersList);
            CamerasList = cameraParser.CameraList;

            ItemSetParser itemSetParser = new ItemSetParser();

            itemSetParser.Parse(itemSetsElements, controllers);
            ItemSetList = itemSetParser.ItemSetList;

            TerrainParser terrainParser = new TerrainParser();

            terrainParser.Parse(terrains);
            TerrainList = terrainParser.TerrainList;

            PropertiesParser propertiesParser = new PropertiesParser();

            propertiesParser.Parse(propertyElements);
            Music      = propertiesParser.Music;
            Background = propertiesParser.Background;
        }
Ejemplo n.º 2
0
        private void ParseIReceivers(List <IReceiver> receivers, IEnumerable <XElement> receiver, List <IController> controllers)
        {
            IEnumerable <XElement> charactersSenderList   = from el in receiver.Elements() where IsCharacter(el) select el;
            IEnumerable <XElement> terrainsSenderList     = from el in receiver.Elements() where IsTerrain(el) select el;
            IEnumerable <XElement> collectablesSenderList = from el in receiver.Elements() where IsCollectable(el) select el;
            IEnumerable <XElement> itemsSenderList        = from el in receiver.Elements() where IsItem(el) select el;
            IEnumerable <XElement> enemiesSenderList      = from el in receiver.Elements() where IsEnemy(el) select el;

            List <AbstractCharacter> characterSenderList   = new List <AbstractCharacter>();
            List <AbstractTerrain>   terrainSenderList     = new List <AbstractTerrain>();
            List <ICollectable>      collectableSenderList = new List <ICollectable>();
            List <IItem>             itemSenderList        = new List <IItem>();
            List <IEnemy>            enemySenderList       = new List <IEnemy>();

            CharacterParser characterParser = new CharacterParser();

            characterParser.Parse(charactersSenderList, controllers);
            characterSenderList = characterParser.CharacterList;

            TerrainParser terrainParser = new TerrainParser();

            terrainParser.Parse(terrainsSenderList);
            terrainSenderList = terrainParser.TerrainList;

            ICollectableParser collectableParser = new ICollectableParser();

            collectableParser.Parse(collectablesSenderList);
            collectableSenderList = collectableParser.CollectablesList;

            IItemParser itemParser = new IItemParser();

            itemParser.Parse(itemsSenderList);
            itemSenderList = itemParser.ItemList;

            IEnemyParser enemyParser = new IEnemyParser();

            enemyParser.Parse(enemiesSenderList);
            enemySenderList = enemyParser.EnemiesList;

            foreach (AbstractCharacter c in characterSenderList)
            {
                receivers.Add(c);
            }

            foreach (AbstractTerrain t in terrainSenderList)
            {
                receivers.Add(t);
            }

            foreach (ICollectable i in collectableSenderList)
            {
                receivers.Add(i);
            }

            foreach (IItem i in itemSenderList)
            {
                receivers.Add(i);
            }

            foreach (IEnemy i in enemySenderList)
            {
                receivers.Add(i);
            }
        }