|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectTrack
Class Track represents a track/course in the game.
A track contains a group of gates (which the player must pass through in
correct order), track name, number of laps, maximum duration of a race and
knowledge of wind velocity, direction and variation frequency. The track
is read from a file using TrackFileParser.
Format of a track file:
#This is a comment
TRACK;Default # track name (here "Default")
LAPS;1 # how many laps to sail in a race
MAXTIME;300 # maximum duration of a race in seconds
CHANGEWIND;10 # change frequency of the wind velocity and direction in
# seconds
MINWINDD;10 # minimum wind direction in degrees
MAXWINDD;40 # maximum wind direction in degrees
MINWINDV;10 # minimum wind velocity in m/s
MAXWINDV;20 # maximum wind velocity in m/s
NUMPORTS;5 # number of gates
# NUMPORTS gates defined like this:
# PORT;left_x;left_y;right_x;right_y
PORT;10;40;30;-10
PORT;160;50;170;10
PORT;150;100;170;130
PORT;50;80;30;100
PORT;-100;30;-140;30
TrackFileParser,
Game,
Vector2,
Port,
Serialized Form| Field Summary | |
private int |
laps
how many laps a race sailed on this track lasts |
private int |
maxDuration
maximum duration of a race sailed on this track in seconds |
private int |
maxWindDirection
maximum direction of the wind in degrees |
private int |
maxWindVelocity
maximum velocity of the wind in m/s |
private int |
minWindDirection
minimum direction of the wind in degrees |
private int |
minWindVelocity
minimum velocity of the wind in m/s |
private java.lang.String |
name
track name |
private Port[] |
ports
gates of this track in an array |
private int |
windChangeInterval
how often to change the wind direction and velocity in seconds |
| Constructor Summary | |
Track()
Default constructor. |
|
| Method Summary | |
void |
addPort(int i,
Vector2 pb,
Vector2 sb)
Adds a gate. |
void |
crashWithPlayer(Player p)
Checks and handles the player collisions to the gate buoys. |
int |
getMaxGameDuration()
Returns the maxDuration attribute |
int |
getMaxWindDirection()
Returns the maxWindDirection attribute |
int |
getMaxWindVelocity()
Returns the maxWindVelocity attribute |
int |
getMinWindDirection()
Returns the minWindDirection attribute |
int |
getMinWindVelocity()
Returns the minWindVelocity attribute |
java.lang.String |
getName()
Returns the name attribute |
int |
getNumberOfLaps()
Returns the laps attribute |
int |
getPortCount()
Returns the number of gates in this track. |
Vector2 |
getPortPB(int i)
Returns the location of the portboard buoy of the given gate. |
Vector2 |
getPortSB(int i)
Returns the location of the starboard buoy of the given gate. |
int |
getWindChangeInterval()
Returns the windChangeInterval attribute |
void |
initPorts(int num)
Initialises the gates by reserving memory for them. |
void |
move(float seconds)
Moves all the gates as needed. |
boolean |
passedPort(int port_id,
Vector2 p1,
Vector2 p2)
Check if the line segment (p1-<p2) passed the port_id:th gate. |
private void |
readObject(java.io.ObjectInputStream in)
Reads an object from the given stream. |
void |
setMaxGameDuration(int md)
Sets the maxDuration attribute. |
void |
setMaxWindDirection(int mwd)
Sets the maxWindDirection attribute. |
void |
setMaxWindVelocity(int mwv)
Sets the maxWindVelocity attribute. |
void |
setMinWindDirection(int mwd)
Sets the minWindDirection attribute. |
void |
setMinWindVelocity(int mwv)
Sets the minWindVelocity attribute. |
void |
setName(java.lang.String n)
Sets the name attribute. |
void |
setNumberOfLaps(int l)
Sets the laps attribute. |
void |
setWindChangeInterval(int wci)
Sets the windChangeInterval attribute. |
private void |
writeObject(java.io.ObjectOutputStream out)
Writes an object in the given stream. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
private java.lang.String name
private int laps
private int maxDuration
private Port[] ports
private int windChangeInterval
private int minWindDirection
private int maxWindDirection
private int minWindVelocity
private int maxWindVelocity
| Constructor Detail |
public Track()
| Method Detail |
public void setName(java.lang.String n)
public void setNumberOfLaps(int l)
public void setMaxGameDuration(int md)
public void setMinWindDirection(int mwd)
public void setMinWindVelocity(int mwv)
public void setMaxWindDirection(int mwd)
public void setMaxWindVelocity(int mwv)
public void setWindChangeInterval(int wci)
public void initPorts(int num)
num - how many gates to reserve memory for
public void addPort(int i,
Vector2 pb,
Vector2 sb)
Receives as a parameter the number of the gate and the x and y
coordinates of both the starboard and portboard buoys as a
Vector2.
i - gate numberpb - portboard buoysb - starboard buoypublic java.lang.String getName()
public int getNumberOfLaps()
public int getMaxGameDuration()
public int getMinWindDirection()
public int getMinWindVelocity()
public int getMaxWindDirection()
public int getMaxWindVelocity()
public int getWindChangeInterval()
public Vector2 getPortPB(int i)
i - gate number
public Vector2 getPortSB(int i)
i - gate number
public int getPortCount()
private void writeObject(java.io.ObjectOutputStream out)
throws java.io.IOException
java.io.IOException
private void readObject(java.io.ObjectInputStream in)
throws java.io.IOException,
java.lang.ClassNotFoundException
java.io.IOException
java.lang.ClassNotFoundException
public boolean passedPort(int port_id,
Vector2 p1,
Vector2 p2)
The direction does matter!
port_id - number of the gate to check againstp1 - startpoint of the line segmentp2 - endpoint of the line segment
public void move(float seconds)
seconds - time interval to move for in secondspublic void crashWithPlayer(Player p)
p - player whose collisions to check
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||