Ejemplo n.º 1
0
        public void DrawMap(Map map)
        {
            MapCanvas.Children.Clear();
            MapCanvas.Width = 32 * map.Width;
            MapCanvas.Height = 32 * map.Height;

            mapCanvasIMGs = new Image[map.Width, map.Height];
            for (int x = 0; x < map.Width; x++)
            {
                for (int y = 0; y < map.Height; y++)
                {
                    Image img = new Image
                    {
                        Width = 32,
                        Height = 32,
                        Source = this.controller.TileIMG(map.Tiles[x, y].Type),
                        Tag = new Vector2(map.Tiles[x,y].Position.X, map.Tiles[x,y].Position.Y)
                    };

                    img.MouseLeftButtonDown += this.BrushDown;
                    img.MouseLeftButtonUp += this.BrushUp;
                    img.MouseMove += this.OnDraw;
                    this.MapCanvas.Children.Add(img);
                    mapCanvasIMGs[x, y] = img;
                    Canvas.SetLeft(img, x * 32);
                    Canvas.SetTop(img, y * 32);
                }
            }
        }
Ejemplo n.º 2
0
        public void CreateNewMap(int width, int height)
        {
            this.map = new Map(width, height);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    map.Tiles[x, y] = new MapTile(x, y, "Water");
                }
            }

            this.newWindow.Close();
            this.mainWindow.DrawMap(map);
        }
Ejemplo n.º 3
0
        public void ExecuteOpen()
        {
            OpenFileDialog openDialog = new OpenFileDialog
            {
                AddExtension = true,
                CheckFileExists = true,
                CheckPathExists = true,
                ValidateNames = true,
                DefaultExt = ".xml",
                Filter = "Map File (.xml)|*xml"
            };

            var checkDialog = openDialog.ShowDialog();
            if (checkDialog != true)
            {
                return;
            }

            using (var stream = openDialog.OpenFile())
            {
                XmlReaderSettings settings = new XmlReaderSettings
                {
                    IgnoreWhitespace = true,
                    IgnoreComments = true
                };

                using (var reader = XmlReader.Create(stream, settings))
                {
                    reader.Read();

                    reader.ReadToFollowing("Width");
                    reader.ReadStartElement();
                    int mapWidth = reader.ReadContentAsInt();

                    reader.ReadToFollowing("Height");
                    reader.ReadStartElement();
                    int mapHeight = reader.ReadContentAsInt();

                    Map newMap = new Map(mapWidth, mapHeight);

                    reader.ReadToFollowing("Tiles");

                    for (int i = 0; i < mapWidth * mapHeight; i++)
                    {
                        reader.ReadToFollowing("XPos");
                        reader.ReadStartElement();
                        int xPos = reader.ReadContentAsInt();

                        reader.ReadToFollowing("YPos");
                        reader.ReadStartElement();
                        int yPos = reader.ReadContentAsInt();

                        reader.ReadToFollowing("Type");
                        reader.ReadStartElement();
                        string tileType = reader.ReadContentAsString();

                        newMap.Tiles[xPos, yPos] = new MapTile(xPos, yPos, tileType);
                    }

                    this.map = newMap;
                    this.mainWindow.DrawMap(map);
                }
            }
        }