Breakout Problem Set Javadocs

breakout
Class WorldState

java.lang.Object
  extended bybreakout.WorldState
All Implemented Interfaces:
World

public class WorldState
extends java.lang.Object
implements World

WorldState implements the World interface, providing an augmented container for BreakoutComponents. It also serves as a synchronization point for the program. In order for it to behave properly, it must be passed a JComponent GUI object before any components are added. It currently uses a dumb component intersection and rebound implementation.

Version:
$id$
Author:
benmv@olin.edu
See Also:
World

Field Summary
 Wall EAST
           
 Wall NORTH
           
 Wall SOUTH
           
 Wall WEST
           
 
Fields inherited from interface breakout.World
MAXX, MAXY, SHAPE_PRECISION
 
Constructor Summary
WorldState(boolean networked)
          Builds a WorldState object with only the components that make up the walls.
 
Method Summary
 void add(BreakoutComponent bc)
          adds the component to the world and sends a WorldEvent if the component added was a brick.
 void addMouseAware(BreakoutComponent bc)
          adds the component to the world using the add method and then registers the component with the GUI as a MouseListener and MouseMotionListener.
 void addWorldListener(WorldListener wl)
          adds the given listener to the list of objects to be informed of changes in the world state
 void ballLeft(Ball b)
          signal that the given ball has left the board for a better place (the other board).
 int getBallsLeft()
          returns the number of balls left.
 BreakoutComponent intersects(BreakoutComponent bc)
          Assumes the component checking for intersections is rectangular.
 java.util.Iterator iterator()
          Returns an iterator that supports the remove operation.
 void killAll()
          kills all components except the walls and empties the vector.
 boolean playing()
          returns true if a game is in progress.
 void rebound(BreakoutComponent bc1, BreakoutComponent bc2)
          Assumes that two active components rebounding are equal mass and non active components have infinite mass.
 void removeAt(java.awt.Point loc)
          removes the component at the given coordinates.
 void startPlaying()
          indicate that game should start.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORTH

public final Wall NORTH

SOUTH

public final Wall SOUTH

EAST

public final Wall EAST

WEST

public final Wall WEST
Constructor Detail

WorldState

public WorldState(boolean networked)
Builds a WorldState object with only the components that make up the walls. The South wall is a KillerWall. If the networked version is requested, the North wall is a TransferWall.

Parameters:
networked - specifies whether the worldstate will be networked to another world.
See Also:
Wall, KillerWall, TransferWall
Method Detail

intersects

public BreakoutComponent intersects(BreakoutComponent bc)
Assumes the component checking for intersections is rectangular.

Specified by:
intersects in interface World
Parameters:
bc - component to test
Returns:
BreakoutComponent or null if none.
See Also:
World

rebound

public void rebound(BreakoutComponent bc1,
                    BreakoutComponent bc2)
Assumes that two active components rebounding are equal mass and non active components have infinite mass.

Specified by:
rebound in interface World
Parameters:
bc1 - component to have rebound
bc2 - component to have rebound

add

public void add(BreakoutComponent bc)
adds the component to the world and sends a WorldEvent if the component added was a brick.

Specified by:
add in interface World
Parameters:
bc - BreakoutComponent to add

addMouseAware

public void addMouseAware(BreakoutComponent bc)
adds the component to the world using the add method and then registers the component with the GUI as a MouseListener and MouseMotionListener.

Specified by:
addMouseAware in interface World
Parameters:
bc - BreakoutComponent to add to World and mouse listeners.
Throws:
java.lang.ClassCastException - if the BreakoutComponent does not also implement MouseListener and MouseMotionListener.

iterator

public java.util.Iterator iterator()
Returns an iterator that supports the remove operation. Remember to synchronize on this before using.

Specified by:
iterator in interface World
Returns:
Iterator that supports remove();

removeAt

public void removeAt(java.awt.Point loc)
Description copied from interface: World
removes the component at the given coordinates. Coordinates must exactly match. Removes at most one component.

Specified by:
removeAt in interface World
Parameters:
loc - coordinates of component to be removed.

ballLeft

public void ballLeft(Ball b)
Description copied from interface: World
signal that the given ball has left the board for a better place (the other board). The ball is kill()'ed.

Specified by:
ballLeft in interface World
Parameters:
b - ball that has left. Ball is killed.

killAll

public void killAll()
Description copied from interface: World
kills all components except the walls and empties the vector. pauses for half a second to ensure all previous threads have died before continuing. Resets the number of balls.

Specified by:
killAll in interface World

startPlaying

public void startPlaying()
Description copied from interface: World
indicate that game should start. releases a ball from the store.

Specified by:
startPlaying in interface World

playing

public boolean playing()
Description copied from interface: World
returns true if a game is in progress.

Specified by:
playing in interface World
Returns:
boolean true if a game is in progress.

getBallsLeft

public int getBallsLeft()
Description copied from interface: World
returns the number of balls left.

Specified by:
getBallsLeft in interface World
Returns:
int number of balls left

addWorldListener

public void addWorldListener(WorldListener wl)
Description copied from interface: World
adds the given listener to the list of objects to be informed of changes in the world state

Specified by:
addWorldListener in interface World
Parameters:
wl - WorldListener to add.

Breakout Problem Set Javadocs