Class Track

java.lang.Object
  extended byTrack
All Implemented Interfaces:
java.io.Serializable

public class Track
extends java.lang.Object
implements java.io.Serializable

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

Version:
1.0
Author:
Stefan Brockmann, Tero Kuusela
See Also:
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

name

private java.lang.String name
track name


laps

private int laps
how many laps a race sailed on this track lasts


maxDuration

private int maxDuration
maximum duration of a race sailed on this track in seconds


ports

private Port[] ports
gates of this track in an array


windChangeInterval

private int windChangeInterval
how often to change the wind direction and velocity in seconds


minWindDirection

private int minWindDirection
minimum direction of the wind in degrees


maxWindDirection

private int maxWindDirection
maximum direction of the wind in degrees


minWindVelocity

private int minWindVelocity
minimum velocity of the wind in m/s


maxWindVelocity

private int maxWindVelocity
maximum velocity of the wind in m/s

Constructor Detail

Track

public Track()
Default constructor.

Method Detail

setName

public void setName(java.lang.String n)
Sets the name attribute.


setNumberOfLaps

public void setNumberOfLaps(int l)
Sets the laps attribute.


setMaxGameDuration

public void setMaxGameDuration(int md)
Sets the maxDuration attribute.


setMinWindDirection

public void setMinWindDirection(int mwd)
Sets the minWindDirection attribute.


setMinWindVelocity

public void setMinWindVelocity(int mwv)
Sets the minWindVelocity attribute.


setMaxWindDirection

public void setMaxWindDirection(int mwd)
Sets the maxWindDirection attribute.


setMaxWindVelocity

public void setMaxWindVelocity(int mwv)
Sets the maxWindVelocity attribute.


setWindChangeInterval

public void setWindChangeInterval(int wci)
Sets the windChangeInterval attribute.


initPorts

public void initPorts(int num)
Initialises the gates by reserving memory for them.

Parameters:
num - how many gates to reserve memory for

addPort

public void addPort(int i,
                    Vector2 pb,
                    Vector2 sb)
Adds a gate.

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.

Parameters:
i - gate number
pb - portboard buoy
sb - starboard buoy

getName

public java.lang.String getName()
Returns the name attribute


getNumberOfLaps

public int getNumberOfLaps()
Returns the laps attribute


getMaxGameDuration

public int getMaxGameDuration()
Returns the maxDuration attribute


getMinWindDirection

public int getMinWindDirection()
Returns the minWindDirection attribute


getMinWindVelocity

public int getMinWindVelocity()
Returns the minWindVelocity attribute


getMaxWindDirection

public int getMaxWindDirection()
Returns the maxWindDirection attribute


getMaxWindVelocity

public int getMaxWindVelocity()
Returns the maxWindVelocity attribute


getWindChangeInterval

public int getWindChangeInterval()
Returns the windChangeInterval attribute


getPortPB

public Vector2 getPortPB(int i)
Returns the location of the portboard buoy of the given gate.

Parameters:
i - gate number
Returns:
Location of the portboard buoy.

getPortSB

public Vector2 getPortSB(int i)
Returns the location of the starboard buoy of the given gate.

Parameters:
i - gate number
Returns:
Location of the starboard buoy.

getPortCount

public int getPortCount()
Returns the number of gates in this track.

Returns:
Number of gates in this track.

writeObject

private void writeObject(java.io.ObjectOutputStream out)
                  throws java.io.IOException
Writes an object in the given stream.

Throws:
java.io.IOException

readObject

private void readObject(java.io.ObjectInputStream in)
                 throws java.io.IOException,
                        java.lang.ClassNotFoundException
Reads an object from the given stream.

Throws:
java.io.IOException
java.lang.ClassNotFoundException

passedPort

public boolean passedPort(int port_id,
                          Vector2 p1,
                          Vector2 p2)
Check if the line segment (p1-<p2) passed the port_id:th gate.

The direction does matter!

Parameters:
port_id - number of the gate to check against
p1 - startpoint of the line segment
p2 - endpoint of the line segment
Returns:
true if the line segment passed the gate, false if it didn't.

move

public void move(float seconds)
Moves all the gates as needed.

Parameters:
seconds - time interval to move for in seconds

crashWithPlayer

public void crashWithPlayer(Player p)
Checks and handles the player collisions to the gate buoys.

Parameters:
p - player whose collisions to check