Package com.iwolverton.smartbeetle
Class Coord
- java.lang.Object
-
- com.iwolverton.smartbeetle.Coord
-
- Direct Known Subclasses:
GameElement
public class Coord extends Object
An x, y coordinate pair.Coord also serves as the base class for all game elements, which means that each game element has all of Coord's methods (inheritance) and can be used anywhere a Coord is called for (polymorphism).
Note that in the game's coordinates,right (E) and down (S) are positive.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DirectionaltDirectionTo(Coord other)Determine the direction most aimed toward another coordinate.intdiagonalDistanceFrom(int x, int y)Get the distance from this coordinate to another coordinate allowing cardinal and diagonal moves.intdiagonalDistanceFrom(Coord other)Get the distance from this coordinate to another coordinate allowing cardinal and diagonal moves.DirectiondirectionTo(Coord other)Determine the direction most aimed toward another coordinate.booleanequals(Object other)intgetX()X coordinate: right (E) is positive.intgetY()Y coordinate: down (S) is positive.booleanisAt(int x, int y)Is this coordinate at the given x and y?booleanisAt(Coord other)Is this coordinate at the same location as another coordinate?static CoordrandCoord()Generate a random coordinate within the bounds of the map.static intrandCoordPart()Generate a random coordinate on a single axis within the bounds of the map.intrightAngleDistanceFrom(int x, int y)Get the distance from this coordinate to another coordinate making only cardinal direction moves (no diagonals).intrightAngleDistanceFrom(Coord other)Get the distance from this coordinate to another coordinate making only cardinal direction moves (no diagonals).
-
-
-
Constructor Detail
-
Coord
public Coord(int x, int y)
-
Coord
public Coord(Coord from)
-
-
Method Detail
-
getX
public int getX()
X coordinate: right (E) is positive.
-
getY
public int getY()
Y coordinate: down (S) is positive.
-
isAt
public boolean isAt(int x, int y)Is this coordinate at the given x and y?
-
isAt
public boolean isAt(Coord other)
Is this coordinate at the same location as another coordinate?
-
rightAngleDistanceFrom
public int rightAngleDistanceFrom(int x, int y)Get the distance from this coordinate to another coordinate making only cardinal direction moves (no diagonals). This is useful since the game only allows cardinal direction moves.
-
rightAngleDistanceFrom
public int rightAngleDistanceFrom(Coord other)
Get the distance from this coordinate to another coordinate making only cardinal direction moves (no diagonals). This is useful since the game only allows cardinal direction moves.
-
diagonalDistanceFrom
public int diagonalDistanceFrom(int x, int y)Get the distance from this coordinate to another coordinate allowing cardinal and diagonal moves. Game elements cannot actually move diagonally, but this can still be a useful measure.
-
diagonalDistanceFrom
public int diagonalDistanceFrom(Coord other)
Get the distance from this coordinate to another coordinate allowing cardinal and diagonal moves. Game elements cannot actually move diagonally, but this can still be a useful measure.
-
directionTo
public Direction directionTo(Coord other)
Determine the direction most aimed toward another coordinate. In case of a tie, the x-axis coordinate is chosen. If the other coordinate is the same as this, NONE is returned.
-
altDirectionTo
public Direction altDirectionTo(Coord other)
Determine the direction most aimed toward another coordinate. In case of a tie, the y-axis coordinate is chosen. If the other coordinate is the same as this, NONE is returned.
-
randCoordPart
public static int randCoordPart()
Generate a random coordinate on a single axis within the bounds of the map.
-
randCoord
public static Coord randCoord()
Generate a random coordinate within the bounds of the map.
-
-