hockey.api
Class Player

java.lang.Object
  |
  +--hockey.api.Player
All Implemented Interfaces:
IObject, IPlayer, IPlayerControl
Direct Known Subclasses:
GoalKeeper

public abstract class Player
extends java.lang.Object
implements IPlayer, IPlayerControl

Every player in your team should extend this class!

It implements the IPlayer and IPlayerControl interfaces to give you full control and information of the player. Additionally it has some methods you must define to give information about your player, and some convenience methods for easier control.

There are seven abstract methods that must be implemented. Most important is the step method that controls your player.

See Also:
IObject, IPlayer, IPlayerControl

Field Summary
 
Fields inherited from interface hockey.api.IPlayerControl
ACCELERATION, MAX_SHOT_SPEED, MAX_SPEED, MAX_STICK_ANGLE, MAX_STICK_R, MAX_TURN_SPEED, MIN_STICK_ANGLE, MIN_STICK_R
 
Constructor Summary
Player()
           
 
Method Summary
 void faceOff()
          Called before step when there is a face-off.
 boolean getAimOnStick()
          The aimOnStick property controls whether the endpoint of the stick or the body position should used when moving to a target position.
 IGoalKeeper getGoalKeeper(int index)
          Gets a goal-keeper from the game.
 int getHeading()
          Returns the absolute heading in degrees.
 int getIndex()
          Returns this player's index.
abstract  java.lang.String getName()
          The name of the player.
abstract  int getNumber()
          The number of the player.
 IPlayer getPlayer(int index)
          Gets a player from the game.
 IPuck getPuck()
          Gets the puck from the game.
 int getScore(boolean myScore)
          Gets the current score of one of the teams.
 int getSpeed()
          Returns the speed in cm/s.
 IObject getStick()
          Returns the current position of the player's stick, as an IObject.
 int getStickAngle()
          Returns the stick relative angle relative to the player's heading, in degrees.
 int getStickR()
          Returns the stick distace from the player's centre, in cm.
 int getStickX()
          Returns the x-coordinate of the player's stick, in cm.
 int getStickY()
          Returns the y-coordinate of the player's stick, in cm.
 int getTargetHeading()
          Returns the target heading, in degrees.
 int getTargetSpeed()
          Returns the target speed, in cm/s.
 int getTargetStickAngle()
          Returns the target stick relative angle from player's heading, in degrees.
 int getTargetStickR()
          Returns the target stick distance from player's centre, in degrees.
 int getTurnSpeed()
          Returns the turn speed, in degrees/s.
 int getX()
          Returns the x-coordinate in cm.
 int getY()
          Returns the y-coordinate in cm.
 boolean hasPuck()
          Returns whether this player has the puck.
 void init()
          Initialise the player.
abstract  boolean isLeftHanded()
          Whether the player is left-handed.
 boolean isOpponent()
          Returns whether this player is your opponent in the game.
 void moveStick(int dir, int dist)
          Move the stick to a given angle and distance relative to the player.
 void penaltyShot()
          Called before step when the player is about to take a penalty-shot.
 void setAimOnStick(boolean aos)
          The aimOnStick property controls whether the endpoint of the stick or the body position should used when moving to a target position.
 void setDebugPoint(int x, int y, java.awt.Color c)
          Sets a point displayed in the HDE.
 void setMessage(java.lang.String message)
          Sets the message displayed in the HDE.
 void setPlayerControl(IPlayer impl, IPlayerControl ctrl)
          This method is used internally to receive the IPlayer and IPlayerControl associated with this player.
 void shoot(int heading, int speed)
          Shoot the puck in a given absolute heading and speed.
 void shoot(int x, int y, int speed)
          Shoot the puck towards a given position with a given speed.
 void shoot(IObject o, int speed)
          Shoot the puck towards a given IObject with a given speed.
 void showDebugPoint(boolean show)
          Sets whether the debug point should be shown.
 void skate(int speed)
          Accelerate to a given speed.
 void skate(int x, int y, int speed)
          Accelerate to a given speed and turn towards a given position with maximum turn speed.
 void skate(IObject o, int speed)
          Accelerate to a given speed and turn towards a given IObject with maximum turn speed.
