gizmoball.board
Class GizmoBoard

java.lang.Object
  extended by gizmoball.board.GizmoBoard

public class GizmoBoard
extends java.lang.Object

This class represents a board for the Gizmoball game. The board contains the gizmos and has functions for adding and viewing the gizmos on a board. The board also has methods to move gizmos, set some gizmos properties, and govern the keyboard connections to gizmos. The board ensures that gizmos added do not overlap.

Author:
Michal Wexler

Constructor Summary
GizmoBoard(int xsize, int ysize, double L)
          constructs a GizmoBoard object.
 
Method Summary
 Absorber addAbsorber(java.lang.String name, java.awt.Color color, Vect upperLeftCorner, double height, double width, Vect launchVelocity)
          adds an absorber to the board.
 Ball addBall(Ball b)
          adds a given ball to the board.
 Ball addBall(java.lang.String name, java.awt.Color color, Vect center, Vect velocity, double radius)
          adds a ball to the board
 Bumper addBumper(java.lang.String name, java.awt.Color color, Shape shape)
          adds a bumper to the board.
 boolean addConnection(Gizmo source, Gizmo target)
          adds a connection between two gizmos that are on the board.
 ExtenderGizmo addExtender(java.lang.String name, java.awt.Color color, Vect upperLeft, double squareLength, double xSpanOfMotion, double ySpanOfMotion, double velocity, double pausingTime)
           
 Ball addGhostBall(java.lang.String name, java.awt.Color color, Vect center, Vect velocity, double radius)
          adds a ghost ball to the board.
 void addKeyDownTriggerToGizmo(java.lang.Integer key, Gizmo g)
          adds a down keyboard trigger to the specified gizmo.
 void addKeyUpTriggerToGizmo(java.lang.Integer key, Gizmo g)
          adds an up keyboard trigger to the specified gizmo.
 RotatingGizmo addLeftFlipper(java.lang.String name, java.awt.Color color, Vect topCenter, double distanceBetweenCenters, double radius)
          adds a left flipper to the board.
 RotatingGizmo addLeftFlipper(java.lang.String name, java.awt.Color color, Vect topCenter, double distanceBetweenCenters, double radius, Angle currentAngle)
          adds a left flipper to the board.
 RotatingGizmo addRightFlipper(java.lang.String name, java.awt.Color color, Vect topCenter, double distanceBetweenCenter, double radius)
          adds a right flipper to the board.
 RotatingGizmo addRightFlipper(java.lang.String name, java.awt.Color color, Vect topCenter, double distanceBetweenCenters, double radius, Angle currentAngle)
          adds a right flipper to the board.
 java.lang.Boolean canAddAbsorber(Vect upperLeftCorner, double height, double width)
          checks if an absorber with the given properties can be added to the board.
 boolean canAddBall(double radius, Vect center)
          checks if a ball with the given center and radius can be added to the board.
 boolean canAddBumper(Shape shape)
          checks if a bumper with the given shape can be added.
 java.lang.Boolean canAddExtender(Vect upperLeft, double squareLength, double xSpanOfMotion, double ySpanOfMotion)
          checks if an extender with the given properties can be added to the baord.
 boolean canAddGhostBall(double radius, Vect center)
          checks if a ghost ball with the given center and radius can be added to the board.
 boolean canAddLeftFlipper(Vect topCenter, double distanceBetweenCenters, double radius)
          checks if a left flipper with the given properties can be added to the board.
 boolean canAddLeftFlipper(Vect topCenter, double distanceBetweenCenters, double radius, Angle currentAngle)
          checks if a left flipper with the given properties can be added to the board.
 boolean canAddRightFlipper(Vect topCenter, double distanceBetweenCenters, double radius)
          checks if a right flipper with the given properties can be added to the board.
 boolean canAddRightFlipper(Vect topCenter, double distanceBetweenCenters, double radius, Angle currentAngle)
          checks if a right flipper with the given properties can be added to the board.
 boolean canMoveGizmo(Gizmo g, Vect vector)
           
 boolean canRotateGizmo(Gizmo g, Angle angle, Vect centerOfRotation)
          checks if the given gizmo can rotate by the given angle and around the given center of rotation.
 boolean contains(Gizmo giz)
          checks if a board contains a given gizmo.
 void deleteBall(Ball bl)
          removes a ball from the board.
 void deleteGizmo(Gizmo g)
          removes the given gizmo from the board.
 void deleteKeyDownTriggerToGizmo(java.lang.Integer key, Gizmo g)
          removes a press key connection from the given key to the given gizmo
 void deleteKeyUpTriggerToGizmo(java.lang.Integer key, Gizmo g)
          removes a release key connection from the given key to the given gizmo
 void downTrigger(java.lang.Integer key)
          adds a key to a waiting list to trigger a gizmo.
 void executeKeyboardEvents()
          executes the action of the gizmos that got triggered.
 java.util.List<Absorber> getAbsorbers()
          returns a list of all the absorbers that are on the board.
 java.util.List<Ball> getBalls()
          returns a list of balls that are on the board.
 java.util.List<Bumper> getBumpers()
          returns a list of the bumpers that are on the board.
 java.util.List<Gizmo> getDrawableGizmos()
          returns all the gizmos that are to be drawn.
 java.util.List<ExtenderGizmo> getExtenders()
          returns a list of all the extender gizmos that are on the board.
 java.util.List<ExtenderGizmo> getExtendersAt(int x, int y)
          returns the extenders that intersect with the LxL square that its upper-left vertex is at (x*L,y*L).
 Gizmo getGizmo(java.lang.String n)
          returns the gizmo with the specified name that is on the board.
 java.util.List<Gizmo> getGizmoAt(Vect pt)
          returns a list of gizmos that are at the location specified.
 java.util.List<Gizmo> getKeyDownGizmos(java.lang.Integer key)
          returns the list of gizmos that are triggered by the specified key when pressed.
 java.util.Set<java.lang.Integer> getKeyDownTriggers()
          returns all the keys that are mapped to trigger gizmos when are pressed.
 java.util.List<Gizmo> getKeyUpGizmos(java.lang.Integer key)
          returns the list of gizmos that are triggered by the specified key when released.
 java.util.Set<java.lang.Integer> getKeyUpTriggers()
          returns all the keys that are mapped to trigger gizmos when are released.
 java.util.List<RotatingGizmo> getLeftFlippers()
          returns the list of the left flippers that are on the board.
 java.util.List<RotatingGizmo> getRightFlippers()
          returns the right flippers that are on the board.
 java.util.List<RotatingGizmo> getRotatingGizmos()
          returns a list of all the rotating objects that are on the board.
 java.util.List<RotatingGizmo> getRotatingGizmosAt(int x, int y)
          returns the rotating gizmos that intersect with the LxL square that its upper-left vertex is at (x*L,y*L).
 java.util.List<Gizmo> getStationaryGizmos()
          returns a list of all the stationary objects that are on the board.
 java.util.List<Gizmo> getStationaryGizmosAt(int x, int y)
          returns the stationary gizmos that intersect with the LxL square that its upper-left vertex is at (x*L,y*L).
 double getUnitSize()
          returns the scale factor.
 int getXSize()
          returns the x-dimension of the board.
 int getYSize()
          returns the y-dimension of the board.
 boolean moveGizmo(Gizmo g, Vect vector)
           
 boolean removeConnection(Gizmo source, Gizmo target)
          removes a connection between two gizmos that are on the board.
 void RotateGizmo(Gizmo g, Angle angle, Vect centerOfRotation)
           
 void upTrigger(java.lang.Integer key)
          adds a key to a waiting list to trigger a gizmo.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GizmoBoard

