fi.utu.cs.asteroids
Class Game

java.lang.Object
  |
  +--fi.utu.cs.asteroids.Game

public class Game
extends java.lang.Object

Parameter handling and auxiliary methods for the game.

The initial parameters include:

asteroidDensity
The density of the asteroids. The radius of an asteroid is determined by dividing its mass with the density.
asteroidInitialVelocity
The initial velocity of an asteroid.
asteroidInitialAcceleration
The initial acceleration of an asteroid.
asteroidMinimumMass
The minimum mass for the asteroids.
asteroidMaximumMass
The maximum mass for the asteroids.
asteroidMinFractionOnSplit
The minimum size of the asteroid fraction on a split with respect to the original asteroid in the interval (0.0,1.0].
asteroidMaxFractionOnSplit
The maximum size of the asteroid fraction on a split with respect to the original asteroid in the interval (0.0,1.0].
asteroidSumOfFractionsOnSplit
The total sum of fractions created on a split (should be < 1.0).
projectileMass
The mass of the projectiles.
projectileRadius
The radius of the projectiles.
projectileLifetime
The lifetime of the projectiles in seconds.
projectileInitialVelocity
The initial velocity of the projectiles.
projectileInitialAcceleration
The initial acceleration of the projectiles
shipMass
The mass of the ships.
shipRadius
The radius of the ships.
shipShotsPerSecond
The amount of shots that the ship is capable of firing in one second.
shipSteeringRotationPerSecond
The angle (in radians) that the ship is capable of rotating in one second.
shipThrusterForce
The force created by the ship's thruster in one second. The acceleration of the ship depends on this force and the ship's mass.
sparkRadius
The radius of the sparks.
sparkLifetime
The lifetime of the sparks in seconds.
sparkMaxVelocity
The maximum velocity of the sparks on an explosion cloud.
sparksOnCloud
The amount of sparks used in an explosion cloud.
debrisRadius
The radius of a piece of debris.
debrisLifetime
The lifetime of a piece of debris in seconds.
debrisMaxVelocity
The maximum velocity of the debris on a cloud.
debrisOnCloud
The amount of debris in a cloud.
collisionAsteroidAsteroid
A Boolean value indicating whether the asteroids can collide with each other.
collisionProjectileProjectile
A Boolean value indicating whether the projectiles can collide with each other.
collisionProjectileShip
A Boolean value indicating whether the projectiles can collide with the ships.
collisionShipShip
A Boolean value indicating whether the ships can collide with each other.
playgroundWidth
The width of the universe used in the game.
playgroundHeight
The height of the universe used in the game.
playgroundBorder
The size of the border that surrounds the visible area.
decorations
A Boolean value indicating whether the decorations (i.e., sparks and debris) are included in the game.


Method Summary
static Asteroid createAsteroidOnBorder(Universe u)
          Creates and inserts an Asteroid object to the the universe u.
static Universe createPlayground()
          Creates and returns a toroid universe.
static Universe createPlayground(double w, double h)
          Creates and returns a toroid universe with the width w and height h.
static Ship createShipOnCenter(Universe u)
          Creates and inserts a Ship object to the center of the universe u.
static Ship createShipOnRandomPosition(Universe u)
          Creates and inserts a Ship object to a random position in the universe u.
static ShapeView createView(Universe u, double z)
          Creates and returns a ShapeView Swing component.
static ShapeView createView(Universe u, double z, double b)
          Creates and returns a ShapeView Swing component.
static boolean getBooleanParameter(java.lang.String n)
          Returns the Boolean value of the parameter n.
static double getDoubleParameter(java.lang.String n)
          Returns the double-precision floating point value of the parameter n.
static int getIntegerParameter(java.lang.String n)
          Returns the integer value of the parameter n.
static java.lang.String getStringParameter(java.lang.String n)
          Returns the String object of the parameter n.
static void initialize()
          Sets the built-in default values to the parameters.
static void load(java.io.InputStream is)
          Reads a parameter list (type, name and value triplets) from the input stream is.
static java.util.Iterator parameterNames()
          Returns an iterator to the names of all the parameters.
static void save(java.io.OutputStream os)
          Writes the parameter list (type, key and element triplets) to the output stream os.
static void setParameter(java.lang.String n, boolean v)
          Sets the parameter n to the Boolean value v.
