Class FlyManager

java.lang.Object
  |
  +--FlyManager

public class FlyManager
extends java.lang.Object

CLASS: FlyManager
PURPOSE: This class is the monitor of where the flies are and to manage them
IMPORT: java.util.Vector, java.awt.Image, java.awt.Graphics, java.awt.image.ImageObserver, Fly
EXPORT: New Class|FlyManager
New Method| FlyManager, createFly, eatFly moveAllFly, paintAllFly


Field Summary
private  java.util.Vector flyList
          Keep track of the list of flies
private  int height
          height of the box where the fly is allow to go
private  int maxFly
          Maximum number of flies alive at any given time
private  int maxMovement
          how far the flies can move
private  int width
          width of the box where the fly is allow to go
 
Constructor Summary
FlyManager(int max, int w, int h)
          
PRE: NONE
POST: Save the configuration information
 
Method Summary
 boolean createFly()
          
PRE: NONE
POST: A fly is created if the maximum number of fly has not been reach yet
 boolean eatFly(int x, int y)
          
PRE: NONE
POST: Try to eat the fly, if fail return false, otherwise, return true and the fly will be removed
 void moveAllFly()
          
PRE: NONE
POST: move all the flies' position randomly
 void paintAllFly(java.awt.Graphics g, java.awt.Image flyImage, java.awt.image.ImageObserver appletRef)
          
PRE: Valid instance of Graphics, Image, and ImageObserver
POST: Paint all the flies available onto the Graphics object
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

flyList

private java.util.Vector flyList
Keep track of the list of flies

width

private int width
width of the box where the fly is allow to go

height

private int height
height of the box where the fly is allow to go

maxFly

private int maxFly
Maximum number of flies alive at any given time

maxMovement

private int maxMovement
how far the flies can move
Constructor Detail

FlyManager

public FlyManager(int max,
                  int w,
                  int h)

PRE: NONE
POST: Save the configuration information
Method Detail

createFly

public boolean createFly()

PRE: NONE
POST: A fly is created if the maximum number of fly has not been reach yet

eatFly

public boolean eatFly(int x,
                      int y)

PRE: NONE
POST: Try to eat the fly, if fail return false, otherwise, return true and the fly will be removed

paintAllFly

public void paintAllFly(java.awt.Graphics g,
                        java.awt.Image flyImage,
                        java.awt.image.ImageObserver appletRef)

PRE: Valid instance of Graphics, Image, and ImageObserver
POST: Paint all the flies available onto the Graphics object

moveAllFly

public void moveAllFly()

PRE: NONE
POST: move all the flies' position randomly