/// <summary> /// Creates a new command for drawing on the specified map. /// </summary> /// <param name="map">Map to draw on.</param> public DrawCommand(Map map) { this.Map = map; this.NewTileTypes = new Dictionary<Vector2I, string>(); this.OldTileTypes = new Dictionary<Vector2I, string>(); }
public Layer(string name) { Name = name; IsVisible = true; IsLocked = false; Map = new Map(100, 100); }
public void TestMapConstructor() { // Create new map. this.map = new Map(Width, Height); // Check width and height. Assert.AreEqual(Width, this.map.Width); Assert.AreEqual(Height, this.map.Height); }
public void CreateNewMap() { int width; int height; try { width = int.Parse(this.newMapWindow.TextBoxMapWidth.Text); } catch (FormatException) { ShowErrorMessage("Incorrect Width", "Please type in Width"); return; } try { height = int.Parse(this.newMapWindow.TextBoxMapHeight.Text); } catch (FormatException) { ShowErrorMessage("Incorrect Height", "Please type in Height"); return; } try { map = new Map(width, height); } catch (ArgumentOutOfRangeException e) { ShowErrorMessage("Incorrect Map Size", e.Message); return; } string defaultMapTile = this.newMapWindow.SelectedMapTileType; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { map[x, y] = new MapTile(x, y, defaultMapTile); } } this.newMapWindow.Close(); }
/// <summary> /// Clears the map canvas and fills it with sprites for the specified map. /// </summary> /// <param name="map">Map to show.</param> public void UpdateMapCanvas(Map map) { // Remove old images. this.MapCanvas.Children.Clear(); // Set canvas size. this.MapCanvas.Width = map.Width * TileSizeInPixels; this.MapCanvas.Height = map.Height * TileSizeInPixels; this.canvasImages = new Image[map.Width, map.Height]; for (var x = 0; x < map.Width; x++) { for (var y = 0; y < map.Height; y++) { var mapTile = map[x, y]; // Add new image to canvas. var image = new Image { Width = TileSizeInPixels, Height = TileSizeInPixels, Source = this.controller.GetTileImage(mapTile.Type), Tag = new Vector2I(x, y) }; this.MapCanvas.Children.Add(image); this.canvasImages[x, y] = image; // Set image position. Canvas.SetLeft(image, x * TileSizeInPixels); Canvas.SetTop(image, y * TileSizeInPixels); // Register image event handlers. image.MouseLeftButtonDown += this.OnBrushDown; image.MouseLeftButtonUp += this.OnBrushUp; image.MouseMove += this.OnTileClicked; } } this.ResetStatusText(); }
private void BackgroundCreateMap(object sender, DoWorkEventArgs e) { BackgroundWorker worker = (BackgroundWorker)sender; Vector2I mapSize = (Vector2I)e.Argument; // Create new map. try { this.map = new Map(mapSize.X, mapSize.Y); } catch (ArgumentOutOfRangeException ex) { this.ShowErrorMessage("Incorrect Map Size", ex.Message); return; } // Fill with tiles. var defaultMapTile = this.newMapWindow.SelectedMapTileType; var tilesCreated = 0; var totalTiles = mapSize.X * mapSize.Y; for (var x = 0; x < mapSize.X; x++) { for (var y = 0; y < mapSize.Y; y++) { this.map[x, y] = new MapTile(x, y, defaultMapTile); tilesCreated++; } // Report progress. worker.ReportProgress(tilesCreated * 100 / totalTiles); Thread.Sleep(1); } }
/// <summary> /// Shows an open file dialog box and opens the specified map file. /// </summary> public void ExecuteOpen() { // Show open file dialog box. OpenFileDialog openFileDialog = new OpenFileDialog { AddExtension = true, CheckFileExists = true, CheckPathExists = true, DefaultExt = MapFileExtension, FileName = "Another Map", Filter = MapFileFilter, ValidateNames = true }; var result = openFileDialog.ShowDialog(); if (result != true) { return; } // Close current file. if (this.currentMapFile != null) { this.currentMapFile.Close(); } // Update main window title. this.currentMapFileName = openFileDialog.FileName; this.mainWindow.Title = string.Format("{0} - {1}", MainWindowTitle, this.currentMapFileName); // Open map file. FileInfo fileInfo = new FileInfo(this.currentMapFileName); this.currentMapFile = fileInfo.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.Read); try { // Validate schema. XmlReaderSettings readerSettings = new XmlReaderSettings(); readerSettings.Schemas.Add("http://www.npruehs.de/teaching", "XML/MapSchema.xsd"); readerSettings.ValidationType = ValidationType.Schema; using (var reader = XmlReader.Create(this.currentMapFile, readerSettings)) { while (reader.Read()) { } } // Rewind stream. this.currentMapFile.Seek(0, SeekOrigin.Begin); // Deserialize map. XmlSerializer serializer = new XmlSerializer(typeof(Map)); this.map = (Map)serializer.Deserialize(this.currentMapFile); // Show new map tiles. this.UpdateMapCanvas(); } catch (InvalidOperationException) { this.ShowErrorMessage("Incorrect map file", "Please specify a valid map file!"); } catch (XmlException) { this.ShowErrorMessage("Incorrect map file", "Please specify a valid map file!"); } catch (XmlSchemaValidationException) { this.ShowErrorMessage("Incorrect map file", "Please specify a valid map file!"); } }
public void TestNegativeWidth() { this.map = new Map(-Width, Height); }
public void SetUp() { this.map = new Map(); }