static void setParameter(java.lang.String n, double v)
          Sets the parameter n to the double-precision floating point value v.
static void setParameter(java.lang.String n, int v)
          Sets the parameter n to the integer value v.
static void setParameter(java.lang.String n, java.lang.String s)
          Sets the parameter n to the String object s.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createPlayground

public static Universe createPlayground()
Creates and returns a toroid universe. The width of the universe is defined by the parameter playgroundWidth and the height by the parameter playgroundHeight.

createPlayground

public static Universe createPlayground(double w,
                                        double h)
Creates and returns a toroid universe with the width w and height h.

createView

public static ShapeView createView(Universe u,
                                   double z)
Creates and returns a ShapeView Swing component. The width of the border is defined by the parameter playgroundBorder.
Parameters:
u - The universe of the game.
z - The zoom factor.
See Also:
createView(Universe,double,double)

createView

public static ShapeView createView(Universe u,
                                   double z,
                                   double b)
Creates and returns a ShapeView Swing component. The view shows the rectangle ((u.getMinimumCorner().getX() + b, u.getMinimumCorner().getY() + b), (u.getMaximumCorner().getX() - b, u.getMaximumCorner().getY() - b)).
Parameters:
u - The universe of the game.
z - The zoom factor.
b - The width of the border.

createAsteroidOnBorder

public static Asteroid createAsteroidOnBorder(Universe u)
Creates and inserts an Asteroid object to the the universe u. The asteroid, heading a random direction, is placed on a random position in the border.
Returns:
The created asteroid.
See Also:
Asteroid

createShipOnCenter

public static Ship createShipOnCenter(Universe u)
Creates and inserts a Ship object to the center of the universe u.
Returns:
The created ship.
See Also:
Ship

createShipOnRandomPosition

public static Ship createShipOnRandomPosition(Universe u)
Creates and inserts a Ship object to a random position in the universe u.
Returns:
The created ship.
See Also:
Ship

initialize

public static void initialize()
Sets the built-in default values to the parameters.

getDoubleParameter

public static double getDoubleParameter(java.lang.String n)
Returns the double-precision floating point value of the parameter n. The method throws ClassCastException if the parameter is of a different type.

getIntegerParameter

public static int getIntegerParameter(java.lang.String n)
Returns the integer value of the parameter n. The method throws ClassCastException if the parameter is of a different type.

getBooleanParameter

public static boolean getBooleanParameter(java.lang.String n)
Returns the Boolean value of the parameter n. The method throws ClassCastException if the parameter is of a different type.

getStringParameter

public static java.lang.String getStringParameter(java.lang.String n)
Returns the String object of the parameter n. The method throws ClassCastException if the parameter is of a different type.

setParameter

public static void setParameter(java.lang.String n,
                                double v)
Sets the parameter n to the double-precision floating point value v.

setParameter

public static void setParameter(java.lang.String n,
                                int v)
Sets the parameter n to the integer value v.

setParameter

public static void setParameter(java.lang.String n,
                                boolean v)
Sets the parameter n to the Boolean value v.

setParameter

public static void setParameter(java.lang.String n,
                                java.lang.String s)
Sets the parameter n to the String object s.

parameterNames

public static java.util.Iterator parameterNames()
Returns an iterator to the names of all the parameters.

load

public static void load(java.io.InputStream is)
                 throws java.io.IOException
Reads a parameter list (type, name and value triplets) from the input stream is. The stream is assumed to be using ISO 8859-1 character encoding. Every parameter occupies one line of the input stream. Lines from the input stream are processed until end of file is reached on the input stream. A line that begins with a type token DOUBLE, INTEGER, BOOLEAN or STRING is interpreted to contain the name and the value of a parameter. For example,
DOUBLE  pi            3.14
INTEGER meaningOfLife 42
BOOLEAN existence     false
STRING  employees     "Dilbert, Alice, Wally"
Throws:
java.io.IOException - An error occurred when reading the input stream.
See Also:
save(OutputStream)

save

public static void save(java.io.OutputStream os)
                 throws java.io.IOException
Writes the parameter list (type, key and element triplets) to the output stream os.
Throws:
java.io.IOException - An error occurred when writing the output stream.
See Also:
load(InputStream)