private void DrawTile(object sender, NodeAddedToCollectionEventArgs args) { mainDispatcher.Invoke(() => { Node node = args.node; AStarTile tile = AStarValues.AStarTiles[node.RowIndex, node.ColumnIndex]; if (tile == null) { tile = new AStarTile(node.RowIndex, node.ColumnIndex); } Tile tileType = tile.TileType; if (tileType == Tile.Empty || tileType == Tile.EmptyClosed || tileType == Tile.EmptyOpen) { Tile newType = Tile.Empty; if (sender is OpenSet) { newType = Tile.EmptyOpen; } else if (sender is ClosedSet) { newType = Tile.EmptyClosed; } tile.TileType = newType; AStarValues.SetAStarTile(tile); } }, DispatcherPriority.Normal); }
private void RemoveTile(object sender, MouseEventArgs e) { if (AStarValues.AStarState == State.HasNotStarted) { Point mousePosition = e.GetPosition(canvas); double MousePosX = mousePosition.X; double MousePosY = mousePosition.Y; int RowIndex = GetRowIndex(MousePosY); int ColumnIndex = GetColumnIndex(MousePosX); AStarTile oldTile = AStarValues.AStarTiles[RowIndex, ColumnIndex]; if (oldTile == null) { return; } if (oldTile.TileType == Tile.Start) { AStarValues.StartTile = null; } else if (oldTile.TileType == Tile.Goal) { AStarValues.GoalTile = null; } var emptyTile = new AStarTile(RowIndex, ColumnIndex, Tile.Empty); AStarValues.SetAStarTile(emptyTile); } }
private void SetGoalTile(int RowIndex, int ColumnIndex) { var goalTile = new AStarTile(RowIndex, ColumnIndex, Tile.Goal); AStarValues.SetAStarTile(goalTile); AStarValues.GoalTile = goalTile; SetGoalTileValueChanged(this, EventArgs.Empty); }
private void SetStartTile(int RowIndex, int ColumnIndex) { var startTile = new AStarTile(RowIndex, ColumnIndex, Tile.Start); AStarValues.SetAStarTile(startTile); AStarValues.StartTile = startTile; SetStartTileValueChanged(this, EventArgs.Empty); }
private void ClearTiles_Pressed(object sender, EventArgs args) { int numRows = AStarValues.NumGridRows; int numColumns = AStarValues.NumGridColumns; AStarValues.StartTile = null; AStarValues.GoalTile = null; for (int i = 0; i < numRows; i++) { for (int j = 0; j < numColumns; j++) { var newTile = new AStarTile(i, j, Tile.Empty); AStarValues.SetAStarTile(newTile); } } }
private void ResetPathTiles(object sender, EventArgs args) { AStarTile[,] tiles = AStarValues.AStarTiles; foreach (AStarTile tile in tiles) { if (tile == null) { continue; } if (tile.TileType == Tile.EmptyClosed || tile.TileType == Tile.EmptyOpen) { tile.TileType = Tile.Empty; AStarValues.SetAStarTile(tile); } } }
private void SetWallTile(int RowIndex, int ColumnIndex) { var wallTile = new AStarTile(RowIndex, ColumnIndex, Tile.Wall); AStarValues.SetAStarTile(wallTile); }
public void RedrawTile() { AStarValues.SetAStarTile(this); }