Class Location


public class Location
implements Serializable

This class represents a location in the game. Each location is composed of
three parts. The first is a reference to the Screen it is a location in.
The second is the course x,y coordinate specifying the block it is in. The
third is a fine grained x,y giving a more accurate point in that block.
It should be noted that this class is immutable. Once you create an instance
of it, the values in it will not be changed. The partialMove method returns
a new Location object that is offset from the current one by the specified
number of "partial coordinate" units.


Constructor Summary
Location(Screen s, int x, int y)
          Constructor that sets the main location coordinates.
Location(Screen s, int x, int y, int px, int py)
          Constructor that sets all the location coordinates.
Location(Location loc)
          This copy constructor isn't really needed because this is an immutable
class.

Method Summary
 booleanequals(Object o)
          This method overrides the same method from object.
 intgetLocX()
          Returns the x block location.
 intgetLocY()
          Returns the y block location.
 static intgetPartialsInWhole()
           
 intgetPartialX()
          Returns the x partial block location.
 intgetPartialY()
          Returns the y partial block location.
 ScreengetScreen()
          Returns the Screen object that this location is in.
 LocationpartialMove(int dx, int dy)
          Returns a Location object that has been offset from this one by
the specified partial block distance.
 static voidsetPartialsInWhole(int num)
           

Constructor Detail

Location

public Location(Screen s, int x, int y)
Constructor that sets the main location coordinates. The partial
coordinates are set to zero.
Parameters:
s The screen for this location.
x The value to be stored in locX.
y The value to be stored in locY.

Location

public Location(Screen s, int x, int y, int px, int py)
Constructor that sets all the location coordinates.
Parameters:
s The screen for this location.
x The value to be stored in locX.
y The value to be stored in locY.
px The value to be stored in partialX.
py The value to be stored in partialY.

Location

public Location(Location loc)
This copy constructor isn't really needed because this is an immutable
class. Still it is provided just in case someone feels like they have
a valid need to call it.
Parameters:
loc The location to be copied.
Method Detail

equals

public boolean equals(Object o)
This method overrides the same method from object. If the object
passed in is not a Location it returns false. If it is, it checks to see
if the screens are the same and if the four position variables are the same.
Parameters:
o Object to check for equality against.
Returns: Boolean telling if they are equal.

getLocX

public int getLocX()
Returns the x block location.
Returns: The x block location.

getLocY

public int getLocY()
Returns the y block location.
Returns: The y block location.

getPartialsInWhole

public static int getPartialsInWhole()

getPartialX

public int getPartialX()
Returns the x partial block location.
Returns: The x partial block location.

getPartialY

public int getPartialY()
Returns the y partial block location.
Returns: The y partial block location.

getScreen

public Screen getScreen()
Returns the Screen object that this location is in.
Returns: The screen object the location is in.

partialMove

public Location partialMove(int dx, int dy)
Returns a Location object that has been offset from this one by
the specified partial block distance. This function handles both when
the partial motion moves it into another full block as well as problems
with going beyond a screen bound.
Parameters:
dx The partial block offset in x.
dy The partial block offset in y.
Returns: A location object offset from the current one.

setPartialsInWhole

public static void setPartialsInWhole(int num)

Association Links

to Class Screen