abstract  void step()
          Called every time step.
 void turn(int dir, int turnSpeed)
          Turn towards a given angle with a given turn speed.
 void turn(int x, int y, int turnSpeed)
          Turn towards a given position with a given turn speed.
 void turn(IObject o, int turnSpeed)
          Turn towards a given IObject with a given turn speed.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Player

public Player()
Method Detail

setPlayerControl

public final void setPlayerControl(IPlayer impl,
                                   IPlayerControl ctrl)
This method is used internally to receive the IPlayer and IPlayerControl associated with this player.

Parameters:
impl - the player's IPlayer.
ctrl - the player's IPlayerControl.

getNumber

public abstract int getNumber()
The number of the player. Numbers should be in the range 0-99.


getName

public abstract java.lang.String getName()
The name of the player.


isLeftHanded

public abstract boolean isLeftHanded()
Whether the player is left-handed.

Specified by:
isLeftHanded in interface IPlayer

init

public void init()
Initialise the player. (Here it is OK to use the API functions.)


faceOff

public void faceOff()
Called before step when there is a face-off.


penaltyShot

public void penaltyShot()
Called before step when the player is about to take a penalty-shot.


step

public abstract void step()
                   throws java.lang.Exception
Called every time step. This is where you put your player control code.

java.lang.Exception

getX

public int getX()
Description copied from interface: IObject
Returns the x-coordinate in cm.

Specified by:
getX in interface IObject
Returns:
the x-coordinate, in cm.

getY

public int getY()
Description copied from interface: IObject
Returns the y-coordinate in cm.

Specified by:
getY in interface IObject
Returns:
the y-coordinate, in cm.

getHeading

public int getHeading()
Description copied from interface: IObject
Returns the absolute heading in degrees.

Specified by:
getHeading in interface IObject
Returns:
the absolute heading, in degrees.

getSpeed

public int getSpeed()
Description copied from interface: IObject
Returns the speed in cm/s.

Specified by:
getSpeed in interface IObject
Returns:
the speed, in cm/s.

getStickAngle

public int getStickAngle()
Description copied from interface: IPlayer
Returns the stick relative angle relative to the player's heading, in degrees.

Specified by:
getStickAngle in interface IPlayer

getStickR

public int getStickR()
Description copied from interface: IPlayer
Returns the stick distace from the player's centre, in cm.

Specified by:
getStickR in interface IPlayer

getStickX

public int getStickX()
Description copied from interface: IPlayer
Returns the x-coordinate of the player's stick, in cm.

Specified by:
getStickX in interface IPlayer

getStickY

public int getStickY()
Description copied from interface: IPlayer
Returns the y-coordinate of the player's stick, in cm.

Specified by:
getStickY in interface IPlayer

getStick

public IObject getStick()
Description copied from interface: IPlayer
Returns the current position of the player's stick, as an IObject.

Specified by:
getStick in interface IPlayer

isOpponent

public boolean isOpponent()
Description copied from interface: IPlayer
Returns whether this player is your opponent in the game.

Specified by:
isOpponent in interface IPlayer

hasPuck

public boolean hasPuck()
Description copied from interface: IPlayer
Returns whether this player has the puck.

Specified by:
hasPuck in interface IPlayer

getIndex

public int getIndex()
Description copied from interface: IPlayer
Returns this player's index. The indices are:

Specified by:
getIndex in interface IPlayer

getAimOnStick

public boolean getAimOnStick()
Description copied from interface: IPlayerControl
The aimOnStick property controls whether the endpoint of the stick or the body position should used when moving to a target position.

Specified by:
getAimOnStick in interface IPlayerControl

getTargetSpeed

public int getTargetSpeed()
Description copied from interface: IPlayerControl
Returns the target speed, in cm/s.

Specified by:
getTargetSpeed in interface IPlayerControl

getTargetHeading

public int getTargetHeading()
Description copied from interface: IPlayerControl
Returns the target heading, in degrees.

Specified by:
getTargetHeading in interface IPlayerControl

getTurnSpeed

public int getTurnSpeed()
Description copied from interface: IPlayerControl
Returns the turn speed, in degrees/s.

Specified by:
getTurnSpeed in interface IPlayerControl

getTargetStickAngle

