// If the tile already has properties
        public TilePropertiesWindow(int x, int y, int mapWidth, int mapHeight, tile clickedTile, Rectangle clickedRectangle)
        {
            InitializeComponent();

            mainLabel.Content = "Tile [" + x + "," + y + "] Properties";
            textTextBox.Text = clickedTile.properties.text;
            x1TextBox.Text = x.ToString();
            y1TextBox.Text = y.ToString();
            x2TextBox.Text = clickedTile.properties.x2.ToString();
            y2TextBox.Text = clickedTile.properties.y2.ToString();
            sizeTextBox.Text = clickedTile.properties.size.ToString();

            spritePreview.Fill = clickedRectangle.Fill;
            spritePreview.Stroke = clickedRectangle.Stroke;
            spritePreview.StrokeThickness = clickedRectangle.StrokeThickness;

            maxWidth = mapWidth;
            maxHeight = mapHeight;

            orientationSelect.ItemsSource = orientationSources;
            orientationSelect.SelectedIndex = (int)clickedTile.properties.orientation;

            set = false;
            delete = false;
        }
예제 #2
0
        public tileset(string filename)
        {
            StreamReader sr = new StreamReader(filename);
            ArrayList curTiles=absTiles;
            string line;

            do
            {
                line = sr.ReadLine();
                if(line==null)
                    break;

                else if(line.StartsWith("[ABSOLUTE]"))
                    curTiles = absTiles;
                else if(line.StartsWith("[EDGE]"))
                    curTiles = edgeTiles;
                else if(line.StartsWith("[")) // Any other section is not-for-me
                    curTiles = null;
                else if(line.Equals("") || line.StartsWith("#"))
                    continue;
                else
                {

                    string[] parts = regex.Split(line);

                    if(curTiles==null)
                        continue;

                    tile newTile ;
                    newTile = new tile(parts[0], parts[1], parts[2].Equals("1"), parts[3], parts[4], parts[5], parts[6]);

                    curTiles.Add(newTile);
                }
            }
            while(line != null);

            sr.Close();
        }
        // Apply the texture to the tile(s)
        private void setTileTextureApply(object sender, MouseButtonEventArgs e)
        {
            if (canClick == true)
            {
                Rectangle ClickedRectangle = (Rectangle)e.OriginalSource;

                // Get the TAG of the Rectangle (tag contains coordinates)
                String[] coo = ClickedRectangle.Tag.ToString().Split('/');
                int secondTileX = int.Parse(coo.First());
                int secondTileY = int.Parse(coo.Last());

                // Shortly : MouseDown outside of a rectangle and MouseUp on one
                if (firstTileX == -1 && firstTileY == -1)
                {
                    if (globalMap[secondTileX, secondTileY] == null)
                        globalMap[secondTileX, secondTileY] = new tile { collidable = true };

                    // Check if it's a special tile or not
                    if (specialTile != null)
                        ClickedRectangle = setSpecialTile(ClickedRectangle,secondTileX, secondTileY);
                    else
                        ClickedRectangle.Fill = setRectangleSprite(secondTileX, secondTileY, ClickedRectangle);
                }
                else
                {
                    // Define the smallest X and the biggest. Same for Y
                    Tuple<int, int> xLimits;
                    Tuple<int, int> yLimits;

                    if (firstTileX > secondTileX)
                        xLimits = new Tuple<int, int>(secondTileX, firstTileX);
                    else
                        xLimits = new Tuple<int, int>(firstTileX, secondTileX);

                    if (firstTileY > secondTileY)
                        yLimits = new Tuple<int, int>(secondTileY, firstTileY);
                    else
                        yLimits = new Tuple<int, int>(firstTileY, secondTileY);

                    foreach (WrapPanel panelChild in mapGrid.Children)
                    {
                        for (int i = 0; i < panelChild.Children.Count; i++)
                        {
                            // Get the rectangle as we don't use a foreach anymore because of C#
                            Rectangle rectangleChild = (Rectangle)panelChild.Children[i];

                            // Get the TAG of the Rectangle (tag contains coordinates)
                            String[] currentCoo = rectangleChild.Tag.ToString().Split('/');
                            int currentX = int.Parse(currentCoo.First());
                            int currentY = int.Parse(currentCoo.Last());

                            if (currentX >= xLimits.Item1 && currentX <= xLimits.Item2)
                            {
                                if (currentY >= yLimits.Item1 && currentY <= yLimits.Item2)
                                {
                                    if (globalMap[currentX, currentY] == null)
                                        globalMap[currentX, currentY] = new tile { collidable = true };

                                    // Check if it's a special tile or not
                                    if (specialTile != null)
                                        rectangleChild = setSpecialTile(rectangleChild, currentX, currentY);
                                    else
                                        rectangleChild.Fill = setRectangleSprite(currentX, currentY, rectangleChild);
                                }
                            }
                        }
                    }
                }

                firstTileX = -1;
                firstTileY = -1;
                hasBeenModified = true;
            }
        }
