private bool CheckDirection(int[,] matrix, int directionX, int directionY) { Directions possibleDirections = new Directions(); for (int i = 0; i < possibleDirections.X.Length; i++) { if (this.IsLessThanZeroAndGreaterThanLimit(directionX + possibleDirections.X[i], matrix.GetLength(0))) { possibleDirections.X[i] = 0; } if (this.IsLessThanZeroAndGreaterThanLimit(directionY + possibleDirections.Y[i], matrix.GetLength(1))) { possibleDirections.Y[i] = 0; } } for (int i = 0; i < possibleDirections.X.Length; i++) { if (matrix[directionX + possibleDirections.X[i], directionY + possibleDirections.Y[i]] == 0) { return true; } } return false; }
private void ChangeDirection(ref int directionX, ref int directionY) { Directions possibleDirections = new Directions(); int currentDirection = 0; for (int count = 0; count < possibleDirections.X.Length; count++) { if (possibleDirections.X[count] == directionX && possibleDirections.Y[count] == directionY) { currentDirection = count; break; } } if (currentDirection == possibleDirections.X.Length - 1) { directionX = possibleDirections.X[0]; directionY = possibleDirections.Y[0]; return; } directionX = possibleDirections.X[currentDirection + 1]; directionY = possibleDirections.Y[currentDirection + 1]; }