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

Variable Index

 o _board
A 2x2 array of disc types (EMPTY,WHITE,BLACK).
 o _last_c
Used to determine where to draw the last move indicator.
 o _last_r
Used to determine where to draw the last move indicator.

Constructor Index

 o Board(Othello)
Board class constructor.

Method Index

 o _flip(int, int, int, int)
Flips the discs intersecting the placed disc in one direction.
 o _paint(Graphics)
Draws the board.
 o _squarePos(int)
Returns the position on the board in pixels for the given row or column.
 o clear()
Sets the data structures back to their initial state.
 o getMinimumSize()
Calculates the size of the board.
 o init()
Creates the needed fonts, loads the disc images and initializes the data structures.
 o paint(Graphics)
Draws the board.
 o placeDisc(int, int, boolean)
Makes one move.
 o update(Graphics)
Draws the board.

Variables

 o _board
 protected int _board[][]
A 2x2 array of disc types (EMPTY,WHITE,BLACK).

 o _last_r
 protected int _last_r
Used to determine where to draw the last move indicator.

 o _last_c
 protected int _last_c
Used to determine where to draw the last move indicator.

Constructors

 o Board
 public Board(Othello app)
Board class constructor.

Parameters:
app - the othello applet class which is used to load the board's images

Methods

 o _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
 o _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
 o _paint
 protected void _paint(Graphics g)
Draws the board.

Parameters:
g - the graphics context
 o getMinimumSize
 public Dimension getMinimumSize()
Calculates the size of the board.

Returns:
the minimum size of the board
Overrides:
getMinimumSize in class Container
 o 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.

 o paint
 public void paint(Graphics g)
Draws the board.

Parameters:
g - the graphics context
Overrides:
paint in class Container
 o update
 public void update(Graphics g)
Draws the board.

Parameters:
g - the graphics context
Overrides:
update in class Container
 o clear
 public void clear()
Sets the data structures back to their initial state.

 o 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