Class Barriers

java.lang.Object
  extended byBarriers

public class Barriers
extends java.lang.Object

Class representing barriers in a grid.


Constructor Summary
Barriers(int width, int height, int numberOfBarriers, int positionX, int positionY, int headPositionX, int headPositionY)
          Creates a new instance of Barriers
 
Method Summary
 void Delete(java.awt.Graphics g, java.awt.Color backgroundColor)
          Clears barriers from a grid on a form.
 boolean IsBarrier(int x, int y)
          Tests if there is a barrier at the specific point.
 void paint(java.awt.Graphics g)
          Paints barriers in a form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Barriers

public Barriers(int width,
                int height,
                int numberOfBarriers,
                int positionX,
                int positionY,
                int headPositionX,
                int headPositionY)
         throws java.lang.IllegalArgumentException,
                java.lang.RuntimeException
Creates a new instance of Barriers

Parameters:
width - Width of grid where to create barriers. (Number of cells.)
height - Height of grid where to create barriers. (Number of cells.)
numberOfBarriers - Number of barriers to create. Must be 0 <= numberOfBarriers < width * height * 10
positionX - X-coordinate of upper-left corner of a grid where barriers are displayed (in pixels).
positionY - Y-coordinate of upper-left corner of a grid where barriers are displayed (in pixels).
headPositionX - X-coordinate of a point in grid in whose nearness are no barriers created. In the concrete it's 3 cells around that point. Usually this is a position of caterpillar's head.
headPositionY - Y-coordinate of a point in grid in whose nearness are no barriers created. In the concrete it's 3 cells around that point. Usually this is a position of caterpillar's head.
Throws:
java.lang.IllegalArgumentException - If too big number of barriers is passed, IllegalArgumentException is thrown. Too big means greather then (width * height / 10).
java.lang.RuntimeException
Method Detail

IsBarrier

public boolean IsBarrier(int x,
                         int y)
Tests if there is a barrier at the specific point.

Parameters:
x - X-coordinate (in cells)
y - Y-coordinate (in cells)
Returns:
True if there is a barrier, false otherwise.

paint

public void paint(java.awt.Graphics g)
Paints barriers in a form.

Parameters:
g - Graphics object used to painting.

Delete

public void Delete(java.awt.Graphics g,
                   java.awt.Color backgroundColor)
Clears barriers from a grid on a form. (Repaints the cells by the background color.)

Parameters:
g - Graphics object used to painting.
backgroundColor - Background color.