public AnalyzeMap(int sizeX, int sizeY) { this.sizeX = sizeX; this.sizeY = sizeY; tileStatus = new TileStatus[sizeX, sizeY]; for (int x = 0; x < sizeX; x++) { for (int y = 0; y < sizeY; y++) { tileStatus[x, y] = new TileStatus(); } } }
public void testSaltIronFlint() { AnalyzeMap map = new AnalyzeMap(3, 3); AnalyzeResult result = new AnalyzeResult(new List <AnalyzeMatch>(new AnalyzeMatch[] { new AnalyzeMatch(1, "iron ore", "utmost", "southeast"), new AnalyzeMatch(1, "salt", null, "southeast"), new AnalyzeMatch(1, "flint", null, "southeast") })); map.SetResult(1, 1, result); Tile tile = new Tile(2, 2); Assert.IsNull(map[tile].Estimates); Assert.IsNotNull(map[tile].Found); Assert.IsTrue(map[tile].HasSalt); Assert.IsTrue(map[tile].HasFlint); Assert.AreEqual(TileType.Iron, map[tile].Found.Type); Assert.AreEqual(Quality.Utmost, map[tile].Found.Quality); TileStatus status = map[tile]; String text = status.ToString(); }
public void ResizeMap(int newX, int newY, int dx, int dy) { if (newX <= 0 || newY <= 0) { throw new Exception("A map can't be smaller than 1 tile in each direction"); } TileStatus[,] newTileStatus = new TileStatus[newX, newY]; for (int x = 0; x < newX; x++) { for (int y = 0; y < newY; y++) { int oldX = x - dx; int oldY = y - dy; if (oldX < 0 || oldY < 0 || oldX >= sizeX || oldY >= sizeY) { newTileStatus[x, y] = new TileStatus(); } else { newTileStatus[x, y] = tileStatus[oldX, oldY]; if (newTileStatus[x, y].Result != null && newTileStatus[x, y].Result.PositionSet) { newTileStatus[x, y].Result.X += dx; newTileStatus[x, y].Result.Y += dy; } } } } tileStatus = newTileStatus; sizeX = newX; sizeY = newY; if (OnResize != null) { OnResize(this, newX, newY, dx, dy); } }
public void ResizeMap(int newX, int newY, int dx, int dy) { if (newX <= 0 || newY <= 0) { throw new Exception("A map can't be smaller than 1 tile in each direction"); } TileStatus[,] newTileStatus = new TileStatus[newX, newY]; for (int x = 0; x < newX; x++) { for (int y = 0; y < newY; y++) { int oldX = x - dx; int oldY = y - dy; if (oldX < 0 || oldY < 0 || oldX >= sizeX || oldY >= sizeY) newTileStatus[x, y] = new TileStatus(); else { newTileStatus[x, y] = tileStatus[oldX, oldY]; if (newTileStatus[x, y].Result != null && newTileStatus[x, y].Result.PositionSet) { newTileStatus[x, y].Result.X += dx; newTileStatus[x, y].Result.Y += dy; } } } } tileStatus = newTileStatus; sizeX = newX; sizeY = newY; if (OnResize != null) OnResize(this, newX, newY, dx, dy); }
private void DrawCellBackground(GridControl.Cell cell, Rectangle area, Graphics graphics) { Image texture = GetTileTexture(cell.X, cell.Y); if (texture == null) { switch (map[cell.X, cell.Y].Type) { case TileType.Tunnel: graphics.FillRectangle(Brushes.White, area); break; case TileType.Rock: graphics.FillRectangle(Brushes.Gray, area); break; default: graphics.FillRectangle(Brushes.Green, area); break; } } else { TileStatus tile = map[cell.X, cell.Y]; if (tile.Estimates == null && tile.Found == null) { float b = 0.7f; ColorMatrix cm = new ColorMatrix(new float[][] { new float[] { b, 0, 0, 0, 0 }, new float[] { 0, b, 0, 0, 0 }, new float[] { 0, 0, b, 0, 0 }, new float[] { 0, 0, 0, 1, 0 }, new float[] { 0, 0, 0, 0, 1 }, }); ImageAttributes imgAttr = new ImageAttributes(); imgAttr.SetColorMatrix(cm); Point[] points = { new Point(area.Left, area.Top), new Point(area.Right, area.Top), new Point(area.Left, area.Bottom), }; Rectangle srcRect = new Rectangle(0, 0, area.Width, area.Height); graphics.DrawImage(texture, points, srcRect, GraphicsUnit.Pixel, imgAttr); } else { graphics.DrawImage(texture, area); } } texture = GetSaltTexture(CellToTile(cell)); if (texture != null) { graphics.DrawImage(texture, area); } texture = GetFlintTexture(CellToTile(cell)); if (texture != null) { graphics.DrawImage(texture, area); } }
public XmlDocument Serialize() { XmlDocument doc = new XmlDocument(); doc.AppendChild(doc.CreateXmlDeclaration("1.0", "UTF-8", null)); XmlElement root = doc.CreateElement("AnalyzeMap", namespaceUri); doc.AppendChild(root); root.SetAttribute("xmlns", namespaceUri); root.SetAttribute("version", "1.2"); root.SetAttribute("width", this.SizeX.ToString()); root.SetAttribute("height", this.SizeY.ToString()); for (int x = 0; x < sizeX; x++) { for (int y = 0; y < sizeY; y++) { TileStatus status = tileStatus[x, y]; if (status.Type != TileType.Nothing && status.Type != TileType.Unknown) { XmlElement element = doc.CreateElement("Tile", namespaceUri); element.SetAttribute("x", x.ToString()); element.SetAttribute("y", y.ToString()); element.SetAttribute("type", status.Type.ToString()); if (status.HasSalt) { element.SetAttribute("salt", "true"); } if (status.HasFlint) { element.SetAttribute("flint", "true"); } if (status.HasExactQuality) { element.SetAttribute("quality", status.ExactQuality.ToString()); } else if (status.Quality != Quality.Unknown) { element.SetAttribute("quality", status.Quality.ToString()); } root.AppendChild(element); } } } foreach (AnalyzeResult result in results) { XmlElement element = doc.CreateElement("Analyze", namespaceUri); element.SetAttribute("x", result.X.ToString()); element.SetAttribute("y", result.Y.ToString()); foreach (AnalyzeMatch match in result.Matches) { XmlElement node = doc.CreateElement("Entry", namespaceUri); node.SetAttribute("distance", match.Distance.ToString()); if (match.Type != null) { node.SetAttribute("type", match.Type); } if (match.Quality != null) { node.SetAttribute("quality", match.Quality); } if (match.Direction != null) { node.SetAttribute("direction", match.Direction); } element.AppendChild(node); } root.AppendChild(element); } return(doc); }