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
-
board
-
-
boardPadding
-
-
boardSize
-
-
cellPadding
-
-
cellSize
-
-
columnCounter
-
-
columns
-
-
MAX_NEIGHBORS
-
-
rowCounter
-
-
rows
-
-
scrollbarOffset
-
-
Square2DBoard(int, int, int, int)
-
-
getColumns()
-
-
getItem(int)
-
-
getMaxNeighbors()
-
-
getMinimumSize()
- Return the board size calculated in setBoardSize()
-
getPreferredSize()
- Return the board size calculated in setBoardSize()
-
getRows()
-
-
getTileShape()
-
-
hasNext()
-
-
hasPrevious()
-
-
lastIndex()
-
-
newItem(Pawn)
-
-
next()
-
-
paint(Graphics)
- This methods draws the board and its Pawns.
-
previous()
-
-
reset()
-
-
setBoardSize(int, int)
- This method calculates the real size needed by the board.
-
setNeighborsLists()
-
MAX_NEIGHBORS
private static final int MAX_NEIGHBORS
board
com.monpetitcoin.java.PrisonerGame.Pawn board[][]
columns
int columns
rows
int rows
cellSize
int cellSize
cellPadding
int cellPadding
columnCounter
private int columnCounter
rowCounter
private int rowCounter
scrollbarOffset
private int scrollbarOffset
boardPadding
private java.awt.Insets boardPadding
boardSize
private java.awt.Dimension boardSize
Square2DBoard
public Square2DBoard(int width,
int height,
int columns,
int rows)
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.
getColumns
public int getColumns()
getRows
public int getRows()
newItem
public boolean newItem(com.monpetitcoin.java.PrisonerGame.Pawn newPawn)
getTileShape
public int getTileShape()
getMaxNeighbors
public int getMaxNeighbors()
setNeighborsLists
public void setNeighborsLists()
next
public com.monpetitcoin.java.PrisonerGame.Pawn next()
hasNext
public boolean hasNext()
previous
public com.monpetitcoin.java.PrisonerGame.Pawn previous()
hasPrevious
public boolean hasPrevious()
reset
public void reset()
lastIndex
public void lastIndex()
getItem
public com.monpetitcoin.java.PrisonerGame.Pawn getItem(int itemID)
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
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
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