public GizmoBoard(int xsize,
                  int ysize,
                  double L)
constructs a GizmoBoard object. The actual area of the board is (xsize*L)*(ysize*L)

Parameters:
xsize - the x-dimension of the board
ysize - the y-dimension of the board
L - the scale factor
Method Detail

getXSize

public int getXSize()
returns the x-dimension of the board.

Returns:
the x-dimension of the board

getYSize

public int getYSize()
returns the y-dimension of the board.

Returns:
the y-dimension of the board

getUnitSize

public double getUnitSize()
returns the scale factor.

Returns:
the scale factor

contains

public boolean contains(Gizmo giz)
checks if a board contains a given gizmo.

Parameters:
giz - the gizmo
Returns:
true the board contains the given gizmo

canAddBall

public boolean canAddBall(double radius,
                          Vect center)
checks if a ball with the given center and radius can be added to the board.

Parameters:
radius - the radius of the ball
center - the location of the center of the ball
Returns:
true if the ball can be added

canAddGhostBall

public boolean canAddGhostBall(double radius,
                               Vect center)
checks if a ghost ball with the given center and radius can be added to the board.

Parameters:
radius - the radius of the ball
center - the location of the center of the ball
Returns:
true if the ghost ball can be added

canAddRightFlipper

public boolean canAddRightFlipper(Vect topCenter,
                                  double distanceBetweenCenters,
                                  double radius,
                                  Angle currentAngle)
