Exemplo n.º 1
0
        public EditableMap(int side, MouseRectangle mouse, List<Rectangle> tiles, List<string> tileIDs, int windowWidth, int windowHeight, bool XML, EditableSquare[][] grid)
        {
            this.side = side;
            this.mouse = mouse;
            mapGrid = new EditableSquare[side][];

            if (!XML)
            {
                for (int y = 0; y < side; y++)
                {
                    mapGrid[y] = new EditableSquare[side];
                    for (int x = 0; x < side; x++)
                    {
                        //mapGrid[y][x] = new EditableSquare(x * 32, y * 32, 32, 32, tiles[0], mouse, tileIDs[0]);
                        mapGrid[y][x] = new EditableSquare(x * 32, y * 32, 32, 32, tiles[0], mouse, tileIDs[0]);
                    }
                }

            }
            else
            {
                mapGrid = grid;
            }
            options = new TextureHolder[tiles.Count];

            for (int y = 0; y < tiles.Count; y++)
            {
                options[y] = new TextureHolder(windowWidth - 32, y * 32, 32, 32, tiles[y], mouse, tileIDs[y]);
            }
        }
Exemplo n.º 2
0
        public EditableSquare[][] Load(string xmlFile)
        {
            DirectoryInfo d = new DirectoryInfo(Environment.CurrentDirectory);
            while (d.ToString() != "dynasty")
            {
                d = d.Parent;
            }
            string p = d.FullName + @"\GameData\Maps\";
            XmlReader mapReader = XmlReader.Create(p + xmlFile);
            int currentRow = 0;
            int currentCol = 0;

            EditableSquare[][] mapGrid;

            mapReader.ReadToFollowing("map"); //read to the first map element available
            int mapSize = Convert.ToInt32(mapReader.GetAttribute("size"));
            mapGrid = new EditableSquare[mapSize][];
            string tileID;

            for (int x = 0; x < mapSize; x++)
            {
                mapGrid[x] = new EditableSquare[mapSize];
            }
            currentRow = 0;
            currentCol = 0;
            mapReader.ReadToFollowing("tile");
            do
            {
                int length = Convert.ToInt32(mapReader.GetAttribute("length"));
                tileID = mapReader.GetAttribute("terrain");
                int sourceRecIndex = 0;

                for (int x = 0; x < menu.game.tileIDs.Count; x++)
                {
                    if (menu.game.tileIDs[x].Equals(tileID))
                    { sourceRecIndex = x; }
                }

                for (int i = 0; i < length; i++)
                {

                    mapGrid[currentRow][currentCol] = new EditableSquare(currentCol * 32, currentRow * 32, 32, 32, menu.game.tiles[sourceRecIndex], menu.game.mouse, tileID);

                    if (currentCol != mapSize - 1)
                    {
                        currentCol++;
                    }
                    else
                    {
                        currentRow++;
                        currentCol = 0;
                    }
                }
            } while (mapReader.ReadToNextSibling("tile"));

            mapReader.Close();

            return mapGrid;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Mouse passes its texture (if any) to editablesquare that it's given.
 /// Should only be called by editable square.
 /// </summary>
 /// <param name="e"></param>
 public void GiveTexture(EditableSquare e)
 {
     if (sourceRec != defaultRec )
     {
         e.SourceRec = sourceRec;
         e.TileID = tileID;
     }
 }
Exemplo n.º 4
0
        public XMLWrite(string name, EditableSquare[][] map)
        {
            MapName = name; toSave = map;
            int x = 0;

            DirectoryInfo d = new DirectoryInfo(Environment.CurrentDirectory);
            while (d.ToString() != "dynasty")
            {
                d = d.Parent;
            }
            string p = d.FullName + @"\GameData\Maps\";

            d = new DirectoryInfo(p);

            string originalname = name;

            FileInfo[] files = d.GetFiles();
            bool fileExists = false;

            for(int j = 0; j < files.Length; j++)
            {
                if(files[j].Name.Equals(MapName + ".xml"))
                {
                    fileExists = true;
                }
            }

            while(fileExists)
            {
                MapName = originalname + "(" + x + ")";
                x++;
                fileExists = false;
                for (int j = 0; j < files.Length; j++)
                {
                    if (files[j].Name.Equals(MapName + ".xml"))
                    {
                        fileExists = true;
                    }
                }

            }

            XmlWriterSettings mySettings = new XmlWriterSettings();
               mySettings.Indent = true;
            mySettings.IndentChars = ("\t");
            mySettings.NewLineHandling = NewLineHandling.Entitize;
            writer = XmlWriter.Create(p + MapName + ".xml",mySettings);
        }