Class Board
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Container
|
+----java.awt.Panel
|
+----Board
- class Board
- extends Panel
Board class for the Java Othello Openings Applet.
Handles drawing the board and making individual moves on the Othello board.
- Version:
- 1.00
- Author:
- Bill Lorton
-
_board
-
A 2x2 array of disc types (EMPTY,WHITE,BLACK).
-
_last_c
-
Used to determine where to draw the last move indicator.
-
_last_r
-
Used to determine where to draw the last move indicator.
-
Board(Othello)
-
Board class constructor.
-
_flip(int, int, int, int)
-
Flips the discs intersecting the placed disc in one direction.
-
_paint(Graphics)
-
Draws the board.
-
_squarePos(int)
-
Returns the position on the board in pixels for the given row or column.
-
clear()
-
Sets the data structures back to their initial state.
-
getMinimumSize()
-
Calculates the size of the board.
-
init()
-
Creates the needed fonts, loads the disc images and initializes the
data structures.
-
paint(Graphics)
-
Draws the board.
-
placeDisc(int, int, boolean)
-
Makes one move.
-
update(Graphics)
-
Draws the board.
_board
protected int _board[][]
- A 2x2 array of disc types (EMPTY,WHITE,BLACK).
_last_r
protected int _last_r
- Used to determine where to draw the last move indicator.
_last_c
protected int _last_c
- Used to determine where to draw the last move indicator.
Board
public Board(Othello app)
- Board class constructor.
- Parameters:
- app - the othello applet class which is used to load the board's
images
_squarePos
protected int _squarePos(int rc)
- Returns the position on the board in pixels for the given row or column.
- Parameters:
- rc - an x or y index for the board. valid values are 0-7
- Returns:
- the x or y position in pixels for the row or column
_flip
protected int _flip(int r,
int c,
int row_inc,
int col_inc)
- Flips the discs intersecting the placed disc in one direction. For example
with a row_inc of -1 and a col_inc of -1, discs are flipped diagonally
from the placed disc towards the upper left. The placed disc is never
modified.
- Parameters:
- r - the row of the disc that was placed
- c - the column of the disc that was placed
- row_inc - the row increment value
- col_inc - the column increment value
- Returns:
- number of discs that were flipped
_paint
protected void _paint(Graphics g)
- Draws the board.
- Parameters:
- g - the graphics context
getMinimumSize
public Dimension getMinimumSize()
- Calculates the size of the board.
- Returns:
- the minimum size of the board
- Overrides:
- getMinimumSize in class Container
init
public void init()
- Creates the needed fonts, loads the disc images and initializes the
data structures. The Othello class is used to load the images.
paint
public void paint(Graphics g)
- Draws the board.
- Parameters:
- g - the graphics context
- Overrides:
- paint in class Container
update
public void update(Graphics g)
- Draws the board.
- Parameters:
- g - the graphics context
- Overrides:
- update in class Container
clear
public void clear()
- Sets the data structures back to their initial state.
placeDisc
public void placeDisc(int r,
int c,
boolean white_move)
- Makes one move. The position specified for the move cannot already
have a disc. The disc placement must flip at least one existing disc.
- Parameters:
- r - the row of the move
- c - the column of the move
- white_move - true if a white disc is being placed, false if a
black disc is being placed