checks if a right flipper with the given properties can be added to the board.

Parameters:
topCenter - the center of rotation
distanceBetweenCenters - the distance between the centers of circles of the flipper shape
radius - the radius of the circles of the flipper shape
currentAngle - the initial angle that the flipper is in
Returns:
true if the flipper can be added

canAddRightFlipper

public boolean canAddRightFlipper(Vect topCenter,
                                  double distanceBetweenCenters,
                                  double radius)
checks if a right flipper with the given properties can be added to the board.

Parameters:
topCenter - the center of rotation
distanceBetweenCenters - the distance between the centers of circles of the flipper shape
radius - the radius of the circles of the flipper shape
Returns:
true if the flipper can be added

canAddBumper

public boolean canAddBumper(Shape shape)
checks if a bumper with the given shape can be added.

Parameters:
shape - the shape of the bumper
Returns:
true if the bumper can be added

canAddLeftFlipper

public boolean canAddLeftFlipper(Vect topCenter,
                                 double distanceBetweenCenters,
                                 double radius,
                                 Angle currentAngle)
checks if a left flipper with the given properties can be added to the board.

Parameters:
topCenter - the center of rotation
distanceBetweenCenters - the distance between the centers of circles of the flipper shape
radius - the radius of the circles of the flipper shape
currentAngle - the initial angle that the flipper is in
Returns:
true if the flipper can be added

canAddLeftFlipper

public boolean canAddLeftFlipper(Vect topCenter,
                                 double distanceBetweenCenters,
                                 double radius)
checks if a left flipper with the given properties can be added to the board.

Parameters:
topCenter - the center of rotation
distanceBetweenCenters - the distance between the centers of circles of the flipper shape
radius - the radius of the circles of the flipper shape
Returns:
true if the flipper can be added

canAddAbsorber

public java.lang.Boolean canAddAbsorber(Vect upperLeftCorner,
                                        double height,
                                        double width)
checks if an absorber with the given properties can be added to the board.

Parameters:
upperLeftCorner - the upper-left point of the absorber's rectangle
height - the height of the absorber's rectangle
width - the width of the absorber's rectangle
Returns:
true if the absorber can be added to the board

canAddExtender

public java.lang.Boolean canAddExtender(Vect upperLeft,
                                        double squareLength,
                                        double xSpanOfMotion,
                                        double ySpanOfMotion)
checks if an extender with the given properties can be added to the baord.

Parameters:
upperLeft - the upper-left vertex of the square of the extender
squareLength - the length of the sides of the square of the extender
xSpanOfMotion - the maximum horizontal expansion, which means that the max width of the extender is 2*xSpanOfMotion + squareLength
ySpanOfMotion - the maximum vertical expansion, which means that the max height of the extender is 2*ySpanOfMotion + squareLength
Returns:
true if the extender can be added

addBall

public Ball addBall(java.lang.String name,
                    java.awt.Color color,
                    Vect center,
                    Vect velocity,
                    double radius)
adds a ball to the board

Parameters:
name - the name of the ball
color - the color of the ball
center - the initial location of the center of the ball
velocity - the inital velocity of the ball
radius - the radius of the ball
Returns:
the ball that is added to the board, if the ball cannot be added to the board null is returned

