internal void moveCharacter(string v, CartesianCell orginalPostition, CartesianCell newCell) { var img = new Bitmap(WIDTH, HEIGHT); using (var g = Graphics.FromImage(img)) { if (v == "North") { Console.WriteLine("North"); CharacterPosition = orginalPostition.North.Location; var brush = new SolidBrush(Color.Green); g.FillRectangle(brush, CharacterPosition.X, CharacterPosition.Y, CELLSIZE, CELLSIZE); } if (v == "South") { CharacterPosition = orginalPostition.South.Location; var brush = new SolidBrush(Color.Green); g.FillRectangle(brush, CharacterPosition.X, CharacterPosition.Y, CELLSIZE, CELLSIZE); } if (v == "East") { CharacterPosition = orginalPostition.East.Location; var brush = new SolidBrush(Color.Green); g.FillRectangle(brush, CharacterPosition.X, CharacterPosition.Y, CELLSIZE, CELLSIZE); } if (v == "West") { CharacterPosition = orginalPostition.West.Location; var brush = new SolidBrush(Color.Green); g.FillRectangle(brush, CharacterPosition.X, CharacterPosition.Y, CELLSIZE, CELLSIZE); } } }
protected override void ToImgWithInset(Graphics g, CartesianCell cell, DrawMode mode, int cellSize, int x, int y, int inset) { if (cell is UnderCell) { var(x1, x2, x3, x4, y1, y2, y3, y4) = CellCoordinatesWithInset(x, y, cellSize, inset); if (cell.VerticalPassage) { g.DrawLine(Pens.Black, x2, y1, x2, y2); g.DrawLine(Pens.Black, x3, y1, x3, y2); g.DrawLine(Pens.Black, x2, y3, x2, y4); g.DrawLine(Pens.Black, x3, y3, x3, y4); } else { g.DrawLine(Pens.Black, x1, y2, x2, y2); g.DrawLine(Pens.Black, x1, y3, x2, y3); g.DrawLine(Pens.Black, x3, y2, x4, y2); g.DrawLine(Pens.Black, x3, y3, x4, y3); } } else { base.ToImgWithInset(g, cell, mode, cellSize, x, y, inset); } }
private void DrawSquare(Graphics g, CartesianCell cell, double cx, double cy, double aSize) { var x1 = (int)(cx - aSize); var y1 = (int)(cy - aSize); var x2 = (int)(cx + aSize); var y2 = (int)(cy + aSize); if (cell.North == null) { g.DrawLine(Pens.Black, x1, y1, x2, y1); } if (cell.West == null) { g.DrawLine(Pens.Black, x1, y1, x1, y2); } if (!cell.IsLinked(cell.East)) { g.DrawLine(Pens.Black, x2, y1, x2, y2); } if (!cell.IsLinked(cell.South)) { g.DrawLine(Pens.Black, x1, y2, x2, y2); } if (cell == ActiveCell) { g.FillRectangle(Brushes.GreenYellow, x1 + 2, y1 + 2, (int)(aSize * 2) - 4, (int)(aSize * 2) - 4); } }
public RecursiveBacktracker(Grid grid, int seed = -1, CartesianCell startAt = null) { _grid = grid; _rand = seed >= 0 ? new Random(seed) : new Random(); CurrentCell = startAt ?? _grid.RandomCell(_rand); _stack = new Stack <Cell>(); _stack.Push(CurrentCell); }
private void ToImgWithoutInset(Graphics g, CartesianCell cell, DrawMode mode, int cellSize, int x, int y) { var x1 = x; var y1 = y; var x2 = x1 + cellSize; var y2 = y1 + cellSize; if (cell.Neighbors.Count == 0) { return; } if (mode == DrawMode.Background) { var color = BackgroundColorFor(cell); if (color != null) { g.FillRectangle(new SolidBrush(color.GetValueOrDefault()), x1, y1, cellSize, cellSize); } } else if (mode == DrawMode.Walls) { if (cell.North == null) { g.DrawLine(Pens.Black, x1, y1, x2, y1); } if (cell.West == null) { g.DrawLine(Pens.Black, x1, y1, x1, y2); } if (!cell.IsLinked(cell.East)) { g.DrawLine(Pens.Black, x2, y1, x2, y2); } if (!cell.IsLinked(cell.South)) { g.DrawLine(Pens.Black, x1, y2, x2, y2); } if (cell == ActiveCell) { g.FillRectangle(Brushes.GreenYellow, x1 + 2, y1 + 2, cellSize - 4, cellSize - 4); } } else if (mode == DrawMode.Path) { DrawPath(cell, g, cellSize); } }
protected virtual void ToImgWithInset(Graphics g, CartesianCell cell, DrawMode mode, int cellSize, int x, int y, int inset) { var(x1, x2, x3, x4, y1, y2, y3, y4) = CellCoordinatesWithInset(x, y, cellSize, inset); if (mode == DrawMode.Background) { var color = BackgroundColorFor(cell); if (color != null) { // fill center var brush = new SolidBrush(color.GetValueOrDefault()); g.FillRectangle(brush, x2, y2, cellSize - inset * 2, cellSize - inset * 2); if (cell.IsLinked(cell.North)) { g.FillRectangle(brush, x2, y1, cellSize - 2 * inset, inset); } if (cell.IsLinked(cell.South)) { g.FillRectangle(brush, x2, y3, cellSize - 2 * inset, inset); } if (cell.IsLinked(cell.West)) { g.FillRectangle(brush, x1, y2, inset, cellSize - 2 * inset); } if (cell.IsLinked(cell.East)) { g.FillRectangle(brush, x3, y2, inset, cellSize - 2 * inset); } } } else if (mode == DrawMode.Walls) { if (cell.IsLinked(cell.North)) { g.DrawLine(Pens.Black, x2, y1, x2, y2); g.DrawLine(Pens.Black, x3, y1, x3, y2); } else { g.DrawLine(Pens.Black, x2, y2, x3, y2); } if (cell.IsLinked(cell.South)) { g.DrawLine(Pens.Black, x2, y3, x2, y4); g.DrawLine(Pens.Black, x3, y3, x3, y4); } else { g.DrawLine(Pens.Black, x2, y3, x3, y3); } if (cell.IsLinked(cell.West)) { g.DrawLine(Pens.Black, x1, y2, x2, y2); g.DrawLine(Pens.Black, x1, y3, x2, y3); } else { g.DrawLine(Pens.Black, x2, y2, x2, y3); } if (cell.IsLinked(cell.East)) { g.DrawLine(Pens.Black, x3, y2, x4, y2); g.DrawLine(Pens.Black, x3, y3, x4, y3); } else { g.DrawLine(Pens.Black, x3, y2, x3, y3); } if (cell == ActiveCell) { g.FillRectangle(Brushes.GreenYellow, x2 + 1, y2 + 1, cellSize - inset * 2 - 2, cellSize - inset * 2 - 2); } } else if (mode == DrawMode.Path) { DrawPath(cell, g, cellSize); } }
internal bool isWall(CartesianCell orginalPostition, CartesianCell newCell) { return(!orginalPostition.IsLinked(newCell)); }
private void ToImgWithoutInset(Graphics g, CartesianCell cell, DrawMode mode, int cellSize, int x, int y) { CELLSIZE = cellSize; var x1 = x; var y1 = y; var x2 = x1 + cellSize; var y2 = y1 + cellSize; Random v = new Random(555 * cellSize); int vN = v.Next(); if (cell.Neighbors.Count == 0) { return; } if (mode == DrawMode.Background) { var color = BackgroundColorFor(cell); if (color != null) { if (hasPlayer(x1, y1) == true) { var brush = new SolidBrush(Color.Green); g.FillRectangle(brush, x1, y1, cellSize, cellSize); } else { if (cell.containsBonus(y1 * vN * x) == true && hasPlayer(x1, y1) == false) { var brush = new SolidBrush(Color.Red); g.FillRectangle(brush, x1, y1, cellSize, cellSize); } else { g.FillRectangle(new SolidBrush(color.GetValueOrDefault()), x1, y1, cellSize, cellSize); } } } } else if (mode == DrawMode.Walls) { if (cell.North == null) { g.DrawLine(Pens.Black, x1, y1, x2, y1); } if (cell.West == null) { g.DrawLine(Pens.Black, x1, y1, x1, y2); } if (!cell.IsLinked(cell.East)) { g.DrawLine(Pens.Black, x2, y1, x2, y2); } if (!cell.IsLinked(cell.South)) { g.DrawLine(Pens.Black, x1, y2, x2, y2); } if (cell == ActiveCell) { g.FillRectangle(Brushes.GreenYellow, x1 + 2, y1 + 2, cellSize - 4, cellSize - 4); } } else if (mode == DrawMode.Path) { DrawPath(cell, g, cellSize); } }
protected virtual void ToImgWithInset(Graphics g, CartesianCell cell, DrawMode mode, int cellSize, int x, int y, int inset) { var(x1, x2, x3, x4, y1, y2, y3, y4) = CellCoordinatesWithInset(x, y, cellSize, inset); if (mode == DrawMode.Background) { var color = BackgroundColorFor(cell); if (color != null) { // fill center var brush = new SolidBrush(Color.AliceBlue); g.FillRectangle(brush, x2, y2, cellSize - inset * 2, cellSize - inset * 2); Console.WriteLine("REached"); if (cell.IsLinked(cell.North)) { brush = new SolidBrush(Color.Red); g.FillRectangle(brush, x2, y2, cellSize - inset * 2, cellSize - inset * 2); } if (cell.IsLinked(cell.South)) { g.FillRectangle(brush, x2, y3, cellSize - 2 * inset, inset); if (cell.containsBonus(y3) == true) { brush = new SolidBrush(Color.Red); g.FillRectangle(brush, x2, y3, cellSize - 2 * inset, inset); } } if (cell.IsLinked(cell.West)) { g.FillRectangle(brush, x1, y2, inset, cellSize - 2 * inset); if (cell.containsBonus(x1) == true) { Icon bonus = Icon.ExtractAssociatedIcon("../../bonus.ico"); Point p = new Point(x1, y2); g.DrawIcon(icon: bonus, x1, y2); } } if (cell.IsLinked(cell.East)) { g.FillRectangle(brush, x3, y2, inset, cellSize - 2 * inset); if (cell.containsBonus(x3) == true) { Icon bonus = Icon.ExtractAssociatedIcon("../../bonus.ico"); Point p = new Point(x3, y2); g.DrawIcon(icon: bonus, x3, y2); } } } } else if (mode == DrawMode.Walls) { if (cell.IsLinked(cell.North)) { g.DrawLine(Pens.Black, x2, y1, x2, y2); g.DrawLine(Pens.Black, x3, y1, x3, y2); } else { g.DrawLine(Pens.Black, x2, y2, x3, y2); } if (cell.IsLinked(cell.South)) { g.DrawLine(Pens.Black, x2, y3, x2, y4); g.DrawLine(Pens.Black, x3, y3, x3, y4); } else { g.DrawLine(Pens.Black, x2, y3, x3, y3); } if (cell.IsLinked(cell.West)) { g.DrawLine(Pens.Black, x1, y2, x2, y2); g.DrawLine(Pens.Black, x1, y3, x2, y3); } else { g.DrawLine(Pens.Black, x2, y2, x2, y3); } if (cell.IsLinked(cell.East)) { g.DrawLine(Pens.Black, x3, y2, x4, y2); g.DrawLine(Pens.Black, x3, y3, x4, y3); } else { g.DrawLine(Pens.Black, x3, y2, x3, y3); } if (cell == ActiveCell) { g.FillRectangle(Brushes.GreenYellow, x2 + 1, y2 + 1, cellSize - inset * 2 - 2, cellSize - inset * 2 - 2); } } else if (mode == DrawMode.Path) { DrawPath(cell, g, cellSize); } }