com.ibm.rally
Class Car
java.lang.Object
|
+--com.ibm.rally.Car
- All Implemented Interfaces:
- ICar, IObject
- Direct Known Subclasses:
- RallyCar
- public abstract class Car
- extends java.lang.Object
- implements ICar
This class is the superclass of the RallyCar that you implement. This
class contains helper methods to find out about the state of your car,
to set the steering and throttle for your car, as well as entering
protect mode and throwing spare tires.
enterProtectMode
public boolean enterProtectMode()
- Enter protect mode. This will sheild your car from spare tires,
but you will use twice the amount of fuel. Protect mode lasts for
50 clock ticks.
- Returns:
- boolean - true if the car entered protect mode, and false
if the car was already in protect mode.
getChangeInHeading
public int getChangeInHeading()
- Description copied from interface:
ICar
- Returns the current change of heading of the car, in degrees per turn.
This method returns a positive number if the car is turning right, and
a negative number if the car is turning left.
- Specified by:
getChangeInHeading
in interface ICar
- See Also:
ICar.getChangeInHeading()
getCheckpoints
public IObject[] getCheckpoints()
- Returns a list of checkpoints that you can pass to gain points.
- Returns:
- com.ibm.rally.IObject[]
getClockTicks
public int getClockTicks()
- Returns the number of clock ticks (turns) that have occurred
during this match.
- Returns:
- int
getColor
public abstract byte getColor()
- Returns the color of your car. This method should return one of the
six CAR_XXX color constants and will only be called once during
initialization.
- Returns:
- byte
getDistanceTo
public double getDistanceTo(double x,
double y)
- Description copied from interface:
IObject
- Returns the distance to the given location.
- Specified by:
getDistanceTo
in interface IObject
- See Also:
IObject.getDistanceTo(double, double)
getDistanceTo
public double getDistanceTo(IObject obj)
- Description copied from interface:
IObject
- Returns the distance to the given object.
- Specified by:
getDistanceTo
in interface IObject
- See Also:
IObject.getDistanceTo(IObject)
getFuel
public int getFuel()
- Description copied from interface:
ICar
- Returns the amount of fuel remaining in the car.
- Specified by:
getFuel
in interface ICar
- See Also:
ICar.getFuel()
getFuelDepots
public IObject[] getFuelDepots()
- Returns the available fuel depots for this match. When you are
within 20 units of a fuel depot, your car will gain fuel.
- Returns:
- com.ibm.rally.IObject[]
getHeading
public int getHeading()
- Description copied from interface:
ICar
- Return the car's heading, in degrees.
- Specified by:
getHeading
in interface ICar
- See Also:
ICar.getHeading()
getHeadingTo
public int getHeadingTo(double x,
double y)
- Description copied from interface:
IObject
- Returns the heading (angle) to the given location.
- Specified by:
getHeadingTo
in interface IObject
- See Also:
IObject.getHeadingTo(double, double)
getHeadingTo
public int getHeadingTo(IObject obj)
- Description copied from interface:
IObject
- Returns the heading (angle) to the given object.
- Specified by:
getHeadingTo
in interface IObject
- See Also:
IObject.getHeadingTo(IObject)
getName
public java.lang.String getName()
- Returns the name of your car.
- Specified by:
getName
in interface ICar
- Returns:
- java.lang.String
getNumberOfSpareTires
public int getNumberOfSpareTires()
- Description copied from interface:
ICar
- Returns the number of spare tires currently available to be
thrown from this car.
- Specified by:
getNumberOfSpareTires
in interface ICar
- See Also:
ICar.getNumberOfSpareTires()
getOpponents
public ICar[] getOpponents()
- Returns an array of all the cars that you are currently competing
against in this match. This array will not include your own car, and
will always return the cars in the same order.
- Returns:
- ICar[]
getPoints
public int getPoints()
- Description copied from interface:
ICar
- Returns the number of points that this car has accumulated
during this match.
- Specified by:
getPoints
in interface ICar
- See Also:
ICar.getPoints()
getPreviousCheckpoint
public int getPreviousCheckpoint()
- Returns the index of the previous checkpoint that was reached, or -1
if the car has not passed any checkpoints yet during this match. You
can go to checkpoints in any order, but you will get more points if
you go to the next checkpoint in the list.
- Returns:
- int
getOrganization
public abstract java.lang.String getOrganization()
- Return the name of your organization.
- Specified by:
getOrganization
in interface ICar
- Returns:
- java.lang.String
getSpareTireDepot
public IObject[] getSpareTireDepot()
- Returns the available spare tire depots for this match. When you are
within 20 units of a spare tire depot, your car will gain a spare tire
every 25 ticks.
- Returns:
- com.ibm.rally.IObject[]
getSpareTiresOnTrack
public ISpareTire[] getSpareTiresOnTrack()
- Returns the spare tires that have been thrown but have not yet hit a
wall or another car.
- Returns:
- com.ibm.rally.ISpareTire[]
getSpeed
public double getSpeed()
- Description copied from interface:
ICar
- Return the car's current speed, in units per turn. This method
returns the speed in the direction in which the car is heading,
so the car may move (e.g. as the result of being hit sideways
by another car) without the speed changing. This method will
return a negative value if the car is going backwards.
- Specified by:
getSpeed
in interface ICar
- See Also:
ICar.getSpeed()
getSteeringSetting
public int getSteeringSetting()
- Returns the steering setting for this car. The steering setting
will affect the turn rate of the car.
- Returns:
- int;
getThrottle
public int getThrottle()
getTrackHeight
public int getTrackHeight()
- Returns the height of the track, in units.
- Returns:
- int
getTrackWidth
public int getTrackWidth()
- Returns the width of the track, in units.
- Returns:
- int
getX
public double getX()
- Description copied from interface:
IObject
- Return the X position.
- Specified by:
getX
in interface IObject
- See Also:
IObject.getX()
getY
public double getY()
- Description copied from interface:
IObject
- Return the Y position.
- Specified by:
getY
in interface IObject
- See Also:
IObject.getY()
initialize
public abstract void initialize()
- Called to give you a chance to do initialization. This method
will be called at the beginning of each match, and you will
have a limited amount of time to do initialization.
isHeadlightsOn
public boolean isHeadlightsOn()
- Returns true if the car's headlights are on.
- Returns:
- boolean
isInProtectMode
public boolean isInProtectMode()
- Returns true if the car is in protect mode.
- Specified by:
isInProtectMode
in interface ICar
- Returns:
- boolean
isReadyToThrowSpareTire
public boolean isReadyToThrowSpareTire()
- Returns true if the car is ready to throw a spare tire, and false if
does not have any spare tires, or if it is not ready to throw again
after the last spare tire.
- Returns:
- boolean
move
public abstract void move(int lastMoveTime,
boolean hitWall,
ICar collidedWithCar,
ICar hitBySpareTire)
- This method is called repeatedly to allow you to move your car.
When you have run out of fuel, this method will no longer be called.
The first parameter returns the length of time (in ms) that the last call
to move() took.
The second parameter (hitWall) returns true if your car has just ran
into a wall. If your car has collided with another car, the third
parameter (collidedWithCar) will return that other car; otherwise this
parameter will be null. If you have just been hit by a spare tire from another
car, the fourth parameter (hitBySpareTire) returns that other car; otherwise
this parameter will be null.
- Parameters:
int
- lastMoveTimeboolean
- hitWallcom.ibm.rally.ICar
- collidedWithCarcom.ibm.rally.ICar
- hitBySpareTire
setHeadlightsOn
public void setHeadlightsOn(boolean on)
- Turn the car headlights on or off. There's no reason to do
this, but hey, why not?
- Parameters:
boolean
-
setSteeringSetting
public void setSteeringSetting(int steering)
- Set the steering setting. This must be somewhere between the
MAX_STEER_LEFT and MAX_STEER_RIGHT constants, and will affect the
car's rate of turn.
- Parameters:
steering
-
setThrottle
public void setThrottle(int throttle)
- Set the throttle (gas peddle) of the car. This must be somewhere
between the MIN_SPEED (reverse) and MAX_SPEED (full throttle)
constants. Increasing the throttle will make the car move faster,
but will also burn more fuel per unit travelled.
- Parameters:
throttle
-
throwSpareTire
public boolean throwSpareTire()
- Throw a spare tire out the front of the car. The spare tire will
be thrown in the same heading as the car is currently facing. You
can never be hit by a spare tire thrown by your car.
- Returns:
- boolean - true if the spare tire was thrown, and false if
the car did not have any remaining spare tires or was not ready
to throw again after the last thrown spare tire.