PinBallDomain
Class PolygonObstacle

java.lang.Object
  extended by PinBallDomain.PolygonObstacle
All Implemented Interfaces:
Obstacle

public class PolygonObstacle
extends java.lang.Object
implements Obstacle

Obstacle class for polygonal obstacles. This is the only type of obstacle implemented at the moment.

Author:
George Konidaris (gdk at cs dot umass dot edu)

Method Summary
 boolean collision(Ball b)
          Determine whether or not there has been a collision.
 double[] collisionEffect(Ball b)
          Determine the effect of the ball's collision with the obstacle.
static PolygonObstacle create(java.lang.String line)
          Create a polygon obstacle from a line of configuration file text.
 Point getIntercept()
          Get the last intercept point.
 java.util.ArrayList<Point> getPoints()
          Get the Point variables making up the obstacle.
 boolean inside(Point p)
          Determine whether a point lies within the polygon.
static boolean matchTag(java.lang.String line)
          Determine whether a given config input text line matches a polygon obstacle.
 void write(java.io.FileWriter f)
          Write the polygon to a file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

collision

public boolean collision(Ball b)
Determine whether or not there has been a collision.

Specified by:
collision in interface Obstacle
Parameters:
b - the ball
Returns:
true if there was a collision, false if there wasn't.

collisionEffect

public double[] collisionEffect(Ball b)
Determine the effect of the ball's collision with the obstacle. NOTE: must call LineIntersect (probably via collision) first

Specified by:
collisionEffect in interface Obstacle
Parameters:
b - the ball
Returns:
the collision effect (array of 2 doubles)

matchTag

public static boolean matchTag(java.lang.String line)
Determine whether a given config input text line matches a polygon obstacle.

Parameters:
line - the input line
Returns:
true if there's a match, false if not

write

public void write(java.io.FileWriter f)
           throws java.io.IOException
Write the polygon to a file.

Specified by:
write in interface Obstacle
Parameters:
f - the file to write to
Throws:
java.io.IOException

create

public static PolygonObstacle create(java.lang.String line)
Create a polygon obstacle from a line of configuration file text.

Parameters:
line - the line
Returns:
the resulting polygon obstacle

getPoints

public java.util.ArrayList<Point> getPoints()
Get the Point variables making up the obstacle.

Returns:
an ArrayList of Points

getIntercept

public Point getIntercept()
Get the last intercept point.

Specified by:
getIntercept in interface Obstacle
Returns:
the intercept point

inside

public boolean inside(Point p)
Determine whether a point lies within the polygon.

Specified by:
inside in interface Obstacle
Parameters:
p - the test point
Returns:
true if p lies within the obstacle, false otherwise