예제 #4
0
        public tile mirrorVert(tile t)
        {
            string str = t.name;

            // Try to split this string into a type and direction suffix
            int ii = str.Length-1;
            while(ii>0 && str[ii]==str.ToUpper()[ii])
                ii--;
            if(ii+1 < str.Length) ii++;
            string start = str.Substring(0, ii),
                   suffix = str.Substring(ii, str.Length-ii);

            switch(suffix)
            {
                case "N" : suffix="S";  break;
                case "S" : suffix="N";  break;
                case "NE": suffix="SE"; break;
                case "NW": suffix="SW"; break;
                case "SE": suffix="NE"; break;
                case "SW": suffix="NW"; break;
            }

            tile ret = getTile(start+suffix);
            if(ret != null) return ret;
            else return t;
        }
        // Open an existing JSON saved map
        private void MenuFileNew_Open(object sender, RoutedEventArgs e)
        {
           if (hasBeenModified == true)
            {
                changeExitButton = true;
                editorClosing(this, new System.ComponentModel.CancelEventArgs());
                if (cancelNextAction == true)
                    return;
            }

            canClick = false;

            usedBlockSprites.Clear();
            usedPlayerSprites.Clear();
            usedEnemySprites.Clear();

            System.Windows.Forms.OpenFileDialog openFilePopup = new System.Windows.Forms.OpenFileDialog();
            int newMapWidth, newMapHeight, tileSize = 0;
            string newMapName;

            openFilePopup.DefaultExt = ".json";
            openFilePopup.Filter = "JSON documents (.json)|*.json";
            openFilePopup.Title = "Open a map";
            openFilePopup.ShowDialog();

            if (openFilePopup.FileName != "")
            {
                tile[,] newGlobalMap;

                // Error handling
                try
                {
                    MapInfos loadedMap = JsonConvert.DeserializeObject<MapInfos>(File.ReadAllText(openFilePopup.FileName));

                    // Loading the informations from the deserialized object
                    String[] size = loadedMap.size.Split('/');

                    newMapWidth = int.Parse(size.First());
                    newMapHeight = int.Parse(size.Last());
                    newMapName = loadedMap.name;
                    mapAudioPath = loadedMap.audio;
                    mapBackgroundPath = loadedMap.background;

                    defaultSpriteSheetSize = 0;
                    playerSpriteSheetSize = 0;
                    enemySpriteSheetSize = 0;
                    numberPlayerOnMap = 0;

                    newGlobalMap = new tile[newMapWidth, newMapHeight];

                    // Deciding the size of the rectangles (tiles)
                    tileSize = 32;

                    loadButtonsFromFile();

                    foreach (var list in loadedMap.blockTileList)
                    {
                        var tileIndex = list.Key;
                        var tileList = list.Value;

                        foreach (tile elem in tileList)
                        {
                            tile newTile = new tile();
                            newTile.coordx = elem.coordx;
                            newTile.coordy = elem.coordy;
                            newTile.tileSprite = listSprites[tileIndex];
                            newTile.collidable = elem.collidable;
                            newTile.properties = elem.properties;
                            newTile.spriteType = SpriteType.BLOCK;

                            if (!usedBlockSprites.ContainsKey(tileIndex))
                                usedBlockSprites.Add(tileIndex, listSprites[tileIndex]);
                            else if (usedBlockSprites[tileIndex] != listSprites[tileIndex])
                                usedBlockSprites[tileIndex] = listSprites[tileIndex];

                            newGlobalMap[elem.coordx, elem.coordy] = newTile;
                        }
                    }

                    foreach (var list in loadedMap.playerTileList)
                    {
                        var tileIndex = list.Key;
                        var tileList = list.Value;

                        foreach (tile elem in tileList)
                        {
                            tile newTile = new tile();
                            newTile.coordx = elem.coordx;
                            newTile.coordy = elem.coordy;
                            newTile.tileSprite = listSprites[tileIndex + defaultSpriteSheetSize];
                            newTile.collidable = elem.collidable;
                            newTile.properties = elem.properties;
                            newTile.spriteType = SpriteType.PLAYER;

                            numberPlayerOnMap++;

                            if (!usedPlayerSprites.ContainsKey(tileIndex))
                                usedPlayerSprites.Add(tileIndex, listSprites[tileIndex + defaultSpriteSheetSize]);
                            else if (usedPlayerSprites[tileIndex] != listSprites[tileIndex + defaultSpriteSheetSize])
                                usedPlayerSprites[tileIndex] = listSprites[tileIndex + defaultSpriteSheetSize];

                            newGlobalMap[elem.coordx, elem.coordy] = newTile;
                        }
                    }

                    foreach (var list in loadedMap.enemyTileList)
                    {
                        var tileIndex = list.Key;
                        var tileList = list.Value;

                        foreach (tile elem in tileList)
                        {
                            tile newTile = new tile();
                            newTile.coordx = elem.coordx;
                            newTile.coordy = elem.coordy;
                            newTile.tileSprite = listSprites[tileIndex + defaultSpriteSheetSize + playerSpriteSheetSize];
                            newTile.collidable = elem.collidable;
                            newTile.properties = elem.properties;
                            newTile.spriteType = SpriteType.ENEMY;

                            if (!usedEnemySprites.ContainsKey(tileIndex))
                                usedEnemySprites.Add(tileIndex, listSprites[tileIndex + defaultSpriteSheetSize + playerSpriteSheetSize]);
                            else if (usedEnemySprites[tileIndex] != listSprites[tileIndex + defaultSpriteSheetSize + playerSpriteSheetSize])
                                usedEnemySprites[tileIndex] = listSprites[tileIndex + defaultSpriteSheetSize + playerSpriteSheetSize];

                            newGlobalMap[elem.coordx, elem.coordy] = newTile;
                        }
                    }

                    foreach (tile heatZone in loadedMap.heatZonesList)
                    {
                        if (newGlobalMap[heatZone.coordx, heatZone.coordy] != null)
                            newGlobalMap[heatZone.coordx, heatZone.coordy].heatZone = true;
                        else
                        {
                            tile newTile = new tile();
                            newTile.coordx = heatZone.coordx;
                            newTile.coordy = heatZone.coordy;
                            newTile.heatZone = true;
                            newTile.properties = heatZone.properties;

                            newGlobalMap[heatZone.coordx, heatZone.coordy] = newTile;
                        }

                    }

                    foreach (tile otherTile in loadedMap.otherTileList)
                    {
                        tile newTile = new tile();
                        newTile.coordx = otherTile.coordx;
                        newTile.coordy = otherTile.coordy;
                        newTile.collidable = otherTile.collidable;
                        newTile.properties = otherTile.properties;

                        newGlobalMap[otherTile.coordx, otherTile.coordy] = newTile;
                    }

                }
                catch (Exception)
                {
                    GenericErrorPopup errorPopup = new GenericErrorPopup();

                    tileSelectionPanel.Children.Clear();
                    errorPopup.setErrorMessage("Error opening a map", "The map you're trying to open is corrupted.");
                    errorPopup.Owner = this;
                    errorPopup.ShowDialog();
                    return;
                }

                globalMap = newGlobalMap;
                mapName = newMapName;
                mapHeight = newMapHeight;
                mapWidth = newMapWidth;

                try {
                    // Setting the mapName as the title of the window
                    this.Title = newMapName;
                }
                catch (Exception) { }

                // Clear the potential already existing map
                mapGrid.Children.Clear();

                // Reapply the sprites to the map
                for (int j = 0; j < mapHeight; j++)
                {
                    WrapPanel panel = new WrapPanel();
                    for (int i = 0; i < mapWidth; i++)
                    {
                        panel.Children.Add(new Rectangle { Tag = i + "/" + (mapHeight - 1 - j), Width = tileSize, Height = tileSize, Fill = (Brush)new System.Windows.Media.BrushConverter().ConvertFromString(defaultColor), Stroke = new SolidColorBrush(Colors.Black), Margin = new Thickness(0, 2, 2, 0) });
                    }
                    mapGrid.Children.Add(panel);
                }

                foreach (WrapPanel panelChild in mapGrid.Children)
                {
                    for (int i = 0; i < panelChild.Children.Count; i++)
                    {
                        Rectangle rectangleChild = (Rectangle)panelChild.Children[i];

                        // Get the TAG of the Rectangle (tag contains coordinates)
                        String[] currentCoo = rectangleChild.Tag.ToString().Split('/');
                        int currentX = int.Parse(currentCoo.First());
                        int currentY = int.Parse(currentCoo.Last());

                        if (globalMap[currentX, currentY] != null)
                        {
                            if (globalMap[currentX, currentY].tileSprite != null)
                                rectangleChild.Fill = globalMap[currentX, currentY].tileSprite;
                            if (globalMap[currentX, currentY].collidable == false)
                                rectangleChild = setGivenSpecialTile(rectangleChild, currentX, currentY, SpecialTile.NON_COLLIDABLE);
                            if (globalMap[currentX, currentY].heatZone == true)
                                rectangleChild = setGivenSpecialTile(rectangleChild, currentX, currentY, SpecialTile.HEATZONE);
                            if (globalMap[currentX, currentY].properties != null)
                                if (globalMap[currentX, currentY].properties.isScriptedOrTexted(currentX, currentY) == true)
                                    rectangleChild.Opacity = 0.5;
                        }
                    }
                }

                // Clear existing buttons
                tileSelectionPanel.Children.Clear();

                defaultSpriteSheetSize = 0;
                playerSpriteSheetSize = 0;
                enemySpriteSheetSize = 0;

                loadButtonsFromFile();
                loadSpecialTiles();
                gridSplitter.Visibility = Visibility.Visible;
                selectedSpriteLabel.Visibility = Visibility.Visible;
                audioButton.Visibility = Visibility.Visible;
                backgroundButton.Visibility = Visibility.Visible;
                saveButton.IsEnabled = true;
                lastSavePath = openFilePopup.FileName;
                hasBeenModified = false;

                selectedSprite.Fill = listSprites[0];
                sprite = listSprites[0];
                spriteInt = 0;

                // Thread system to prevent miss clicking while opening a map
                System.Threading.Timer timer = null;
                timer = new System.Threading.Timer((obj) =>
                {
                    canClick = true;
                    timer.Dispose();
                }, null, 500, System.Threading.Timeout.Infinite);

                firstTileX = -1;
                firstTileY = -1;
            }
        }
        // To save a map
        private void MenuFileNew_Save(object sender, RoutedEventArgs e)
        {
            // Popup to select the location of the file
            System.Windows.Forms.SaveFileDialog saveFilePopup = new System.Windows.Forms.SaveFileDialog();

            string savePath;

            if (String.IsNullOrEmpty(lastSavePath))
            {
                saveFilePopup.DefaultExt = ".json";
                saveFilePopup.Filter = "JSON documents (.json)|*.json";
                saveFilePopup.Title = "Save your map";
                saveFilePopup.FileName = removeSpecialCharacters(mapName);
                if (saveFilePopup.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                {
                    cancelExit = true;
                    return;
                }
            }

            if (saveFilePopup.FileName != "" || !String.IsNullOrEmpty(lastSavePath))
            {
                savePath = (saveFilePopup.FileName != "" ? saveFilePopup.FileName : lastSavePath);

                Dictionary<int, List<tile>> sortedBlockTileList = new Dictionary<int, List<tile>>();
                Dictionary<int, List<tile>> sortedPlayerTileList = new Dictionary<int, List<tile>>();
                Dictionary<int, List<tile>> sortedEnemyTileList = new Dictionary<int, List<tile>>();

                List<tile> heatZoneTileList = new List<tile>();
                List<tile> otherTileList = new List<tile>();

                // Handle the saving of heatzones tiles and null with properties tiles
                for (int j = 0; j < mapHeight; j++)
                {
                    for (int i = 0; i < mapWidth; i++)
                    {
                        if (globalMap[i, j] != null)
                        {
                            tile specialTile = new tile { coordx = i, coordy = j, collidable = globalMap[i, j].collidable, properties = globalMap[i, j].properties };

                            if (globalMap[i, j].heatZone == true)
                                heatZoneTileList.Add(specialTile);
                            else
                            {
                                if (globalMap[i, j].properties != null && globalMap[i, j].tileSprite == null)
                                    otherTileList.Add(specialTile);
                            }
                        }
                    }
                }

                // Saving of all the tiles with sprites
                for (int k = 0; k < listSprites.Count; k++)
                {
                    List<tile> blockTileList = new List<tile>();
                    List<tile> playerTileList = new List<tile>();
                    List<tile> enemyTileList = new List<tile>();

                    for (int j = 0; j < mapHeight; j++)
                    {
                        for (int i = 0; i < mapWidth; i++)
                        {
                            if (globalMap[i, j] != null)
                            {
                                if (globalMap[i, j].tileSprite != null)
                                {
                                    if (globalMap[i, j].tileSprite.ImageSource == listSprites[k].ImageSource)
                                    {
                                        if (globalMap[i, j].spriteType == SpriteType.BLOCK)
                                            blockTileList.Add(new tile() { coordx = i, coordy = j, collidable = globalMap[i, j].collidable, properties = globalMap[i, j].properties });
                                        else if (globalMap[i, j].spriteType == SpriteType.PLAYER)
                                            playerTileList.Add(new tile() { coordx = i, coordy = j, collidable = globalMap[i, j].collidable, properties = globalMap[i, j].properties });
                                        else if (globalMap[i, j].spriteType == SpriteType.ENEMY)
                                            enemyTileList.Add(new tile() { coordx = i, coordy = j, collidable = globalMap[i, j].collidable, properties = globalMap[i, j].properties });
                                    }
                                    else
                                    {
                                        if (usedBlockSprites.ContainsKey(k))
                                            if (globalMap[i, j].tileSprite == usedBlockSprites[k])
                                                if (globalMap[i, j].spriteType == SpriteType.BLOCK)
                                                    blockTileList.Add(new tile() { coordx = i, coordy = j, collidable = globalMap[i, j].collidable, properties = globalMap[i, j].properties });
                                        if (usedPlayerSprites.ContainsKey(k - defaultSpriteSheetSize))
                                            if (globalMap[i, j].tileSprite == usedPlayerSprites[k - defaultSpriteSheetSize])
                                                if (globalMap[i, j].spriteType == SpriteType.PLAYER)
                                                    playerTileList.Add(new tile() { coordx = i, coordy = j, collidable = globalMap[i, j].collidable, properties = globalMap[i, j].properties });
                                        if (usedEnemySprites.ContainsKey(k - defaultSpriteSheetSize - playerSpriteSheetSize))
                                            if (globalMap[i, j].tileSprite == usedEnemySprites[k - defaultSpriteSheetSize - playerSpriteSheetSize])
                                                if (globalMap[i, j].spriteType == SpriteType.ENEMY)
                                                    enemyTileList.Add(new tile() { coordx = i, coordy = j, collidable = globalMap[i, j].collidable, properties = globalMap[i, j].properties });
                                    }
                                }
                            }
                        }
                    }

                    if (blockTileList.Count != 0)
                        sortedBlockTileList.Add(k, blockTileList);
                    if (playerTileList.Count != 0)
                        sortedPlayerTileList.Add(k - defaultSpriteSheetSize, playerTileList);
                    if (enemyTileList.Count != 0)
                        sortedEnemyTileList.Add(k - defaultSpriteSheetSize - playerSpriteSheetSize, enemyTileList);
                }

                MapInfos map = new MapInfos();

                map.name = mapName;
                map.size = mapWidth + "/" + mapHeight;
                map.audio = mapAudioPath;
                map.background = mapBackgroundPath;
                map.blockTileList = sortedBlockTileList;
                map.playerTileList = sortedPlayerTileList;
                map.enemyTileList = sortedEnemyTileList;
                map.heatZonesList = heatZoneTileList;
                map.otherTileList = otherTileList;

                string json = JsonConvert.SerializeObject(map, Formatting.Indented);
                File.WriteAllText(savePath, json);

                lastSavePath = savePath;
                hasBeenModified = false;
            }
        }
예제 #7
0
파일: Map.cs 프로젝트: yixu34/RefuseRobots
 public tile_t(tile t, landfill i)
 {
     tile_p = t;
     landf = i;
 }
        // Set the properties of a tile after right cliking it
        private void setTileProperties(object sender, MouseButtonEventArgs e)
        {
            Rectangle ClickedRectangle = (Rectangle)e.OriginalSource;

            int x = 0, y = 0;
            String[] coo = ClickedRectangle.Tag.ToString().Split('/');
            if (coo != null && coo.Length != 0)
            {
                x = int.Parse(coo.First());
                y = int.Parse(coo.Last());
            }

            TileProperties tileProperties = new TileProperties();
            TilePropertiesWindow tilePropertiesWindow;

            if (globalMap[x, y] != null)
            {
                if (globalMap[x, y].properties == null)
                    tilePropertiesWindow = new TilePropertiesWindow(x, y, mapWidth, mapHeight, ClickedRectangle);
                else
                    tilePropertiesWindow = new TilePropertiesWindow(x, y, mapWidth, mapHeight, globalMap[x, y], ClickedRectangle);
            }
            else
            {
                globalMap[x, y] = new tile { coordx = x, coordy = y, collidable = false };
                setGivenSpecialTile(ClickedRectangle, x, y, SpecialTile.NON_COLLIDABLE);
                tilePropertiesWindow = new TilePropertiesWindow(x, y, mapWidth, mapHeight, ClickedRectangle);
            }

            tilePropertiesWindow.Owner = this;
            tilePropertiesWindow.ShowDialog();

            if (tilePropertiesWindow.delete == true)
            {
                globalMap[x, y].properties = null;
                ClickedRectangle.Opacity = 1;
            }

            if (tilePropertiesWindow.set == true)
            {
                globalMap[x, y].properties = tilePropertiesWindow.tileProperties;
                if (globalMap[x, y].properties.isScriptedOrTexted(x, y) == true)
                    ClickedRectangle.Opacity = 0.5;
            }
        }
예제 #9
0
파일: Map.cs 프로젝트: yixu34/RefuseRobots
 public tile_t(tile t)
 {
     tile_p=t;
     landf=null;
 }
예제 #10
0
파일: Map.cs 프로젝트: yixu34/RefuseRobots
 public tile_t(string type)
 {
     tile_p = tiles.getTile(type);
     landf=null;
 }
예제 #11
0
파일: Map.cs 프로젝트: yixu34/RefuseRobots
 public tile_t(tile_t old)
 {
     landf = old.landf;
     tile_p = old.myTile;
 }
예제 #12
0
파일: Map.cs 프로젝트: yixu34/RefuseRobots
        public tile setTile(int x, int y, tile t, bool checkBorder)
        {
            if(!isInBounds(x, y))
                return null;

            tile oldTile = m[x,y].myTile;
            m[x,y].myTile = t;

            if(!checkBorder)
                return oldTile;

            for(int yi=-1; yi<=1; yi++)
                for(int xi=-1; xi<=1; xi++)
                {
                    if(xi!=0 || yi!=0)
                        blankTile(x+xi, y+yi, -xi, -yi);
                }

            bool repeat = false;

            do
            {
                repeat = false;

                // Because of certain corner cases, we have to visit tiles in a
                // particular order (horizontally-adjacent first, then diagonally-
                // adjacent).
                int[] xs = { -1, 0, 1,  0, -1, -1,  1, 1 };
                int[] ys = { 0,  1, 0, -1, -1,  1, -1, 1 };

                //for(int yi=-1; yi<=1; yi++)
                //for(int xi=-1; xi<=1; xi++)
                for(int ii=0; ii<8; ii++)
                {
                    int xi = x+xs[ii], yi = y+ys[ii];

                    if(isInBounds(xi, yi) && m[xi,yi].blanked)
                    {
                        if(matchTile(xi, yi))
                        {
                            repeat = true;
                            unblankTile(xi, yi);
                        }
                    }
                }
            } while(repeat);

            for(int yi=-1; yi<=1; yi++)
                for(int xi=-1; xi<=1; xi++)
                    unblankTile(x+xi, y+yi);

            return oldTile;
        }
예제 #13
0
파일: Map.cs 프로젝트: yixu34/RefuseRobots
        public bool fill(int x, int y, tile t)
        {
            tile current = m[x,y].myTile;
            if(t==current) return false;
            int cx=x;
            int cy=y;
            Queue q = new Queue();
            q.Enqueue(new Point(x,y));
            m[x,y].myTile = t;
            while(q.Count!=0)
            {
                Point p = (Point)q.Dequeue();
                if(p.X+1<width && m[p.X+1,p.Y].myTile == current)
                {

                    m[p.X+1,p.Y].myTile = t;
                    q.Enqueue(new Point(p.X+1,p.Y));
                }
                if(p.X-1>=0 && m[p.X-1,p.Y].myTile == current)
                {
                    m[p.X-1,p.Y].myTile = t;
                    q.Enqueue(new Point(p.X-1,p.Y));
                }
                if(p.Y+1<height && m[p.X,p.Y+1].myTile == current)
                {
                    m[p.X,p.Y+1].myTile = t;
                    q.Enqueue(new Point(p.X,p.Y+1));
                }
                if(p.Y-1>=0 && m[p.X,p.Y-1].myTile == current)
                {
                    m[p.X,p.Y-1].myTile = t;
                    q.Enqueue(new Point(p.X,p.Y-1));
                }

            }
            return true;
        }