jtge.util.grid
Class Grid

java.lang.Object
  extended byjtge.util.grid.Grid
All Implemented Interfaces:
IGrid

public class Grid
extends java.lang.Object
implements IGrid

Implements a grid.

Version:
$Id: Grid.java,v 1.5 2005/09/09 22:12:34 mat007 Exp $
Author:
Jean-Laurent Fabre de Morlhon

Constructor Summary
Grid(int width, int height, IDirectionGroup directionGroup)
          Create a grid.
Grid(int width, int height, IDirectionGroup directionGroup, ITorus torus)
          Create a grid.
 
Method Summary
 java.util.Iterator adjacentIterator(Coordinate coordinate)
          Create an iterator on coordinates around a given coordinate.
 java.util.Iterator adjacentTileIterator(Coordinate coordinate)
          Create an iterator on tiles around a given coordinate.
 Coordinate getAdjacent(Coordinate coordinate, IDirection direction)
          returns the adjacent Coordinate given a Coordinate center and a Direction.
Coordinate returned are always valid, an CoordinateOutOfBoundException is thrown if you asked for an impossible coordinate.
 int getHeight()
          Retrieve the height.
 ITile getTile(Coordinate coordinate)
          Retrieve the tile object at the supplied coordinate.
 int getWidth()
          Retrieve the width.
 boolean isValid(Coordinate coordinate)
          Checks if the coordinate supplied is valid for this grid.
 java.util.Iterator linearIterator()
          Create an iterator on coordinates from the top left to the bottom right coordinate.
 java.util.Iterator linearTileIterator()
          Create an iterator on tiles from the top left to the bottom right coordinate.
 void setTile(ITile tile, Coordinate coordinate)
          Assign the supplied tile to this grid.

If a tile is already present at coordinate() for the current grid it gets replaced.

 int size()
          Retrieve the maximum number of tiles this hexGrid can hold.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Grid

public Grid(int width,
            int height,
            IDirectionGroup directionGroup,
            ITorus torus)
Create a grid.

Parameters:
width - the grid width in tiles
height - the grid height in tiles
directionGroup - the direction group strategy
torus - the torus

Grid

public Grid(int width,
            int height,
            IDirectionGroup directionGroup)
Create a grid.

Parameters:
width - the grid width in tiles
height - the grid height in tiles
directionGroup - the direction group strategy
Method Detail

getWidth

public final int getWidth()
Retrieve the width.

Specified by:
getWidth in interface IGrid
Returns:
an int representing the maximum width of this grid

getHeight

public final int getHeight()
Retrieve the height.

Specified by:
getHeight in interface IGrid
Returns:
an int representing the maximum height of this grid

size

public final int size()
Retrieve the maximum number of tiles this hexGrid can hold.

Specified by:
size in interface IGrid
Returns:
the maximum number of tiles.

setTile

public final void setTile(ITile tile,
                          Coordinate coordinate)
Assign the supplied tile to this grid.

If a tile is already present at coordinate() for the current grid it gets replaced.

Specified by:
setTile in interface IGrid
Parameters:
tile - the tile to set in this grid
coordinate - the coordinate to place the tile at

getTile

public final ITile getTile(Coordinate coordinate)
Retrieve the tile object at the supplied coordinate.

Specified by:
getTile in interface IGrid
Parameters:
coordinate - the coordinate in the grid you want the tile for
Returns:
the tile at the current coordinate or null if none

isValid

public final boolean isValid(Coordinate coordinate)
Checks if the coordinate supplied is valid for this grid.

Specified by:
isValid in interface IGrid
Parameters:
coordinate - the coordinate to test
Returns:
whether the given coordinate is within the bound of this grid or not

getAdjacent

public final Coordinate getAdjacent(Coordinate coordinate,
                                    IDirection direction)
returns the adjacent Coordinate given a Coordinate center and a Direction.
Coordinate returned are always valid, an CoordinateOutOfBoundException is thrown if you asked for an impossible coordinate.

Specified by:
getAdjacent in interface IGrid
Parameters:
coordinate - the coordinate from which the adjacent coordinate is calculated.
direction - the direction from which the adjacent coordinate is calculated.
Returns:
an adjacent Coordiante given the center and direction or null if there is no adjacent coordinate.

adjacentIterator

public final java.util.Iterator adjacentIterator(Coordinate coordinate)
Create an iterator on coordinates around a given coordinate.

Specified by:
adjacentIterator in interface IGrid
Parameters:
coordinate - a coordinate
Returns:
an iterator on coordinates

adjacentTileIterator

public final java.util.Iterator adjacentTileIterator(Coordinate coordinate)
Create an iterator on tiles around a given coordinate.

Specified by:
adjacentTileIterator in interface IGrid
Parameters:
coordinate - a coordinate
Returns:
an iterator on tiles

linearIterator

public final java.util.Iterator linearIterator()
Create an iterator on coordinates from the top left to the bottom right coordinate.

Specified by:
linearIterator in interface IGrid
Returns:
an iterator on coordinates

linearTileIterator

public final java.util.Iterator linearTileIterator()
Create an iterator on tiles from the top left to the bottom right coordinate.

Specified by:
linearTileIterator in interface IGrid
Returns:
an iterator on tiles


Copyright © 2003-2005 . All Rights Reserved.