Class Grid

java.lang.Object
  extended byGrid

public class Grid
extends java.lang.Object

Class representing the grid where caterpillar is moving and where barriers are placed.


Field Summary
static int cellSize
          Width and height (cells are squares) of interior of a cell.
 
Constructor Summary
Grid(int width, int height)
          Creates a new instance of grid
 
Method Summary
static java.awt.Point countCellPosition(int cellX, int cellY, int positionX, int positionY)
          Counts the upper-left corner point of a interior of a specific cell.
 int GetHeight()
          Gets the height of a grid (number of cells).
 int GetHeightPixels()
          Gets the height of a grid in pixels.
 int GetWidth()
          Gets the width of a grid (number of cells).
 int GetWidthPixels()
          Gets the width of a grid in pixels.
 void Paint(java.awt.Color backgroundColor, java.awt.Graphics g, int left, int top)
          Call this method to repaint the grid.
 void SetHeight(int height)
          Sets the height of a grid.
 void SetWidth(int width)
          Sets the width of a grid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cellSize

public static int cellSize
Width and height (cells are squares) of interior of a cell.

Constructor Detail

Grid

public Grid(int width,
            int height)
Creates a new instance of grid

Parameters:
width - Width of a grid (number of cells).
height - Height of a grid (number of cells).
Method Detail

Paint

public void Paint(java.awt.Color backgroundColor,
                  java.awt.Graphics g,
                  int left,
                  int top)
Call this method to repaint the grid.

Parameters:
backgroundColor - Background color of a grid. Is used to clear grid if it is reduced.
g - Graphics object used to painting.
left - x-coordinate of upper-left corner of a grid (in pixels).
top - y-coordinate of upper-left corner of a grid (in pixels).

GetWidthPixels

public int GetWidthPixels()
Gets the width of a grid in pixels.

Returns:
The whole width of a grid in pixels.

GetHeightPixels

public int GetHeightPixels()
Gets the height of a grid in pixels.

Returns:
The whole height of a grid in pixels.

SetWidth

public void SetWidth(int width)
              throws java.lang.IllegalArgumentException
Sets the width of a grid.

Parameters:
width - Width of a grid (number of cells).
Throws:
java.lang.IllegalArgumentException - Throws if width is less than 1 or greater than 50.

SetHeight

public void SetHeight(int height)
               throws java.lang.IllegalArgumentException
Sets the height of a grid.

Parameters:
height - Height of a grid (number of cells).
Throws:
java.lang.IllegalArgumentException - Throws if height is less than 1 or greater than 50.

GetWidth

public int GetWidth()
Gets the width of a grid (number of cells).

Returns:
Wdith of a grid.

GetHeight

public int GetHeight()
Gets the height of a grid (number of cells).

Returns:
Height of a grid.

countCellPosition

public static java.awt.Point countCellPosition(int cellX,
                                               int cellY,
                                               int positionX,
                                               int positionY)
Counts the upper-left corner point of a interior of a specific cell.

Parameters:
cellX - Column number. Zero-based.
cellY - Row number. Zero-based.
positionX - X-coordinate (in pixels) of upper-left corner of a grid.
positionY - Y-coordinate (in pixels) of upper-left corner of a grid.
Returns:
upper-left corner point of a interior of a specific cell