addBall

public Ball addBall(Ball b)
adds a given ball to the board.

Parameters:
b - the ball to be added to the board
Returns:
the ball that is added to the board, if the ball cannot be added null is returned

addGhostBall

public Ball addGhostBall(java.lang.String name,
                         java.awt.Color color,
                         Vect center,
                         Vect velocity,
                         double radius)
adds a ghost ball to the board.

Parameters:
name - the name of the ball
color - the color of the ball
center - the location of the center of the ball
velocity - the initial velocity of the ball
radius - the radius of the ball
Returns:
the ball that is added to the board, if the ghost ball cannot be added null is returned

addBumper

public Bumper addBumper(java.lang.String name,
                        java.awt.Color color,
                        Shape shape)
adds a bumper to the board.

Parameters:
name - the name of the bumper
color - the color of the bumper
shape - the shape of the bumper
Returns:
the bumper that is added to the board, if the bumper cannot be added null is returned

addRightFlipper

public RotatingGizmo addRightFlipper(java.lang.String name,
                                     java.awt.Color color,
                                     Vect topCenter,
                                     double distanceBetweenCenters,
                                     double radius,
                                     Angle currentAngle)
adds a right flipper to the board.

Parameters:
name - the name of the flipper
color - the color of the flipper
topCenter - the center of rotation
distanceBetweenCenters - the distance between the two centers of circles of the flipper shape
radius - the radius of the circles of the flipper shape
currentAngle - the initial angle that the flipper is in
Returns:
the right flipper that is added to the board, if the flipper cannot be added null is returned

addRightFlipper

public RotatingGizmo addRightFlipper(java.lang.String name,
                                     java.awt.Color color,
                                     Vect topCenter,
                                     double distanceBetweenCenter,
                                     double radius)
adds a right flipper to the board.

Parameters:
name - the name of the flipper
color - the color of the flipper
topCenter - the center of rotation
distanceBetweenCenters - the distance between the two centers of circles of the flipper shape
radius - the radius of the circles of the flipper shape
Returns:
the right flipper that is added to the board, if the flipper cannot be added null is returned

addLeftFlipper

public RotatingGizmo addLeftFlipper(java.lang.String name,
                                    java.awt.Color color,
                                    Vect topCenter,
                                    double distanceBetweenCenters,
                                    double radius,
                                    Angle currentAngle)
adds a left flipper to the board.

Parameters:
name - the name of the flipper
color - the color of the flipper
topCenter - the center of rotation
distanceBetweenCenters - the distance between the two centers of circles of the flipper shape
radius - the radius of the circles of the flipper shape
currentAngle - the initial angle that the flipper is in
Returns:
the left flipper that is added to the board, if the flipper cannot be added null is returned

addLeftFlipper

public RotatingGizmo addLeftFlipper(java.lang.String name,
                                    java.awt.Color color,
                                    Vect topCenter,
                                    double distanceBetweenCenters,
                                    double radius)
adds a left flipper to the board.

Parameters:
name - the name of the flipper
color - the color of the flipper
topCenter - the center of rotation
distanceBetweenCenters - the distance between the two centers of circles of the flipper shape
radius - the radius of the circles of the flipper shape
currentAngle - the initial angle that the flipper is in
Returns:
the left flipper that is added to the board, if the flipper cannot be added null is returned

addAbsorber

public Absorber addAbsorber(java.lang.String name,
                            java.awt.Color color,
                            Vect upperLeftCorner,
                            double height,
                            double width,
                            Vect launchVelocity)
adds an absorber to the board.

Parameters:
name - of the absorber
color - of the absorber
upperLeftCorner - of the absorber
height - of the absorber
width - of the absorber
launchVelocity - of a ball that is shot from the absorber
Returns:
the absorber that is added to the board, if the absorber cannot be added null is returned

addExtender

public ExtenderGizmo addExtender(java.lang.String name,
                                 java.awt.Color color,
                                 Vect upperLeft,
                                 double squareLength,
                                 double xSpanOfMotion,
                                 double ySpanOfMotion,
                                 double velocity,
                                 double pausingTime)
