fi.utu.cs.hockey.net
Class Client

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--fi.utu.cs.hockey.net.Client
All Implemented Interfaces:
Communication, Position, java.lang.Runnable
Direct Known Subclasses:
AI

public abstract class Client
extends java.lang.Thread
implements Communication

A hockey player client.


Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface fi.utu.cs.hockey.net.Communication
CENTER_SPOT, HEADING_ANGLE, NO_FACEOFF, OUR_ENDZONE_LEFT, OUR_ENDZONE_RIGHT, OUR_NEUTRAL_ZONE_LEFT, OUR_NEUTRAL_ZONE_RIGHT, THEIR_ENDZONE_LEFT, THEIR_ENDZONE_RIGHT, THEIR_NEUTRAL_ZONE_LEFT, THEIR_NEUTRAL_ZONE_RIGHT, X_COORDINATE, Y_COORDINATE
 
Fields inherited from interface fi.utu.cs.hockey.Position
CENTER, GOALKEEPER, LEFT_DEFENSE, LEFT_WING, RIGHT_DEFENSE, RIGHT_WING
 
Constructor Summary
protected Client()
          Creates a player client.
protected Client(java.lang.String s, java.lang.String t, int n, int p, java.awt.Color h, java.awt.Color j)
          Creates a player client with name s, team name t, number n, position p, helmet color h, and jersey color j.
 
Method Summary
 void brake(double p)
          Brakes (or dashes backwards) the player with the relative power p, where p is from the range [0.0, 1.0].
 void connect(java.lang.String sAddr, int sPort, int iPort, java.lang.String gAddr, int gPort)
          Connects to a game server.
 void dash(double p)
          Dashes the player with the relative power p, where p is from the range [0.0, 1.0].
 int faceoff()
          Returns the place of the faceoff.
 void finalize()
          Cleanup for the garbage collector.
 java.awt.Color getHelmetColor()
          Returns the color of the player's helmet.
 java.awt.Color getJerseyColor()
          Returns the color of the player's jersey.
 int getNumber()
          Returns the player's number.
 java.lang.String getPlayerName()
          Returns the player's name.
 int getPosition()
          Returns the player's position in the team.
 java.lang.String getTeamName()
          Returns the name of the player's team.
 void head(double a)
          Sets the player's heading to the angle a in radians.
 boolean isFoul(boolean us)
          Returns whether a team has caused some other foul.
 boolean isGameOver()
          Returns whether the game is over.
 boolean isGameStopped()
          Returns whether the game is stopped.
 boolean isGoal(boolean us)
          Returns whether a team has scored a goal.
 boolean isGoalieKeepingPuck(boolean us)
          Returns whether the goalkeeper of a team is keeping the puck.
 boolean isIcing(boolean us)
          Returns whether a team is in icing.
 boolean isInHomeTeam()
          Returns true if the player belongs to the home team; otherwise returns false.
 boolean isInterferingGoalie(boolean us)
          Returns whether any member of a team is interfering the other team's goalie.
 boolean isJoined()
          Returns true, if the player has joined a game.
 boolean isOffside(boolean us)
          Returns whether a team is in offside.
 boolean isPuckUnplayable()
          Returns true if the puck has become unplayable.
 void keepPuck()
          Keeps the puck, if the player is a goalkeeper.
 long[] messages(boolean us)
          Returns a team's messages.
 double[] player(boolean us, int p)
          Returns the location and the angle of the heading of a player.
 double[] puck()
          Returns the location of the puck.
 void say(long s)
          Says the 64-bit long word s.
 int score(boolean us)
          Returns the score of a team.
 void setHelmetColor(java.awt.Color h)
          Sets the name of the player's helmet to h.
 void setJerseyColor(java.awt.Color j)
          Sets the name of the player's jersey to j.
 void setNumber(int n)
          Sets the player's number to n.
 void setPlayerName(java.lang.String s)
          Sets the player's name to s.
 void setPosition(int p)
          Sets the player's position in the team to p.
 void setTeamName(java.lang.String t)
          Sets the name of the player's team to t.
 void shoot(double p)
          Shoots the puck with the relative power p, where p is from the range [0.0, 1.0].
 long time()
          Returns the time left in the game in milliseconds.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Client

protected Client()
Creates a player client.


Client

protected Client(java.lang.String s,
                 java.lang.String t,
                 int n,
                 int p,
                 java.awt.Color h,
                 java.awt.Color j)
Creates a player client with name s, team name t, number n, position p, helmet color h, and jersey color j.

Method Detail

finalize

public void finalize()
              throws java.lang.Throwable
Cleanup for the garbage collector.

Overrides:
finalize in class java.lang.Object
java.lang.Throwable

connect

public void connect(java.lang.String sAddr,
                    int sPort,
                    int iPort,
                    java.lang.String gAddr,
                    int gPort)
