Esempio n. 1
0
        public XMLMap(string mappath)
        {
            String xmlSource = ReadMap(mappath);

            XElement xmlItems = XElement.Parse(xmlSource);

            // Set rows and cols for map
            map = new Map();
            MapAttribs(map, xmlItems);

            // Map Static child elements
            mapObjects = new List <MapObject>();

            IEnumerable <XElement> elements = from el in xmlItems.Elements("static")
                                              select el;

            foreach (XElement el in elements)
            {
                StaticMapObject o = new StaticMapObject();
                MapAttribs(o, el);
                mapObjects.Add(o);
            }

            elements = from el in xmlItems.Elements("tile")
                       select el;

            foreach (XElement el in elements)
            {
                TileMapObject o = new TileMapObject();
                MapAttribs(o, el);
                mapObjects.Add(o);
            }
        }
Esempio n. 2
0
        private bool LoadXmlMap()
        {
            // load the correct rows, columns and timer first
            Rows    = XmlMap.MapObject.Rows;
            Columns = XmlMap.MapObject.Columns;
            SetBoardTimeDirectly(XmlMap.MapObject.Time);

            // starting parsing the data
            foreach (MapObject mapObject in XmlMap.MapTileObjects)
            {
                Type   type       = mapObject.GetType();
                String typeString = type.Name;

                Position position = new Position(mapObject.X, mapObject.Y);

                switch (typeString)
                {
                case "StaticMapObject":
                    StaticMapObject staticMapObject = (StaticMapObject)mapObject;

                    switch (staticMapObject.Identifier)
                    {
                    case "monkey":
                        new Monkey().SetBoard(this).SetPosition(position);
                        break;

                    case "door":
                        new Door().SetBoard(this).SetPosition(position);
                        break;

                    case "spike":
                        new Spike().SetBoard(this).SetPosition(position);
                        break;

                    case "spikeceiling":
                        new SpikeCeiling().SetBoard(this).SetPosition(position);
                        break;

                    case "spider":
                        new Spider().SetBoard(this).SetPosition(position);
                        break;

                    case "crab":
                        new Crab().SetBoard(this).SetPosition(position);
                        break;

                    case "octopus":
                        new Octopus().SetBoard(this).SetPosition(position);
                        break;

                    case "tortoise":
                        new Tortoise().SetBoard(this).SetPosition(position);
                        break;

                    case "tortoiseleft":
                        new TortoiseLeft().SetBoard(this).SetPosition(position);
                        break;

                    case "gaga":
                        new Gaga().SetBoard(this).SetPosition(position);
                        break;

                    case "goomba":
                        new Goomba().SetBoard(this).SetPosition(position);
                        break;

                    case "ghost":
                        new Ghost().SetBoard(this).SetPosition(position);
                        break;

                    default:
                        return(false);
                    }

                    break;


                case "TileMapObject":

                    TileMapObject tileMapObject = (TileMapObject)mapObject;

                    switch (tileMapObject.Type)
                    {
                    case "crate":
                        new Crate().SetBoard(this).SetPosition(position);
                        break;

                    case "banana":
                        new Banana().SetBoard(this).SetPosition(position);
                        break;

                    case "mud":
                        new Tile("MudTile" + tileMapObject.Property).SetBoard(this).SetPosition(position);
                        break;

                    case "grass":
                        new Tile("GrassTile" + tileMapObject.Property).SetBoard(this).SetPosition(position);
                        break;

                    default:
                        return(false);
                    }

                    break;
                }
            }

            return(true);
        }