|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.ObjectGame
Class Game runs one race.
The race can have two states, racing or not racing (attribute
is_racing. If the race isn't in a racing state, all player boats
wait at the starting line for the master player to begin the race. When this
happens, the race switches to the racing state. The race runs in it's own
thread where several things, like checking any changes in positions and wind
velocity, are done in a race loop.
GameInfo,
Track,
TrackFileParser,
Serialized Form| Field Summary | |
private int |
change_wind_time
time when the direction and strength of the wind will next be changed |
private int |
end_time
time when the current race state (racing/not racing) ends |
private java.lang.String |
game_status
A text that tells the race state. |
private int |
id
race id |
private boolean |
is_racing
is this race in a racing state or not |
private int |
master_id
id of the master player |
static int |
MaxPlayers
maximum number of players in one race |
private java.lang.String |
name
race name |
private int |
num_finished
number of players who have reached the goal |
private java.util.ArrayList |
players
A list of all players in this race. |
private java.lang.String[] |
race_result
list of results is a String array where the name of
each player reaching the goal is stored |
private java.util.Random |
rand
Random object to generate random numbers |
private boolean |
running
Is the race being run? The race loop is executed as long as running == true. |
private Server |
server
Server object this race belongs to |
private int |
start_time
starting time of the race |
private Track |
track
track used in this race |
private int |
wind_direction
direction of the wind in this race, given in degrees |
private int |
wind_velocity
velocity of the wind in this race, given in m/s |
| Constructor Summary | |
Game(int id,
java.lang.String name,
int master_id,
Server s)
Constructor. |
|
| Method Summary | |
boolean |
addPlayer(Player p)
Adds a player to the race. |
void |
clearRaceResult()
Clears the result array. |
void |
crashWithOtherPlayers(Player plr)
Makes the collision detections between the given player and other players. |
java.lang.String |
getGameStatus()
Returns the text that gives the race status. |
int |
getId()
Returns the id of this race. |
GameInfo |
getInfo()
Returns the information related to this race. |
int |
getMasterId()
Returns the id of the master player of this race. |
java.lang.String |
getName()
Returns the name of this race. |
int |
getNumPlayers()
Returns the number of players in this race. |
java.util.Iterator |
getPlayersIterator()
Returns an iterator for the players. |
java.lang.String[] |
getRaceResult()
Returns the result array. |
int |
getRandomIntRange(int min,
int max)
Returns the next random number from the given range. |
int |
getTimeS()
Returns the time of the server clock in seconds. |
Track |
getTrack()
Returns a reference to the currect track object. |
java.lang.String |
getTrackName()
Returns the name of the current track. |
int |
getWindDirection()
Returns the direction of the wind in this race. |
int |
getWindVelocity()
Returns the wind velocity in this race. |
boolean |
isRacing()
Returns the race state. |
void |
loadTrack(java.lang.String track_name)
Loads a new track to the race. |
void |
movePlayers(float seconds)
Moves all the players and makes the collision detections. |
void |
preparePlayers()
Prepares players for the race. |
void |
quit()
Exits the race. |
private void |
readObject(java.io.ObjectInputStream in)
Reads an object from a stream. |
void |
removeAllPlayers()
Removes all players from the race. |
void |
removePlayer(Player p)
Removes a player from the race. |
void |
run()
The race is ran in this run method of the thread. |
void |
say(java.lang.String str)
Sends a message to all players in this race. |
void |
setStatusText(java.lang.String str)
Sets the text that gives the race status. |
void |
startGame()
Begins a race. |
void |
stopGame()
Ends a race. |
private void |
writeObject(java.io.ObjectOutputStream out)
Writes the race data to an Object stream. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int MaxPlayers
private int id
private java.lang.String name
private int master_id
private Server server
Server object this race belongs to
private java.lang.String[] race_result
String array where the name of
each player reaching the goal is stored
private int num_finished
private Track track
private boolean is_racing
private boolean running
private int start_time
private int end_time
private java.lang.String game_status
private java.util.ArrayList players
private int wind_direction
private int wind_velocity
private int change_wind_time
private java.util.Random rand
Random object to generate random numbers
| Constructor Detail |
public Game(int id,
java.lang.String name,
int master_id,
Server s)
id - Race idname - Race namemaster_id - Id of the master players - Server object| Method Detail |
public GameInfo getInfo()
public int getId()
public java.lang.String getName()
public int getMasterId()
public void clearRaceResult()
public java.lang.String[] getRaceResult()
public boolean isRacing()
public void setStatusText(java.lang.String str)
str - Race status textpublic java.lang.String getGameStatus()
public void loadTrack(java.lang.String track_name)
track_name - name of the track to loadpublic Track getTrack()
public java.lang.String getTrackName()
public boolean addPlayer(Player p)
p - Player object to add
public java.util.Iterator getPlayersIterator()
public void removePlayer(Player p)
p - player's objectpublic void removeAllPlayers()
public int getNumPlayers()
public void preparePlayers()
public int getWindDirection()
public int getWindVelocity()
public int getRandomIntRange(int min,
int max)
min - lower limit of the integer to returnmax - the upper limit of the integer to return
public int getTimeS()
NOTE: This means all timing is done at a precision of one second.
public void quit()
public void startGame()
public void stopGame()
public void run()
run in interface java.lang.Runnablepublic void movePlayers(float seconds)
public void crashWithOtherPlayers(Player plr)
plr - The player whose collisions to check.public void say(java.lang.String str)
str - The message to send.
private void writeObject(java.io.ObjectOutputStream out)
throws java.io.IOException
Object stream.
NOTE: We only write the necessary attributes and objects to keep the race and network load as load as possible.
out - ObjectOutputStream to write into
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 | |||||||||