Connects to a game server. The server has two ports, one for initialization upon joining and one for client input throughout the game. The server sends output to a multicast group. Hence, parameter gAddr must be a D-class address (i.e., within the range 224.0.0.0-239.255.255.255). Preferably, it should be from the range 239.0.0.0-239.255.255.255 which is intended for local area network (LAN) use only.

Parameters:
sAddr - Server address
sPort - Server port for client input
iPort - Server port for client initialization
gAddr - Multicast group for server output
gPort - Multicast port

getPlayerName

public final java.lang.String getPlayerName()
Description copied from interface: Communication
Returns the player's name.

Specified by:
getPlayerName in interface Communication

setPlayerName

public final void setPlayerName(java.lang.String s)
Description copied from interface: Communication
Sets the player's name to s. After the player has joined a game, this method will have no effect.

Specified by:
setPlayerName in interface Communication
See Also:
Communication.isJoined()

getTeamName

public final java.lang.String getTeamName()
Description copied from interface: Communication
Returns the name of the player's team.

Specified by:
getTeamName in interface Communication

setTeamName

public final void setTeamName(java.lang.String t)
Description copied from interface: Communication
Sets the name of the player's team to t. After the player has joined a game, this method will have no effect.

Specified by:
setTeamName in interface Communication
See Also:
Communication.isJoined()

getNumber

public final int getNumber()
Description copied from interface: Communication
Returns the player's number.

Specified by:
getNumber in interface Communication

setNumber

public final void setNumber(int n)
Description copied from interface: Communication
Sets the player's number to n. The number should be from the range 1-99. After the player has joined a game, this method will have no effect.

Specified by:
setNumber in interface Communication
See Also:
Communication.isJoined()

getPosition

public final int getPosition()
Description copied from interface: Communication
Returns the player's position in the team.

Specified by:
getPosition in interface Communication
See Also:
Position.GOALKEEPER, Position.LEFT_DEFENSE, Position.RIGHT_DEFENSE, Position.LEFT_WING, Position.RIGHT_WING, Position.CENTER

setPosition

public final void setPosition(int p)
Description copied from interface: Communication
Sets the player's position in the team to p. After the player has joined a game, this method will have no effect.

Specified by:
setPosition in interface Communication
See Also:
Communication.isJoined(), Position.GOALKEEPER, Position.LEFT_DEFENSE, Position.RIGHT_DEFENSE, Position.LEFT_WING, Position.RIGHT_WING, Position.CENTER

getHelmetColor

public final java.awt.Color getHelmetColor()
Description copied from interface: Communication
Returns the color of the player's helmet.

Specified by:
getHelmetColor in interface Communication

setHelmetColor

public final void setHelmetColor(java.awt.Color h)
Description copied from interface: Communication
Sets the name of the player's helmet to h. After the player has joined a game, this method will have no effect.

Specified by:
setHelmetColor in interface Communication
See Also:
Communication.isJoined()

getJerseyColor

public final java.awt.Color getJerseyColor()
Description copied from interface: Communication
Returns the color of the player's jersey.

Specified by:
getJerseyColor in interface Communication

setJerseyColor

public final void setJerseyColor(java.awt.Color j)
Description copied from interface: Communication
Sets the name of the player's jersey to j. After the player has joined a game, this method will have no effect.

Specified by:
setJerseyColor in interface Communication
See Also:
Communication.isJoined()

isInHomeTeam

public final boolean isInHomeTeam()
Description copied from interface: Communication
Returns true if the player belongs to the home team; otherwise returns false. Before the player has joined a game, this method returns only false.

Specified by:
isInHomeTeam in interface Communication
See Also:
Communication.isJoined()

isJoined

public final boolean isJoined()
Description copied from interface: Communication
Returns true, if the player has joined a game. After joining, changes in name, number, position or colors have no effect.

Specified by:
isJoined in interface Communication
See Also:
Communication.setPlayerName(String), Communication.setTeamName(String), Communication.setNumber(int), Communication.setPosition(int), Communication.setHelmetColor(Color), Communication.setJerseyColor(Color)

shoot

public final void shoot(double p)
Description copied from interface: Communication
Shoots the puck with the relative power p, where p is from the range [0.0, 1.0].

Specified by:
shoot in interface Communication

dash

public final void dash(double p)
Description copied from interface: Communication
Dashes the player with the relative power p, where p is from the range [0.0, 1.0]. Methods dash and brake cancel out each other (i.e., only the last call will remain active).

Specified by:
dash in interface Communication
See Also:
Communication.brake(double)

brake

public final void brake(double p)
Description copied from interface: Communication
Brakes (or dashes backwards) the player with the relative power p, where p is from the range [0.0, 1.0]. Methods dash and brake cancel out each other (i.e., only the last call will remain active).

