public static bool CheckForEmptyCellInCurrentDirection(int[,] matrix, CurrentPosition currentPosition) { Directions direction = new Directions(); int DIRECTIONS_COUNT = 8; for (int i = 0; i < DIRECTIONS_COUNT; i++) { if (currentPosition.X + direction.X[i] >= matrix.GetLength(0) || currentPosition.X + direction.X[i] < 0) { direction.X[i] = 0; } if (currentPosition.Y + direction.Y[i] >= matrix.GetLength(1) || currentPosition.Y + direction.Y[i] < 0) { direction.Y[i] = 0; } } for (int i = 0; i < DIRECTIONS_COUNT; i++) { if (matrix[currentPosition.X + direction.X[i], currentPosition.Y + direction.Y[i]] == 0) { return true; } } return false; }
public static void ChangeDirection(CurrentDirection currentDirection) { Directions direction = new Directions(); int currentDirectionCount = 0; int DIRECTIONS_COUNT = 8; for (int i = 0; i < DIRECTIONS_COUNT; i++) { if (direction.X[i] == currentDirection.X && direction.Y[i] == currentDirection.Y) { currentDirectionCount = i; break; } } if (currentDirectionCount == (DIRECTIONS_COUNT - 1)) { currentDirection.X = direction.X[0]; currentDirection.Y = direction.Y[0]; return; } currentDirection.X = direction.X[currentDirectionCount + 1]; currentDirection.Y = direction.Y[currentDirectionCount + 1]; }