mahjong
Class Board

java.lang.Object
  extended by mahjong.Board

public class Board
extends java.lang.Object

This class represents a mahjong board with tiles in it.


Field Summary
private  Tile[][][] content
          The actual board is a 3d array of Tile objects.
static int GROUPSIZE
          Constant number of tiles in a group.
private  int height
          Dimensions of a layer.
static int MAXGROUPS
          Constant number of groups.
private  java.util.Random r
          The random variable used to construct the board.
private  int width
          Dimensions of a layer.
 
Constructor Summary
Board(java.util.Random r1, java.lang.String boardName)
          Construct a new board from a given template file, but using a given (seeded) random variable.
Board(java.lang.String boardName)
          Construct a new board from a given template file.
 
Method Summary
protected  void build(java.util.Random r1)
          Basic setup routine.
 boolean free(Tile t)
          Return true if the given tile is free.
 Tile[][][] getContent()
          Getter.
 int getHeight()
          Getter.
 int getWidth()
          Getter.
 boolean isEmpty()
          Check if the board is empty or not.
 boolean remove(Tile t)
          Attempt to remove the given tile; the tile must be present.
 void reset()
          Wipes the current board and constructs a new one using the current Random variable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GROUPSIZE

public static final int GROUPSIZE
Constant number of tiles in a group.

See Also:
Constant Field Values

MAXGROUPS

public static final int MAXGROUPS
Constant number of groups.

See Also:
Constant Field Values

r

private java.util.Random r
The random variable used to construct the board.


content

private Tile[][][] content
The actual board is a 3d array of Tile objects. Each tile actually occupies a block of 4 cells in the same dimension to allow for partial overlap of tiles.


height

private int height
Dimensions of a layer.


width

private int width
Dimensions of a layer.

Constructor Detail

Board

public Board(java.lang.String boardName)
Construct a new board from a given template file.

Parameters:
boardName - template file name.

Board

public Board(java.util.Random r1,
             java.lang.String boardName)
Construct a new board from a given template file, but using a given (seeded) random variable.

Parameters:
boardName - template file name.
r1 - the random variable to use.
Method Detail

build

protected void build(java.util.Random r1)
Basic setup routine. Uses or creates a random number generator and then initializes the board and the gui.

Parameters:
r1 - the random number generator to use.

reset

public void reset()
Wipes the current board and constructs a new one using the current Random variable.


isEmpty

public boolean isEmpty()
Check if the board is empty or not.

Returns:
true if the board has no more tiles.

remove

public boolean remove(Tile t)
Attempt to remove the given tile; the tile must be present.

Parameters:
t - the tile to remove.
Returns:
false if the tile wasn't there, or true if it was.

free

public boolean free(Tile t)
Return true if the given tile is free.

Parameters:
t - The Tile to check.
Returns:
true if the Tile is visible and can be removed, false otherwise.

getContent

public Tile[][][] getContent()
Getter.

Returns:
Tile content.

getWidth

public int getWidth()
Getter.

Returns:
board width in tiles.

getHeight

public int getHeight()
Getter.

Returns:
board height in tiles.