Specified by:
brake in interface Communication
See Also:
Communication.dash(double)

head

public final void head(double a)
Description copied from interface: Communication
Sets the player's heading to the angle a in radians.

Specified by:
head in interface Communication

say

public final void say(long s)
Description copied from interface: Communication
Says the 64-bit long word s. The message is received both by the own team and the opponent.

Specified by:
say in interface Communication

keepPuck

public final void keepPuck()
Description copied from interface: Communication
Keeps the puck, if the player is a goalkeeper. Cancels out any calls to the method shoot.

Specified by:
keepPuck in interface Communication
See Also:
Communication.shoot(double)

time

public final long time()
Description copied from interface: Communication
Returns the time left in the game in milliseconds.

Specified by:
time in interface Communication

isGameStopped

public final boolean isGameStopped()
Description copied from interface: Communication
Returns whether the game is stopped.

Specified by:
isGameStopped in interface Communication

isGameOver

public final boolean isGameOver()
Description copied from interface: Communication
Returns whether the game is over.

Specified by:
isGameOver in interface Communication

score

public final int score(boolean us)
Description copied from interface: Communication
Returns the score of a team. If us == true, the team is own, otherwise the team is opponent.

Specified by:
score in interface Communication

puck

public final double[] puck()
Description copied from interface: Communication
Returns the location of the puck.

Specified by:
puck in interface Communication
See Also:
Communication.X_COORDINATE, Communication.Y_COORDINATE

player

public final double[] player(boolean us,
                             int p)
Description copied from interface: Communication
Returns the location and the angle of the heading of a player. If us == true, the player is in the own team, otherwise in the opponent team. The parameter p indicates the position of the player. For example, the player's own position can be retrieved with the method call double[] s = player(true, getPosition()). Now, the player is in the coordinate position (s[X_COORDINATE], s[Y_COORDINATE]) and has the heading s[HEADING_ANGLE] in radians.

Specified by:
player in interface Communication
See Also:
Communication.X_COORDINATE, Communication.Y_COORDINATE, Communication.HEADING_ANGLE

messages

public final long[] messages(boolean us)
Description copied from interface: Communication
Returns a team's messages. If us == true, the messages originate from the own team, otherwise fromthe opponent team. For example, the message from the own team's goalkeeper can be retrieved with the method call long msg = messages(true)[GOALKEEPER].

Specified by:
messages in interface Communication

faceoff

public final int faceoff()
Description copied from interface: Communication
Returns the place of the faceoff.

Specified by:
faceoff in interface Communication
See Also:
Communication.NO_FACEOFF, Communication.CENTER_SPOT, Communication.OUR_ENDZONE_LEFT, Communication.OUR_ENDZONE_RIGHT, Communication.OUR_NEUTRAL_ZONE_LEFT, Communication.OUR_NEUTRAL_ZONE_RIGHT, Communication.THEIR_NEUTRAL_ZONE_LEFT, Communication.THEIR_NEUTRAL_ZONE_RIGHT, Communication.THEIR_ENDZONE_LEFT, Communication.THEIR_ENDZONE_RIGHT

isGoal

public final boolean isGoal(boolean us)
Description copied from interface: Communication
Returns whether a team has scored a goal. If us == true, the team is own, otherwise the team is opponent.

Specified by:
isGoal in interface Communication

isIcing

public final boolean isIcing(boolean us)
Description copied from interface: Communication
Returns whether a team is in icing. If us == true, the team is own, otherwise the team is opponent.

Specified by:
isIcing in interface Communication

isOffside

public final boolean isOffside(boolean us)
Description copied from interface: Communication
Returns whether a team is in offside. If us == true, the team is own, otherwise the team is opponent.

Specified by:
isOffside in interface Communication

isInterferingGoalie

public final boolean isInterferingGoalie(boolean us)
Description copied from interface: Communication
Returns whether any member of a team is interfering the other team's goalie. If us == true, the team is own, otherwise the team is opponent.

Specified by:
isInterferingGoalie in interface Communication

isGoalieKeepingPuck

public final boolean isGoalieKeepingPuck(boolean us)
Description copied from interface: Communication
Returns whether the goalkeeper of a team is keeping the puck. If us == true, the team is own, otherwise the team is opponent.

Specified by:
isGoalieKeepingPuck in interface Communication

isFoul

public final boolean isFoul(boolean us)
Description copied from interface: Communication
Returns whether a team has caused some other foul. If us == true, the team is own, otherwise the team is opponent.

Specified by:
isFoul in interface Communication

isPuckUnplayable

public final boolean isPuckUnplayable()
Description copied from interface: Communication
Returns true if the puck has become unplayable.

Specified by:
isPuckUnplayable in interface Communication