Parameters:
name - the name of the extender
color - the color of the extender
upperLeft - the upper-left vertex of the square of the extender
squareLength - the length of the sides of the square of the extender
xSpanOfMotion - the maximum horizontal expansion, which means that the max width of the extender is 2*xSpanOfMotion + squareLength
ySpanOfMotion - the maximum vertical expansion, which means that the max height of the extender is 2*ySpanOfMotion + squareLength
velocity - the speed of the extender when its in motion
pausingTime - the pausing time between expansion/contraction transitions
Returns:
the extender that is added, if the extender cannot be added null is returned

canMoveGizmo

public boolean canMoveGizmo(Gizmo g,
                            Vect vector)

moveGizmo

public boolean moveGizmo(Gizmo g,
                         Vect vector)

canRotateGizmo

public boolean canRotateGizmo(Gizmo g,
                              Angle angle,
                              Vect centerOfRotation)
checks if the given gizmo can rotate by the given angle and around the given center of rotation.

Parameters:
g - the gizmo
angle - the angle to be rotated by
centerOfRotation - the center of rotation
Returns:
true if the gizmo can be rotated by the given angle and around the given center of rotation

RotateGizmo

public void RotateGizmo(Gizmo g,
                        Angle angle,
                        Vect centerOfRotation)

deleteGizmo

public void deleteGizmo(Gizmo g)
removes the given gizmo from the board.

Parameters:
g - the gizmo to be removed

deleteBall

public void deleteBall(Ball bl)
removes a ball from the board.

Parameters:
bl - the ball to be removed

getGizmoAt

public java.util.List<Gizmo> getGizmoAt(Vect pt)
returns a list of gizmos that are at the location specified.

Parameters:
pt - the location
Returns:
a list of gizmos that are at pt

getGizmo

public Gizmo getGizmo(java.lang.String n)
returns the gizmo with the specified name that is on the board.

Parameters:
n - name of the gizmo that is needed
Returns:
the gizmo with the specified name or null if no gizmo on the board has the specified name

getBalls

public java.util.List<Ball> getBalls()
returns a list of balls that are on the board.

Returns:
a list of balls that are on the board

getBumpers

public java.util.List<Bumper> getBumpers()
returns a list of the bumpers that are on the board.

Returns:
a list of the bumpers that are on the board

getRightFlippers

public java.util.List<RotatingGizmo> getRightFlippers()
returns the right flippers that are on the board.

Returns:
the right flippers that are on the board

getLeftFlippers

public java.util.List<RotatingGizmo> getLeftFlippers()
returns the list of the left flippers that are on the board.

Returns:
the list of the left flippers that are on the board

getAbsorbers

public java.util.List<Absorber> getAbsorbers()
returns a list of all the absorbers that are on the board.

Returns:
a list of all the absorbers that are on the board

getExtenders

public java.util.List<ExtenderGizmo> getExtenders()
returns a list of all the extender gizmos that are on the board.

Returns:
a list of all the extenders that are on the board

getRotatingGizmos

public java.util.List<RotatingGizmo> getRotatingGizmos()
returns a list of all the rotating objects that are on the board.

Returns:
a list of all the rotating objects that are on the board

getStationaryGizmosAt

public java.util.List<Gizmo> getStationaryGizmosAt(int x,
                                                   int y)
returns the stationary gizmos that intersect with the LxL square that its upper-left vertex is at (x*L,y*L).

Parameters:
x - the xcoord of the upper-left vertex before multiplying it by the scaling factor
y - the ycoord of the upper-left vertex before multiplying it by the scaling factor
Returns:
the stationary gizmos that interesect with the L*L square that its upperleft vertex is at (x*L,y*L)

getStationaryGizmos

public java.util.List<Gizmo> getStationaryGizmos()
returns a list of all the stationary objects that are on the board.

Returns:
a list of all the stationary objects that are on the board

getRotatingGizmosAt

public java.util.List<RotatingGizmo> getRotatingGizmosAt(int x,
                                                         int y)
returns the rotating gizmos that intersect with the LxL square that its upper-left vertex is at (x*L,y*L).

