jtge.util.grid
Interface IGrid

All Known Implementing Classes:
Grid

public interface IGrid

Abstract representation of a grid.

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

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.
 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.
 int size()
          Retrieve the maximum number of tiles this hexGrid can hold.
 

Method Detail

getWidth

public int getWidth()
Retrieve the width.

Returns:
an int representing the maximum width of this grid

getHeight

public int getHeight()
Retrieve the height.

Returns:
an int representing the maximum height of this grid

size

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

Returns:
the maximum number of tiles.

setTile

public 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.

Parameters:
tile - the tile to set in this grid
coordinate - the coordinate to place the tile at

getTile

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

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 boolean isValid(Coordinate coordinate)
Checks if the coordinate supplied is valid for this grid.

Parameters:
coordinate - the coordinate to test
Returns:
whether the given coordinate is within the bound of this grid or not

getAdjacent

public 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.

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.

linearIterator

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

Returns:
an iterator on coordinates

linearTileIterator

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

Returns:
an iterator on tiles

adjacentIterator

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

Parameters:
coordinate - a coordinate
Returns:
an iterator on coordinates

adjacentTileIterator

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

Parameters:
coordinate - a coordinate
Returns:
an iterator on tiles


Copyright © 2003-2005 . All Rights Reserved.