ctf.environment
Class Grid

java.lang.Object
  |
  +--ctf.environment.Grid
Direct Known Subclasses:
AgentGrid, MineGrid, ObstacleGrid, SingletonGrid

abstract class Grid
extends Object

Generic grid for a capture the flag board. Each location on board can either contain an item or not, but the item type isn't specified. Designed to be extended by more specific grids. Note that this class only has package access enabled.

Author:
Jason Rohrer

Field Summary
protected  Color mFillColor
           
protected  Color mLineColor
           
 
Constructor Summary
protected Grid(int inBoardSize)
          Constructs a Grid.
protected Grid(int inBoardSize, Color inLineColor, Color inFillColor)
          Constructs a Grid.
 
Method Summary
(package private)  void add(EnvironmentLocation inLocation)
          Adds an object to the grid.
(package private)  void add(int inX, int inY)
          Adds an object to the grid.
(package private)  void clear()
          Clears all objects from the grid.
(package private)  void draw(Graphics inGraphics, int inStartX, int inStartY, int inWide, int inHigh)
          Draws the grid and all objects in it.
protected abstract  void drawObject(Graphics inGraphics, int inStartX, int inStartY, int inWide, int inHigh)
          Draws a graphical representation of an object in a specific location in a graphics context.
(package private)  boolean exists(EnvironmentLocation inLocation)
          Checks whether an object exists in a particular grid location.
(package private)  boolean exists(int inX, int inY)
          Checks whether an object exists in a particular grid location.
 Dimension getDrawDimension(int inSuggestedWide, int inSuggestedHigh)
          Gets the actual dimensions of the drawn grid when particular dimensions are requested.
(package private)  void remove(EnvironmentLocation inLocation)
          Removes an object from the grid.
(package private)  void remove(int inX, int inY)
          Removes an object to the grid.
 void setFillColor(Color inFillColor)
          Set fill color for drawing grid objects.
 void setLineColor(Color inLineColor)
          Set line color for drawing grid objects.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mLineColor

protected Color mLineColor

mFillColor

protected Color mFillColor
Constructor Detail

Grid

protected Grid(int inBoardSize)
Constructs a Grid.
Parameters:
inBoardSize - the board width and height, in number of grid spaces.

Grid

protected Grid(int inBoardSize,
               Color inLineColor,
               Color inFillColor)
Constructs a Grid.
Parameters:
inBoardSize - the board width and height, in number of grid spaces.
inLineColor - line color for drawing objects in this grid.
inFillColor - fill color for drawing objects in this grid.
Method Detail

add

void add(int inX,
         int inY)
Adds an object to the grid.
Parameters:
inX - the x component of the object's location.
inY - the y component of the object's location.

add

void add(EnvironmentLocation inLocation)
Adds an object to the grid.
Parameters:
inLocation - location to add object in.

remove

void remove(int inX,
            int inY)
Removes an object to the grid.
Parameters:
inX - the x component of the object's location.
inY - the y component of the object's location.

remove

void remove(EnvironmentLocation inLocation)
Removes an object from the grid.
Parameters:
inLocation - location to remove object from.

clear

void clear()
Clears all objects from the grid.

exists

boolean exists(int inX,
               int inY)
Checks whether an object exists in a particular grid location.
Parameters:
inX - the x component of the location to check.
inY - the y component of the location to check.
Returns:
true iff an object exists at inX and inY.

exists

boolean exists(EnvironmentLocation inLocation)
Checks whether an object exists in a particular grid location.
Parameters:
inLocation - location to check.
Returns:
true iff an object exists at inLocation.

setFillColor

public void setFillColor(Color inFillColor)
Set fill color for drawing grid objects.
Parameters:
inFillColor - fill color for drawing objects in this grid.

setLineColor

public void setLineColor(Color inLineColor)
Set line color for drawing grid objects.
Parameters:
inLineColor - line color for drawing objects in this grid.

draw

void draw(Graphics inGraphics,
          int inStartX,
          int inStartY,
          int inWide,
          int inHigh)
Draws the grid and all objects in it.
Parameters:
inGraphics - the graphics context in which to draw the grid.
inStartX - the starting x coordinate in inGraphics for the grid.
inStartY - the starting y coordinate in inGraphics for the grid.
inWide - the width of the grid image.
inHigh - the height of the grid image.

getDrawDimension

public Dimension getDrawDimension(int inSuggestedWide,
                                  int inSuggestedHigh)
Gets the actual dimensions of the drawn grid when particular dimensions are requested. Because of the requirement that each grid space be the same screen size, a grid drawing can be smaller than requested.
Parameters:
inSuggestedWide - width to be requested for draw.
inSuggestedHigh - height to be requested for draw.
Returns:
the actual dimensions of the drawn grid.

drawObject

protected abstract void drawObject(Graphics inGraphics,
                                   int inStartX,
                                   int inStartY,
                                   int inWide,
                                   int inHigh)
Draws a graphical representation of an object in a specific location in a graphics context. To be implemented by all non-abstract subclasses for drawing graphical representations of particular kinds of grid objects.
Parameters:
inGraphics - the graphics context in which to draw the object.
inStartX - the starting x coordinate in inGraphics for the object.
inStartY - the starting y coordinate in inGraphics for the object.
inWide - the width of the object image.
inHigh - the height of the object image.