Parameters:
x - the xcoord of the upper-left vertex before multiplying it by the scaling factor
y - the ycoord of the upper-left vertex before multiplying it by the scaling factor
Returns:
the rotating gizmos that interesect with the L*L square that its upperleft vertex is at (x*L,y*L)

getExtendersAt

public java.util.List<ExtenderGizmo> getExtendersAt(int x,
                                                    int y)
returns the extenders that intersect with the LxL square that its upper-left vertex is at (x*L,y*L).

Parameters:
x - the xcoord of the upper-left vertex before multiplying it by the scaling factor
y - the ycoord of the upper-left vertex before multiplying it by the scaling factor
Returns:
the extenders that interesect with the L*L square that its upperleft vertex is at (x*L,y*L)

getDrawableGizmos

public java.util.List<Gizmo> getDrawableGizmos()
returns all the gizmos that are to be drawn.

Returns:
all the gizmos that are to be drawn

addConnection

public boolean addConnection(Gizmo source,
                             Gizmo target)
adds a connection between two gizmos that are on the board.

Parameters:
source - the gizmo that will trigger the target gizmo
target - the gizmo that will be triggered by the source gizmo
Returns:
true if the connection is successfully made

removeConnection

public boolean removeConnection(Gizmo source,
                                Gizmo target)
removes a connection between two gizmos that are on the board.

Parameters:
source - the gizmo that triggers the target gizmo
target - the gizmo that gets triggered by the source gizmo
Returns:
true if the connection was removed

addKeyUpTriggerToGizmo

public void addKeyUpTriggerToGizmo(java.lang.Integer key,
                                   Gizmo g)
adds an up keyboard trigger to the specified gizmo.

Parameters:
key - that will trigger the gizmo to do the gizmo's action
g - the gizmo that is triggered

addKeyDownTriggerToGizmo

public void addKeyDownTriggerToGizmo(java.lang.Integer key,
                                     Gizmo g)
adds a down keyboard trigger to the specified gizmo.

Parameters:
key - that will trigger the gizmo to do the gizmo's action
g - the gizmo that is triggered

deleteKeyUpTriggerToGizmo

public void deleteKeyUpTriggerToGizmo(java.lang.Integer key,
                                      Gizmo g)
removes a release key connection from the given key to the given gizmo

Parameters:
key - the key that triggers the gizmo
g - the gizmo that gets triggered by the key

deleteKeyDownTriggerToGizmo

public void deleteKeyDownTriggerToGizmo(java.lang.Integer key,
                                        Gizmo g)
removes a press key connection from the given key to the given gizmo

Parameters:
key - the key that triggers the gizmo
g - the gizmo that gets triggered by the key

upTrigger

public void upTrigger(java.lang.Integer key)
adds a key to a waiting list to trigger a gizmo.

Parameters:
key - that triggers a gizmo

downTrigger

public void downTrigger(java.lang.Integer key)
adds a key to a waiting list to trigger a gizmo.

Parameters:
key - that triggers a gizmo

executeKeyboardEvents

public void executeKeyboardEvents()
executes the action of the gizmos that got triggered.


getKeyUpTriggers

public java.util.Set<java.lang.Integer> getKeyUpTriggers()
returns all the keys that are mapped to trigger gizmos when are released.

Returns:
a set of Integers of all the keys that are mapped to trigger gizmos when released

getKeyDownTriggers

public java.util.Set<java.lang.Integer> getKeyDownTriggers()
returns all the keys that are mapped to trigger gizmos when are pressed.

Returns:
a set of Integers of all the keys that are mapped to trigger gizmos when pressed

getKeyUpGizmos

public java.util.List<Gizmo> getKeyUpGizmos(java.lang.Integer key)
returns the list of gizmos that are triggered by the specified key when released.

Parameters:
key -
Returns:
the list of the gizmos that are triggered by the specified key when released

getKeyDownGizmos

public java.util.List<Gizmo> getKeyDownGizmos(java.lang.Integer key)
returns the list of gizmos that are triggered by the specified key when pressed.

Parameters:
key -
Returns:
the list of the gizmos that are triggered by the specified key when pressed