|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectPlayer
Class Player represents one player.
Contains the data regarding a player, his/her boat, player's status in the race and the functionality of the player's boat.
Vector2,
Serialized Form| Field Summary | |
private ClientInterface |
client
interface to the client object of this player |
private int |
cur_lap
Stores the lap the player is in. |
private int |
direction
direction of the player's boat in degrees |
private float |
dist_to_next_port
distance to the next gate to pass |
private boolean |
finished
has the player reached the goal |
private Game |
game
player's current race |
private int |
id
player's unique id |
private java.lang.String |
name
player's name |
private int |
next_port
the next gate to pass |
(package private) Vector2 |
pos
position of the player's boat |
private int |
sail_value
openness of the sail, an integer in range 0..100 |
| Constructor Summary | |
Player(int id,
java.lang.String name,
ClientInterface cobj)
Constructor. |
|
| Method Summary | |
int |
calcSailDirection(int wind_direction)
Calculates the direction of the sail in relation to the world. |
float |
calcWindPush(int wind_direction,
int wind_velocity)
Calculates the force pushing the boat forward. |
ClientInterface |
getClient()
Returns the interface of the player's client object. |
int |
getCurLap()
Returns the lap the player is in. |
int |
getDirection()
Returns the movement angle of the player's boat. |
Vector2 |
getDirectionVector()
Returns the movement direction vector of the player's boat. |
float |
getDistToNextPort()
Returns the distance to the next gate. |
Game |
getGame()
Returns the race the player is in. |
int |
getId()
Returns the unique id of the player. |
java.lang.String |
getName()
Returns the name of the player. |
int |
getNextPort()
Returns the number of the gate the player must pass through next. |
Vector2 |
getPosition()
Returns a copy of the position vector of the player's boat. |
boolean |
isFinished()
Returns the value of finished. |
void |
move(float seconds,
int wind_direction,
int wind_velocity)
Moves the boat for a certain timeslice. |
void |
passedPort(int passed_port,
int ports_in_track)
Tells the player (s)he has just passed a gate. |
void |
preparePlayerToRace(Game game,
int grid_pos)
Prepares the player for a race. |
private void |
readObject(java.io.ObjectInputStream in)
Reads an object form a stream. |
void |
setCurLap(int l)
Sets a new lap number to the player. |
void |
setDirection(int dir)
Sets the movement direction of the player's boat. |
void |
setDistToNextPort(Vector2 v)
Calculates the disctance between the player's boat and a given location (the next gate). |
void |
setFinished(boolean flag)
Sets the value of finished. |
void |
setGame(Game g)
Joins the player in a race. |
void |
setNextPort(int p)
Sets the next gate the player must pass through. |
void |
setPosition(float x,
float y)
Sets the coordinates of the player's boat. |
void |
setPosition(Vector2 v)
Sets the position vector of the player's boat. |
void |
setSailValue(int pa)
Adjusts the position of the player's sail. |
void |
turnLeft()
Rotates the player's boat to portboard. |
void |
turnRight()
Rotates the player's boat to starboard. |
private void |
writeObject(java.io.ObjectOutputStream out)
Writes an object to a stream. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
Vector2 pos
private int direction
private int sail_value
private int id
private java.lang.String name
private Game game
private ClientInterface client
private int cur_lap
Lap 1 is the first lap.
At start, before the player has crossed the starting line, lap == 0.
private int next_port
private float dist_to_next_port
private boolean finished
| Constructor Detail |
public Player(int id,
java.lang.String name,
ClientInterface cobj)
id - the unique id of the playername - the name of the playercobj - the interface of the player's client object| Method Detail |
public ClientInterface getClient()
public void setGame(Game g)
g - the race the player joined in.public Game getGame()
NULL if the player is
not in a race.public void setFinished(boolean flag)
finished.
flag - the new value of finishedpublic boolean isFinished()
finished.
finished.public void turnLeft()
public void turnRight()
public void setSailValue(int pa)
pa - An integer that defines the position of the sail.
public void setPosition(float x,
float y)
x - the new x coordinate of the boaty - the new y coordinate of the boatpublic void setPosition(Vector2 v)
v - the new position vector of the player's boatpublic void setDirection(int dir)
dir - The new movement direction of the boat, an angle in
two-dimensional plane in degrees.public Vector2 getPosition()
public int getDirection()
public int getId()
public java.lang.String getName()
public void setNextPort(int p)
p - the number of the next gate to pass, in range [0...num_ports-1]public int getNextPort()
public void setCurLap(int l)
l - the number of the lap the player is moving intopublic int getCurLap()
public void setDistToNextPort(Vector2 v)
The result is saved in an attribute and can be requested through the
method getDistToNextPort().
v - the location of the next gatepublic float getDistToNextPort()
public float calcWindPush(int wind_direction,
int wind_velocity)
The force is affected by the direction and velocity of the wind together with the direction of the boat and the position of the sail.
wind_direction - the direction of the wind in degreeswind_velocity - the velocity of the wind in m/s
public int calcSailDirection(int wind_direction)
Needed e.g. to draw the sail correctly.
The direction of the sail is measured outwards from the mast.
wind_direction - The direction of the wind in degrees. This affects to
the direction of the sail, since the sail is below
the wind when it's loose.
public void move(float seconds,
int wind_direction,
int wind_velocity)
seconds - the timeslice to move the boat for (in seconds)wind_direction - the direction of the wind in degreeswind_velocity - the velocity of the wind in m/s
public void passedPort(int passed_port,
int ports_in_track)
passed_port - the number of the passed gate, in range [0...num_ports-1]ports_in_track - the number of gates to pass in one lap
public void preparePlayerToRace(Game game,
int grid_pos)
game - the object of the race the player is racing ingrid_pos - the number of the player's starting grid, according to
which the player is placed in the correct position
before the gate.public Vector2 getDirectionVector()
private void writeObject(java.io.ObjectOutputStream out)
throws java.io.IOException
out - ObjectOutputStream to write to
java.io.IOException
private void readObject(java.io.ObjectInputStream in)
throws java.io.IOException,
java.lang.ClassNotFoundException
in - ObjectInputStream to read from
java.io.IOException
java.lang.ClassNotFoundException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||