All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.monpetitcoin.java.PrisonerGame.Square2DBoard

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----com.monpetitcoin.java.PrisonerGame.Square2DBoard

public class Square2DBoard
extends java.awt.Canvas
implements com.monpetitcoin.java.PrisonerGame.GameBoard
This class represents a typical checkerboard grid: a two-dimensional array of Pawns. It implements the GameBoard interface to behave as a proper game board.

Version:
1.00, 21 August 2001
Author:
François Suter
See Also:
com.monpetitcoin.java.PrisonerGame.Pawn, com.monpetitcoin.java.PrisonerGame.GameBoard

Variable Index

 o board
 o boardPadding
 o boardSize
 o cellPadding
 o cellSize
 o columnCounter
 o columns
 o MAX_NEIGHBORS
 o rowCounter
 o rows
 o scrollbarOffset

Constructor Index

 o Square2DBoard(int, int, int, int)

Method Index

 o getColumns()
 o getItem(int)
 o getMaxNeighbors()
 o getMinimumSize()
Return the board size calculated in setBoardSize()
 o getPreferredSize()
Return the board size calculated in setBoardSize()
 o getRows()
 o getTileShape()
 o hasNext()
 o hasPrevious()
 o lastIndex()
 o newItem(Pawn)
 o next()
 o paint(Graphics)
This methods draws the board and its Pawns.
 o previous()
 o reset()
 o setBoardSize(int, int)
This method calculates the real size needed by the board.
 o setNeighborsLists()

Variables

 o MAX_NEIGHBORS
 private static final int MAX_NEIGHBORS
 o board
 com.monpetitcoin.java.PrisonerGame.Pawn board[][]
 o columns
 int columns
 o rows
 int rows
 o cellSize
 int cellSize
 o cellPadding
 int cellPadding
 o columnCounter
 private int columnCounter
 o rowCounter
 private int rowCounter
 o scrollbarOffset
 private int scrollbarOffset
 o boardPadding
 private java.awt.Insets boardPadding
 o boardSize
 private java.awt.Dimension boardSize

Constructors

 o Square2DBoard
 public Square2DBoard(int width,
                      int height,
                      int columns,
                      int rows)

Methods

 o setBoardSize
 private void setBoardSize(int width,
                           int height)
This method calculates the real size needed by the board. On a checkerboard each cell is represented as a square. It it thus necessary to calculate the largest cell size possible that will allow to fit all the squares in both dimensions. If the cellSize is larger than 2 (pixels), it is set to 1 and the padding (the space between cells) is set to zero. Otherwise, the padding is set to 1 and the cellSize decreased accordingly.

 o getColumns
 public int getColumns()
 o getRows
 public int getRows()
 o newItem
 public boolean newItem(com.monpetitcoin.java.PrisonerGame.Pawn newPawn)
 o getTileShape
 public int getTileShape()
 o getMaxNeighbors
 public int getMaxNeighbors()
 o setNeighborsLists
 public void setNeighborsLists()
 o next
 public com.monpetitcoin.java.PrisonerGame.Pawn next()
 o hasNext
 public boolean hasNext()
 o previous
 public com.monpetitcoin.java.PrisonerGame.Pawn previous()
 o hasPrevious
 public boolean hasPrevious()
 o reset
 public void reset()
 o lastIndex
 public void lastIndex()
 o getItem
 public com.monpetitcoin.java.PrisonerGame.Pawn getItem(int itemID)
 o getMinimumSize
 public java.awt.Dimension getMinimumSize()
Return the board size calculated in setBoardSize()

Returns:
the actual board size
Overrides:
getMinimumSize in class java.awt.Component
See Also:
setBoardSize
 o getPreferredSize
 public java.awt.Dimension getPreferredSize()
Return the board size calculated in setBoardSize()

Returns:
the actual board size
Overrides:
getPreferredSize in class java.awt.Component
See Also:
setBoardSize
 o paint
 public void paint(java.awt.Graphics g)
This methods draws the board and its Pawns. It calculates the position of each Pawn's graphical representation and then asks the Pawn to draw itself at this point. Note that there is not representation of the board itself.

Overrides:
paint in class java.awt.Canvas

All Packages  Class Hierarchy  This Package  Previous  Next  Index