org.newdawn.asd.data
Class GameWorld

java.lang.Object
  extended byorg.newdawn.asd.data.GameWorld

public class GameWorld
extends java.lang.Object

A ticker than updates the turns based on the amount of time that needs to pass based on the rendering engine. TODO: Decide how turn length matters.


Constructor Summary
GameWorld(long seed, int schedulingOffset)
          Create a new game world based on an initial random seed
 
Method Summary
 void activate(Actor actor, int x, int y)
          Activate the tile specified on behalf of the actor
 Actor addActor(java.lang.String username, Stats stats)
          Add an actor into the game world for a given player
 void addCommand(GameCommand command)
          Add a command to the scheduled list.
 void addListener(GameWorldListener listener)
          Add a listener that will recieve notification of game world events.
 Actor getActorById(int id)
          Get an actor that resides in the world somewhere based on its ID
 int getChecksum()
          Get the checksum of the game world and every element in it at the current simualtion time
 Map getMap(Actor actor)
          Get the map containing within this game world
 Map getMap(int index)
          Get the map at the specified index
 double getNextRandom()
          Get the next random number.
 Actor getOwnedActor(java.lang.String owner)
          Get an actor owned by a specific named user
 ActorList getPlayerActors()
          Get the list of actors representing players
 int getScheduledCommandCount()
          Get the number of commands scheduled in the game world
 long getServerOffset()
          Retrieve the amount of millseconds we are offset to the server expected time
 long getTime()
          Get the current simulation time
 boolean isGamePaused()
          Check if the game is currently paused
 void removeActor(java.lang.String username)
          Remove an actor for a given player from the game world
 void removeListener(GameWorldListener listener)
          Remove a listener from the game world.
 void setGamePaused(boolean gamePaused)
          Indicate whether the game should be paused or not
 void update(int delta)
          Update the game world based on a given amount of real time passing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GameWorld

public GameWorld(long seed,
                 int schedulingOffset)
Create a new game world based on an initial random seed

Parameters:
seed - The random seed used to spawn the game world
schedulingOffset - The offset from sim time game commands are expected to be scheduled at
Method Detail

addCommand

public void addCommand(GameCommand command)
Add a command to the scheduled list. This should check that the command isn't in the past (it should never be). It should also caculate how close to game time we're getting. If we're lagging behind the sim will be speeded up. If we're getting to close the sim will be slowed.

Parameters:
command - The command to add

setGamePaused

public void setGamePaused(boolean gamePaused)
Indicate whether the game should be paused or not

Parameters:
gamePaused - True if the game should be paused

isGamePaused

public boolean isGamePaused()
Check if the game is currently paused

Returns:
True if the game is currently paused

update

public void update(int delta)
Update the game world based on a given amount of real time passing.

Parameters:
delta - The amount of read time that has passed since last update (in milliseconds).

getMap

public Map getMap(Actor actor)
Get the map containing within this game world

Parameters:
actor - The actor whose map we're looking for
Returns:
The map in which the actors are running around

getMap

public Map getMap(int index)
Get the map at the specified index

Parameters:
index - The index of the map to retrieve
Returns:
The map at the specified index

getNextRandom

public double getNextRandom()
Get the next random number. All elements of the game world should use this for calculations

Returns:
The next random number in our seeded sequence

addListener

public void addListener(GameWorldListener listener)
Add a listener that will recieve notification of game world events.

Parameters:
listener - The listener to add

removeListener

public void removeListener(GameWorldListener listener)
Remove a listener from the game world. The listener will no longer recieve events about the game world activities.

Parameters:
listener - The listener that should be removed

removeActor

public void removeActor(java.lang.String username)
Remove an actor for a given player from the game world

Parameters:
username - The name of the user that owns the actor to be removed

addActor

public Actor addActor(java.lang.String username,
                      Stats stats)
Add an actor into the game world for a given player

Parameters:
username - The username of the player for which the actor is being added.
stats - The stats describing the actor being added
Returns:
The newly created and added actor

getOwnedActor

public Actor getOwnedActor(java.lang.String owner)
Get an actor owned by a specific named user

Parameters:
owner - The name of the owner whose actor should be retrieved
Returns:
The actor owned by the specified user (or null if none owned)

getTime

public long getTime()
Get the current simulation time

Returns:
The current simulation time

getChecksum

public int getChecksum()
Get the checksum of the game world and every element in it at the current simualtion time

Returns:
The checksum of the game world and every element in it.

getServerOffset

public long getServerOffset()
Retrieve the amount of millseconds we are offset to the server expected time

Returns:
The offset to the expected server time

getScheduledCommandCount

public int getScheduledCommandCount()
Get the number of commands scheduled in the game world

Returns:
The number of scheduled commands

getPlayerActors

public ActorList getPlayerActors()
Get the list of actors representing players

Returns:
The list of player actors

getActorById

public Actor getActorById(int id)
Get an actor that resides in the world somewhere based on its ID

Parameters:
id - The ID of the actor to be retrieved
Returns:
The actor requested or null if no actor with that ID can be found.

activate

public void activate(Actor actor,
                     int x,
                     int y)
Activate the tile specified on behalf of the actor

Parameters:
actor - The actor performing the activation
x - The x location of the tile to be activated
y - The y location of the tile to be activated