public static Direction GetNextDirection(this int[,] matrix, Direction direction, int row, int col) { for (int i = 0; i < DirectionsCount; i++) { Direction currentDirection = (Direction)(((int)direction + i) % DirectionsCount); int currentRow = row + GetRowChange(currentDirection); int currentCol = col + GetColChange(currentDirection); if (matrix.CanContinueInDirection(currentRow, currentCol)) { return(currentDirection); } } throw new InvalidOperationException("The matrix is filled."); }
public static Direction GetNextDirection(this int[,] matrix, Direction currentDirection, int currentRow, int currentCol) { for (int i = 0; i < DirectionsCount; i++) { var nextDirection = (Direction)(((int)currentDirection + i) % DirectionsCount); var nextRow = currentRow + GetRowDelta(nextDirection); var nextCol = currentCol + GetColDelta(nextDirection); if (matrix.CanContinueInDirection(nextRow, nextCol)) { return(nextDirection); } } throw new InvalidOperationException("The matrix is filled."); }