Overview
The Direction
class provides a flexible and powerful interface for working with two-dimensional
coordinates. It defines a set of cardinal and intercardinal directions that can be used for navigating the world.
Attributes
NORTH
tupleDirection that points north (up).
dx
intThe change in the x-coordinate when moving in the NORTH direction.
Default: 0
dy
intThe change in the y-coordinate when moving in the NORTH direction.
Default: 1
NORTH_EAST
tupleDirection that points northeast (up and right).
dx
intThe change in the x-coordinate when moving in the NORTH_EAST direction.
Default: 1
dy
intThe change in the y-coordinate when moving in the NORTH_EAST direction.
Default: 1
EAST
tupleDirection that points east (right).
dx
intThe change in the x-coordinate when moving in the EAST direction.
Default: 1
dy
intThe change in the y-coordinate when moving in the EAST direction.
Default: 0
SOUTH_EAST
tupleDirection that points southeast (down and right).
dx
intThe change in the x-coordinate when moving in the SOUTH_EAST direction.
Default: 1
dy
intThe change in the y-coordinate when moving in the SOUTH_EAST direction.
Default: -1
SOUTH
tupleDirection that points south (down).
dx
intThe change in the x-coordinate when moving in the SOUTH direction.
Default: 0
dy
intThe change in the y-coordinate when moving in the SOUTH direction.
Default: -1
SOUTH_WEST
tupleDirection that points southwest (down and left).
dx
intThe change in the x-coordinate when moving in the SOUTH_WEST direction.
Default: -1
dy
intThe change in the y-coordinate when moving in the SOUTH_WEST direction.
Default: -1
WEST
tupleDirection that points west (left).
dx
intThe change in the x-coordinate when moving in the WEST direction.
Default: -1
dy
intThe change in the y-coordinate when moving in the WEST direction.
Default: 0
NORTH_WEST
tupleDirection that points northwest (up and left).
dx
intThe change in the x-coordinate when moving in the NORTH_WEST direction.
Default: -1
dy
intThe change in the y-coordinate when moving in the NORTH_WEST direction.
Default: 1
Methods
get_random_direction()
Returns a random direction.
Returns
A random direction.
Example:
dir = Direction.get_random_direction()
# Returns Direction.NORTH
dir = Direction.get_random_direction()
# Returns Direction.SOUTH_EAST
Additional Notes
The Direction
enum supports iteration, allowing you to easily loop over all defined directions.
This can be useful when you need to process each direction or perform operations on every direction.
For example, you can loop over the directions like this:
for direction in Direction:
print(direction)