1.    Gameboard

Gameboard is an extension of the Java.swing JPanel class.  Gameboard

·        "holds" all the other control and game playing objects,

·        manages game board initiation,

·        tracks and prompts player turns,

·        checks for wins and displays a win message if a win is detected,

·        checks for valid moves and displays an error message if necessary, and

·        tracks the scores.

1.1.              Attributes

The player scores are displayed as JLabels with the player scores appended to them.  Both scores are always displayed.

JLabel

pOneScoreLabel

"Player 1 Score"

JLabel

pTwoScoreLabel

"Player 2 Score"

int

pOneScore

value of player one's score

int

pTwoScore

value of player two's score

 

The player turn prompts are displayed as a JLabel. 

JLabel

statusLabel

Holds and displays turn status.

 

The colors that correspond to the each player are held by the GameBoard.

Color

pOneColor

blue

Color

pTwoColor

cyan

 

Instructions for using the reset button are always displayed.

JTextBox

 

Reset Information

 

The game control buttons are constructed and placed by the GameBoard.

JButton

Restart

calls the RestartListener to reset the gameboard to its initial state.

JButton

Help

calls the HelpListener to display the help file in a separate, moveable window.

 

The individual lines and squares that make up the playing board are held in containers by the Gameboard.

Vector

lineVector

Holds all the lines in the game

Vector

squareVector

Holds all the squares that the lines are boundaries to. 

 

The game is over when all the squares belong to one player or another - that is, the score totals to 49. 

int

gameTotal

49

1.2.              Methods

boardSetup() - Used during game initiation, calls lineSetup and squareSetup.

lineSetup() - constructs, places and sets initial color (gray) for the line segments.

squareSetup() - constructs, places and sets initial color (gray) for the internal squares.

changePlayer() - toggles the player from one to two and two to one. 

promptPlayer() - displays message to indicate current player

incrementScore() - add one to score of current player.

checkGameWin() - check to see if scores total to gameTotal (49).

displayGameWin() - after a win is detected, displays a message identifying the winner

promptPlayer() - displays a message identifying the player whose turn it is

setPlayer() - sets the player whose turn it currently is.

zeroScores() - sets both player scores to zero

2.    HelpListener

Detects button push on Help button and creates a scrollable window and displays the help file in it

3.    RestartListener

The RestartListener class is implements the java.swing.ActionListener class.  RestartListener detects a button push on the Restart button and

·        resets all the lines and squares in the gameboard line and square vectors,

·        sets both scores to zero and displays them,

·        sets the current player to Player 1 and

·        displays a prompt for Player 1 to make a move.

4.    Line

The lines are the objects selected by players to make boxes.  All the lines used during play of the game are constructed at game initiation.  The size and location of the line buttons are passed to the line constructor by the gameboard lineSetup method.   The line class is an extension of the java.swing.JButton class.  

4.1.              Attributes

The JButton is extended by the addition of the following attributes

int

color

The color of the line:  gray for unused, blue for player 1 and cyan for player 2.

boolean

used

true = assigned, false = unassigned.

4.2.              Methods

identifyLine() - determines what line segment the player selected.

verifyUnusedLine() - verifies that the line segment had not been previously selected

markOwner() - change the color of the verified line segment to the color corresponding to the player who selected it.

5.    Square

Square objects sit within the borders defined by the line segments.  All the squares used during play of the game are constructed at game initiation.  The location of the square buttons are passed to the square constructor by the gameboard squareSetup method.   The square class is an extension of the java.swing.JButton class.  

5.1.              Attributes

boolean

top

true = top border line selected,

false = top border line unselected.

boolean

bottom

true = bottom border line selected,

false = bottom border line unselected.

boolean

right

true = right border line selected,

false = right border line unselected.

boolean

left

true = left border line selected,

false = left border line unselected.

5.2.              Methods

 

setSquareBorder() - sets the state of the top, bottom, left, right variables; depending on the line segment that was selected.

pointScored() - if the values of a square top, bottom, left, right variables are all true, and the square has not been previously scored, reports that a new point was scored.

colorSquare() - if the values of the top, bottom, left, right variables are all true, and the square has not been previously scored, colors the square to the color corresponding to the player.

6.    BoardListener

Detects button push on a line button and initiates actions to

·        verify that the line selected was previously unselected,

·        mark the line with the color of the .player who selected it,

·        update the "border status" of the squares that have the selected line for a border,

·        determine if the selection of the line caused a point to be scored, and

·        set the player whose turn it is.