public bool IsCellOpen(GameCharacter character, Direction direction) { int x = character.X >> 4; int y = character.Y >> 4; switch (direction) { case Direction.Left: return character.CanEnterCell(_maze[y][x - 1]); case Direction.Right: return character.CanEnterCell(_maze[y][x + 1]); case Direction.Up: return character.CanEnterCell(_maze[y - 1][x]); case Direction.Down: return character.CanEnterCell(_maze[y + 1][x]); } return false; }
public Direction[] GetOpenDirections(GameCharacter character, Direction current) { int i = 0; _openDirections[0] = Direction.Stop; _openDirections[1] = Direction.Stop; _openDirections[2] = Direction.Stop; _openDirections[3] = Direction.Stop; if (current != Direction.Right && IsCellOpen(character, Direction.Left)) _openDirections[i++] = Direction.Left; if (current != Direction.Left && IsCellOpen(character, Direction.Right)) _openDirections[i++] = Direction.Right; if (current != Direction.Down && IsCellOpen(character, Direction.Up)) _openDirections[i++] = Direction.Up; if (current != Direction.Up && IsCellOpen(character, Direction.Down)) _openDirections[i++] = Direction.Down; if (i == 0) { if (current == Direction.Right && IsCellOpen(character, Direction.Left)) _openDirections[i++] = Direction.Left; else if (current == Direction.Left && IsCellOpen(character, Direction.Right)) _openDirections[i++] = Direction.Right; else if (current == Direction.Down && IsCellOpen(character, Direction.Up)) _openDirections[i++] = Direction.Up; else if (current == Direction.Up && IsCellOpen(character, Direction.Down)) _openDirections[i++] = Direction.Down; } return _openDirections; }