model
Interface DotsModelInterface


public interface DotsModelInterface

Interface to Dots game model.

Author:
dennis

Nested Class Summary
static class DotsModelInterface.TeamColour
          The possible team colours.
 
Field Summary
static int defaultCols
          Default number of columns on board.
static int defaultRows
          Default number of rows on board.
 
Method Summary
 boolean addHorizontalSegment(int r, int c)
          Place a horizontal segment on the board.
 boolean addVerticalSegment(int r, int c)
          Place a vertical segment on the board.
 boolean canPlayContinue()
          Check if game is over.
 int getCols()
           
 DotsModelInterface.TeamColour getCurrentTurn()
          Get the player colour who's turn it is now.
 DotsModelInterface.TeamColour getHorizontalSegmentColour(int r, int c)
          Get the colour of the horizontal segment.
 int getRows()
           
 int getScore(DotsModelInterface.TeamColour t)
          Get the current score for a player.
 DotsModelInterface.TeamColour getVerticalSegmentColour(int r, int c)
          Get the colour of the vertical segment.
 void reset()
          Reset game to initial state.
 void setObserver(Observer o)
          Set the observer for this model.
 void setSize(int rows, int cols)
          Set size of the game board.
 

Field Detail

defaultRows

static final int defaultRows
Default number of rows on board.

See Also:
Constant Field Values

defaultCols

static final int defaultCols
Default number of columns on board.

See Also:
Constant Field Values
Method Detail

setSize

void setSize(int rows,
             int cols)
Set size of the game board. Note that number of horizontal segments = cols-1 and number of vertical segments = rows-1

Parameters:
rows - number of rows of dots
cols - number of columns of dots

reset

void reset()
Reset game to initial state.


setObserver

void setObserver(Observer o)
Set the observer for this model.

Parameters:
o - Observer that should be notified via o.refresh() with any change to model.

addHorizontalSegment

boolean addHorizontalSegment(int r,
                             int c)
Place a horizontal segment on the board.

Parameters:
r - row to add in (0 = top)
c - column to add to right of (0 = leftmost)
Returns:
true if segment added successfully, false otherwise

addVerticalSegment

boolean addVerticalSegment(int r,
                           int c)
Place a vertical segment on the board.

Parameters:
r - row to add below (0 = top)
c - column to add in (0 = leftmost)
Returns:
true if segment added successfully, false otherwise

getRows

int getRows()
Returns:
number of rows for game

getCols

int getCols()
Returns:
number of columns for game

getHorizontalSegmentColour

DotsModelInterface.TeamColour getHorizontalSegmentColour(int r,
                                                         int c)
Get the colour of the horizontal segment.

Parameters:
r - row containing the segment.
c - column to left of segment.
Returns:
colour of the segment or None if empty.

getVerticalSegmentColour

DotsModelInterface.TeamColour getVerticalSegmentColour(int r,
                                                       int c)
Get the colour of the vertical segment.

Parameters:
r - row above the segment.
c - column containing the segment.
Returns:
colour of the segment or None if empty.

getScore

int getScore(DotsModelInterface.TeamColour t)
Get the current score for a player.

Parameters:
t - player colour to get score for (White or BLACK)
Returns:
the score for that player

getCurrentTurn

DotsModelInterface.TeamColour getCurrentTurn()
Get the player colour who's turn it is now.

Returns:
colour of team who gets to add next segment.

canPlayContinue

boolean canPlayContinue()
Check if game is over.

Returns:
true if more segments can be added to this game, false otherwise