hexIT
Class Board

java.lang.Object
  extended byhexIT.Board
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
DiamondBoard, HexagonalBoard

public abstract class Board
extends java.lang.Object
implements java.io.Serializable

This class represents a configuration of hexagons, a "board". There can be many possibilities for how to layout the Hexagons(tiles) on the board. These specific arrangements are abstractly defined here, and left to be implemented by subclasses. This base class contains all the functions that can be used by all board types.

See Also:
Serialized Form

Constructor Summary
Board()
          Creates a new, empty Board.
Board(int new_size)
          Creates a new board of the specified size.
 
Method Summary
 void createFrame(java.lang.String name)
          Creates a Frame to view this board in.
abstract  int distance(Hexagon h1, Hexagon h2)
          A distance metric between 2 separate hexagons.
 Hexagon findObject(Drawable obj)
          Finds an object that is on one of the hexagons.
abstract  java.util.List getExterior()
          Returns the exterior of the hexagonal board.
abstract  java.util.List getFOV(int hexx1, int hexy1, int maxradius)
          Gets all the hexes that can be "seen" in the Field-of-View of an observer at hex coordinate (hexx1,hexy1).
abstract  java.util.List getLOS(int hexx1, int hexy1, int hexx2, int hexy2)
          Gets all the hexes that can be "seen" from one hexagon to another.
abstract  java.util.List getShortestPath(int hexx1, int hexy1, int hexx2, int hexy2)
          Returns the shortest path (a list of haxagons) from hex locations (hexy1,hexy2) to (hexx2, hexy2);
abstract  java.util.List getSurrounding(int hexx, int hexy, int radius)
          Gets all the hexes surrounding the hexes at hex coords (x,y) within a specified radius (in hex units).
 void setFrameSize(int new_width, int new_height)
          Sets the size of the frame, in pixels, to the specified values.
 void show()
          Show the internal frame created by createFrame().
abstract  java.util.Iterator tilesIterator()
          Returns an iterator over all hexagons in the board, in no particular order.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Board

public Board()
Creates a new, empty Board.


Board

public Board(int new_size)
Creates a new board of the specified size. The semantics of this size setting depends on the board type (sub type).

Method Detail

createFrame

public void createFrame(java.lang.String name)
Creates a Frame to view this board in. By default the frame is not visible.


setFrameSize

public void setFrameSize(int new_width,
                         int new_height)
Sets the size of the frame, in pixels, to the specified values.


show

public void show()
Show the internal frame created by createFrame().


getSurrounding

public abstract java.util.List getSurrounding(int hexx,
                                              int hexy,
                                              int radius)
Gets all the hexes surrounding the hexes at hex coords (x,y) within a specified radius (in hex units).


getLOS

public abstract java.util.List getLOS(int hexx1,
                                      int hexy1,
                                      int hexx2,
                                      int hexy2)
Gets all the hexes that can be "seen" from one hexagon to another. "Seen" means all the hexes that intersect a straight line drawn from the source hexagon to the destination hexagon. (hexx1,hexy1) are the hex coordinates for the source while (hexx2, hexy2) are the hex coordinates for the destination.


getFOV

public abstract java.util.List getFOV(int hexx1,
                                      int hexy1,
                                      int maxradius)
Gets all the hexes that can be "seen" in the Field-of-View of an observer at hex coordinate (hexx1,hexy1). The FOV is all the hexagons that can be seen from a 360 degree cone spawning out from the center of the source hexagon. Note that objects are considered to take up the full hexagons they are on, and block whatever us behind them with respect to the observer. The maxradius is the "range" of sight or view.


getShortestPath

public abstract java.util.List getShortestPath(int hexx1,
                                               int hexy1,
                                               int hexx2,
                                               int hexy2)
Returns the shortest path (a list of haxagons) from hex locations (hexy1,hexy2) to (hexx2, hexy2);


getExterior

public abstract java.util.List getExterior()
Returns the exterior of the hexagonal board. What exactly the exterior is depends on the board type, but should be the outer layer of hexagons: the ones that form the end of the board.


distance

public abstract int distance(Hexagon h1,
                             Hexagon h2)
A distance metric between 2 separate hexagons. This is the minimum # of hex tiles it takes to walk from one hex to the other. It is also the length of the shortest path.


tilesIterator

public abstract java.util.Iterator tilesIterator()
Returns an iterator over all hexagons in the board, in no particular order.


findObject

public Hexagon findObject(Drawable obj)
Finds an object that is on one of the hexagons. Returns the hexagon on which the object is located, or null if not found. Note: this algortihm compares via reference values, not by using equals().