public GridCell GetNeighborGrid(CellNeighbor nb) { switch (nb) { case CellNeighbor.Left: { GridColumn prevColumn = column.PrevColumn; if (prevColumn != null) { return(prevColumn.GetCell(row.RowIndex)); } else { return(null); } } case CellNeighbor.Right: { GridColumn nextColumn = column.NextColumn; if (nextColumn != null) { return(nextColumn.GetCell(row.RowIndex)); } else { return(null); } } case CellNeighbor.Up: { if (row.RowIndex > 0) { return(column.GetCell(row.RowIndex - 1)); } else { return(null); } } case CellNeighbor.Down: { if (row.RowIndex < row.OwnerGridRowCount - 1) { return(column.GetCell(row.RowIndex + 1)); } else { return(null); } } default: { #if DEBUG throw new NotSupportedException(); #else return(null); #endif } } }
public Cell GetNeighborCell(Cell currentCell, CellNeighbor neighbor) { Cell nCell = null; if (currentCell == null) return null; try { switch (neighbor) { case CellNeighbor.Backward: nCell = _board[GetBoardNumber(currentCell.GetName())][GetCellRow(currentCell.GetName()), GetCellCol(currentCell.GetName()) - 1]; break; case CellNeighbor.Forward: nCell = _board[GetBoardNumber(currentCell.GetName())][GetCellRow(currentCell.GetName()), GetCellCol(currentCell.GetName()) + 1]; break; case CellNeighbor.Up: nCell = _board[GetBoardNumber(currentCell.GetName()) - 1][GetCellRow(currentCell.GetName()), GetCellCol(currentCell.GetName())]; break; case CellNeighbor.Down: nCell = _board[GetBoardNumber(currentCell.GetName()) + 1][GetCellRow(currentCell.GetName()), GetCellCol(currentCell.GetName())]; break; case CellNeighbor.Left: nCell = _board[GetBoardNumber(currentCell.GetName())][GetCellRow(currentCell.GetName()) - 1, GetCellCol(currentCell.GetName())]; break; case CellNeighbor.Right: nCell = _board[GetBoardNumber(currentCell.GetName())][GetCellRow(currentCell.GetName()) + 1, GetCellCol(currentCell.GetName())]; break; } } catch (Exception) { return null; } return nCell; }
public bool IsSameOrOpposite(CellNeighbor direction1, CellNeighbor direction2) { if (direction1 == direction2) return true; switch (direction1) { case CellNeighbor.Backward: return direction2 == CellNeighbor.Forward; case CellNeighbor.Forward: return direction2 == CellNeighbor.Backward; case CellNeighbor.Up: return direction2 == CellNeighbor.Down; case CellNeighbor.Down: return direction2 == CellNeighbor.Up; case CellNeighbor.Left: return direction2 == CellNeighbor.Right; } return direction2 == CellNeighbor.Left; }
public GridCell GetNeighborGrid(CellNeighbor nb) { switch (nb) { case CellNeighbor.Left: { GridColumn prevColumn = column.PrevColumn; if (prevColumn != null) { return prevColumn.GetCell(row.RowIndex); } else { return null; } } case CellNeighbor.Right: { GridColumn nextColumn = column.NextColumn; if (nextColumn != null) { return nextColumn.GetCell(row.RowIndex); } else { return null; } } case CellNeighbor.Up: { if (row.RowIndex > 0) { return column.GetCell(row.RowIndex - 1); } else { return null; } } case CellNeighbor.Down: { if (row.RowIndex < row.OwnerGridRowCount - 1) { return column.GetCell(row.RowIndex + 1); } else { return null; } } default: { #if DEBUG throw new NotSupportedException(); #else return null; #endif } } }