public int getTargetStickAngle()
Description copied from interface: IPlayerControl
Returns the target stick relative angle from player's heading, in degrees.

Specified by:
getTargetStickAngle in interface IPlayerControl

getTargetStickR

public int getTargetStickR()
Description copied from interface: IPlayerControl
Returns the target stick distance from player's centre, in degrees.

Specified by:
getTargetStickR in interface IPlayerControl

setAimOnStick

public void setAimOnStick(boolean aos)
Description copied from interface: IPlayerControl
The aimOnStick property controls whether the endpoint of the stick or the body position should used when moving to a target position.

Specified by:
setAimOnStick in interface IPlayerControl

skate

public void skate(int speed)
Description copied from interface: IPlayerControl
Accelerate to a given speed.

Specified by:
skate in interface IPlayerControl

skate

public void skate(int x,
                  int y,
                  int speed)
Accelerate to a given speed and turn towards a given position with maximum turn speed.


skate

public void skate(IObject o,
                  int speed)
Accelerate to a given speed and turn towards a given IObject with maximum turn speed.


turn

public void turn(int dir,
                 int turnSpeed)
Description copied from interface: IPlayerControl
Turn towards a given angle with a given turn speed.

Specified by:
turn in interface IPlayerControl

turn

public void turn(int x,
                 int y,
                 int turnSpeed)
Turn towards a given position with a given turn speed.


turn

public void turn(IObject o,
                 int turnSpeed)
Turn towards a given IObject with a given turn speed.


moveStick

public void moveStick(int dir,
                      int dist)
Description copied from interface: IPlayerControl
Move the stick to a given angle and distance relative to the player.

Specified by:
moveStick in interface IPlayerControl

shoot

public void shoot(int heading,
                  int speed)
Description copied from interface: IPlayerControl
Shoot the puck in a given absolute heading and speed.

Specified by:
shoot in interface IPlayerControl

shoot

public void shoot(int x,
                  int y,
                  int speed)
Shoot the puck towards a given position with a given speed.


shoot

public void shoot(IObject o,
                  int speed)
Shoot the puck towards a given IObject with a given speed.


getScore

public int getScore(boolean myScore)
Description copied from interface: IPlayerControl
Gets the current score of one of the teams.

Specified by:
getScore in interface IPlayerControl
Parameters:
myScore - whether you want your own score or your opponent's score.

getPuck

public IPuck getPuck()
Description copied from interface: IPlayerControl
Gets the puck from the game.

Specified by:
getPuck in interface IPlayerControl

getGoalKeeper

public IGoalKeeper getGoalKeeper(int index)
Description copied from interface: IPlayerControl
Gets a goal-keeper from the game.

Specified by:
getGoalKeeper in interface IPlayerControl
Parameters:
index - the index of the goal-keeper:
  • 0 - Your own goal-keeper.
  • 6 - Your opponent's goal-keeper.

getPlayer

public IPlayer getPlayer(int index)
Description copied from interface: IPlayerControl
Gets a player from the game.

Specified by:
getPlayer in interface IPlayerControl
Parameters:
index - the index of the player. The indices are:
  • Your own
    • 0 - goal-keeper.
    • 1 - left defender.
    • 2 - right defender.
    • 3 - left forward.
    • 4 - right forward.
    • 5 - centre forward.
  • Your opponent's
    • 6 - goal-keeper.
    • 7 - left defender.
    • 8 - right defender.
    • 9 - left forward.
    • 10 - right forward.
    • 11 - centre forward.

setMessage

public void setMessage(java.lang.String message)
Description copied from interface: IPlayerControl
Sets the message displayed in the HDE. You should use this function instead of writing to System.out.

Specified by:
setMessage in interface IPlayerControl
Parameters:
message - the message.

setDebugPoint

public void setDebugPoint(int x,
                          int y,
                          java.awt.Color c)
Description copied from interface: IPlayerControl
Sets a point displayed in the HDE. This is very useful for debugging.

Specified by:
setDebugPoint in interface IPlayerControl

showDebugPoint

public void showDebugPoint(boolean show)
Description copied from interface: IPlayerControl
Sets whether the debug point should be shown.

Specified by:
showDebugPoint in interface IPlayerControl