dualroids
Class Server

java.lang.Object
  |
  +--dualroids.Server
All Implemented Interfaces:
Runnable

public final class Server
extends Object
implements Runnable

The Dualroids game server.


Field Summary
private  Arena arena
          The server's copy of the arena
private  int asteroidIndex
          A counter for controlling the asteroid updating iteration.
private  ServerModelConnector[] connectors
          An array holding all the connectors through which the server sends data to the clients.
static int INITIAL_SHIPS
          The number of spare ships the player has initially.
static long INVULNERABILITY_PERIOD
          The duration of the ship invulnerability period when a player gets a new ship.
private  int level
          The level number counter
private static long LEVEL_START_DELAY
          The delay between the beginning of level generation and the start of the level.
static long MIN_ITERATION_INTERVAL
          Constant for the minimal interval (in milliseconds) between the starts of two server model update iterations.
static long NEW_SHIP_DELAY
          The delay before a new ships appears when a ship has exploded.
private  String playerName
          The name of the player who is running the server
private static int SCORE_1UP
          The interval in scores when player should get an additional spare ship
private  int[] scores
          The score table.
private  int[] shipsLeft
          The table of remaining ships.
 
Constructor Summary
Server(String playerName)
          Contructs a new Server.
 
Method Summary
private  void blowUpShip(int shipIndex, long newAppears)
          Blows up a ship
private  void checkCollisions(long time)
          Checks collisions in the arena (ships or bullets hitting asteroids).
private  void flush()
          Flushes both connectors and thus causes the buffered data in network streams to flush too.
private  void invalidateBullet(int shipIndex, int bulletIndex)
          Marks a bullet non-flying (not visible).
private  void registerAsteroidHit(int shipIndex, int asteroidIndex, long time)
          Register a bullet hit to an asteroid.
 void run()
          The method that starts the server thread.
private  void runLevel()
          The method for running a level
private  void sendArena()
          Sends the arena to the clients.
 boolean updateAsteroids(long time)
          Updates the fields of one asteroid at time and checks whether there are asteroids left.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

MIN_ITERATION_INTERVAL

public static final long MIN_ITERATION_INTERVAL
Constant for the minimal interval (in milliseconds) between the starts of two server model update iterations.

LEVEL_START_DELAY

private static final long LEVEL_START_DELAY
The delay between the beginning of level generation and the start of the level.

INVULNERABILITY_PERIOD

public static final long INVULNERABILITY_PERIOD
The duration of the ship invulnerability period when a player gets a new ship.

NEW_SHIP_DELAY

public static final long NEW_SHIP_DELAY
The delay before a new ships appears when a ship has exploded.

INITIAL_SHIPS

public static final int INITIAL_SHIPS
The number of spare ships the player has initially.

SCORE_1UP

private static final int SCORE_1UP
The interval in scores when player should get an additional spare ship

arena

private Arena arena
The server's copy of the arena

connectors

private ServerModelConnector[] connectors
An array holding all the connectors through which the server sends data to the clients.

level

private int level
The level number counter

asteroidIndex

private int asteroidIndex
A counter for controlling the asteroid updating iteration.

scores

private int[] scores
The score table.

shipsLeft

private int[] shipsLeft
The table of remaining ships.

playerName

private String playerName
The name of the player who is running the server
Constructor Detail

Server

public Server(String playerName)
Contructs a new Server.
Parameters:
playerName - the name of the player running the server
Method Detail

run

public void run()
The method that starts the server thread.
Specified by:
run in interface Runnable

runLevel

private final void runLevel()
                     throws GameOverException
The method for running a level

flush

private final void flush()
Flushes both connectors and thus causes the buffered data in network streams to flush too.

checkCollisions

private final void checkCollisions(long time)
                            throws GameOverException
Checks collisions in the arena (ships or bullets hitting asteroids).
Parameters:
time - the moment in time for which the check is to be performed

updateAsteroids

public final boolean updateAsteroids(long time)
Updates the fields of one asteroid at time and checks whether there are asteroids left.
Parameters:
time - the moment in time to be used as the new timestamp
Returns:
true if there are asteroids left and false otherwise

blowUpShip

private final void blowUpShip(int shipIndex,
                              long newAppears)
                       throws GameOverException
Blows up a ship
Parameters:
shipIndex - the index of the ship to blow up

invalidateBullet

private final void invalidateBullet(int shipIndex,
                                    int bulletIndex)
Marks a bullet non-flying (not visible).
Parameters:
shipIndex - the index of the ship owning the bullet
bulletIndex - the index of the bullet

registerAsteroidHit

private final void registerAsteroidHit(int shipIndex,
                                       int asteroidIndex,
                                       long time)
Register a bullet hit to an asteroid. The hit may cause the asteroid to explode and points to be awarded.
Parameters:
shipIndex - the index of the ship that fired the bullet
asteroidIndex - the index of the asteroid

sendArena

private final void sendArena()
Sends the arena to the clients.


Dualroids was written by Oskar Ojala, Yrjö Kari-Koskinen and Henri Sivonen