net.mazewar
Class MazeImpl

java.lang.Object
  extended by net.mazewar.Maze
      extended by net.mazewar.MazeImpl
All Implemented Interfaces:
java.io.Serializable, java.lang.Runnable, ClientListener

public class MazeImpl
extends Maze
implements java.io.Serializable, ClientListener, java.lang.Runnable

A concrete implementation of a Maze.

Version:
$Id: MazeImpl.java 371 2004-02-10 21:55:32Z geoffw $
Author:
Geoffrey Washburn <geoffw@cis.upenn.edu>
See Also:
Serialized Form

Constructor Summary
MazeImpl(Point point, long seed, java.util.Vector peers)
          Create a Maze.
 
Method Summary
 void addClient(Client client)
          Add a Client at random location in the Maze.
 void addClientAtGivenPoint(Client client, DirectedPoint directedPoint)
           
 void addMazeListener(MazeListener ml)
          Register an object that wishes to be notified when the maze changes
 boolean checkBounds(Point point)
          Check whether a Point is within the bounds of the Maze.
 boolean clientFire(Client client)
          Create a new Projectile from the specified Client
 void clientUpdate(Client c, ClientEvent ce)
          Listen for notifications about action performed by Clients in the maze.
 Cell getCell(Point point)
          Obtain the Cell corresponding to a given Point in the Maze.
 Direction getClientOrientation(Client client)
          Find out the cardinal direction a Client is facing.
 Point getClientPoint(Client client)
          Find out where a specified Client is located in the Maze.
 java.util.Iterator getClients()
          Obtain an Iterator over all Clients in the Maze
 Point getSize()
          Obtain a Point describing the size of the Maze.
 boolean moveClientBackward(Client client)
          Attempt to move a Client in the Maze backward.
 boolean moveClientForward(Client client)
          Attempt to move a Client in the Maze forward.
 void print()
          Display an ASCII version of the maze to stdout for debugging purposes.
static Maze readMazeFile(java.lang.String mazefile)
          Create a maze from a serialized MazeImpl object written to a file.
 void removeClient(Client client)
          Remove the specified Client from the Maze
 void removeMazeListener(MazeListener ml)
          Remove an object from the notification queue
 void rotateClientLeft(Client client)
          Internal helper called when a Client emits a turnLeft action.
 void rotateClientRight(Client client)
          Internal helper called when a Client emits a turnRight action.
 void run()
          Control loop for Projectiles.
 void save(java.lang.String mazefile)
          Serialize this MazeImpl to a file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MazeImpl

public MazeImpl(Point point,
                long seed,
                java.util.Vector peers)
Create a Maze.

Parameters:
point - Treat the Point as a magintude specifying the size of the maze.
seed - Initial seed for the random number generator.
Method Detail

readMazeFile

public static Maze readMazeFile(java.lang.String mazefile)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
Create a maze from a serialized MazeImpl object written to a file.

Parameters:
mazefile - The filename to load the serialized object from.
Returns:
A reconstituted MazeImpl.
Throws:
java.io.IOException
java.lang.ClassNotFoundException

save

public void save(java.lang.String mazefile)
          throws java.io.IOException
Serialize this MazeImpl to a file.

Parameters:
mazefile - The filename to write the serialized object to.
Throws:
java.io.IOException

print

public void print()
Display an ASCII version of the maze to stdout for debugging purposes.


checkBounds

public boolean checkBounds(Point point)
Description copied from class: Maze
Check whether a Point is within the bounds of the Maze.

Specified by:
checkBounds in class Maze
Returns:
true if the point lies within the Maze, false otherwise.

getSize

public Point getSize()
Description copied from class: Maze
Obtain a Point describing the size of the Maze.

Specified by:
getSize in class Maze
Returns:
A Point where the method getX returns the maximum X coordintate, and the method getY returns the maximum Y coordinate.

getCell

public Cell getCell(Point point)
Description copied from class: Maze
Obtain the Cell corresponding to a given Point in the Maze.

Specified by:
getCell in class Maze
Parameters:
point - Location in the Maze.
Returns:
A Cell describing that location.

addClient

public void addClient(Client client)
Description copied from class: Maze
Add a Client at random location in the Maze.

Specified by:
addClient in class Maze
Parameters:
client - Client to be added to the Maze.

addClientAtGivenPoint

public void addClientAtGivenPoint(Client client,
                                  DirectedPoint directedPoint)
Specified by:
addClientAtGivenPoint in class Maze

getClientPoint

public Point getClientPoint(Client client)
Description copied from class: Maze
Find out where a specified Client is located in the Maze.

Specified by:
getClientPoint in class Maze
Parameters:
client - The Client being located.
Returns:
A Point describing the location of the client.

getClientOrientation

public Direction getClientOrientation(Client client)
Description copied from class: Maze
Find out the cardinal direction a Client is facing.

Specified by:
getClientOrientation in class Maze
Parameters:
client - The Client being queried.
Returns:
The orientation of the specific Client as a Direction.

removeClient

public void removeClient(Client client)
Description copied from class: Maze
Remove the specified Client from the Maze

Specified by:
removeClient in class Maze
Parameters:
client - Client to be removed.

clientFire

public boolean clientFire(Client client)
Description copied from class: Maze
Create a new Projectile from the specified Client

Specified by:
clientFire in class Maze
Parameters:
client - Client that is firing.
Returns:
false on failure, true on success.

moveClientForward

public boolean moveClientForward(Client client)
Description copied from class: Maze
Attempt to move a Client in the Maze forward.

Specified by:
moveClientForward in class Maze
Parameters:
client - Client to move.
Returns:
true if successful, false if failure.

moveClientBackward

public boolean moveClientBackward(Client client)
Description copied from class: Maze
Attempt to move a Client in the Maze backward.

Specified by:
moveClientBackward in class Maze
Parameters:
client - Client to move.
Returns:
true if successful, false if failure.

getClients

public java.util.Iterator getClients()
Description copied from class: Maze
Obtain an Iterator over all Clients in the Maze

Specified by:
getClients in class Maze
Returns:
Iterator over clients in the Maze.

addMazeListener

public void addMazeListener(MazeListener ml)
Description copied from class: Maze
Register an object that wishes to be notified when the maze changes

Specified by:
addMazeListener in class Maze
Parameters:
ml - An object implementing the MazeListener interface.

removeMazeListener

public void removeMazeListener(MazeListener ml)
Description copied from class: Maze
Remove an object from the notification queue

Specified by:
removeMazeListener in class Maze
Parameters:
ml - An object implementing the MazeListener interface.

clientUpdate

public void clientUpdate(Client c,
                         ClientEvent ce)
Listen for notifications about action performed by Clients in the maze.

Specified by:
clientUpdate in interface ClientListener
Parameters:
c - The Client that acted.
ce - The action the Client performed.

run

public void run()
Control loop for Projectiles.

Specified by:
run in interface java.lang.Runnable

rotateClientLeft

public void rotateClientLeft(Client client)
Internal helper called when a Client emits a turnLeft action.

Parameters:
client - The Client to rotate.

rotateClientRight

public void rotateClientRight(Client client)
Internal helper called when a Client emits a turnRight action.

Parameters:
client - The Client to rotate.