Class Board


Graphical User Interface for a Board used in the teaching of UW's 100 level CS courses



             

Constructor Summary
Board(int cols)
          The constructor to build a one-dimensional board: One row and N columns.
Board(int rows, int cols)
          The constructor to build a two-dimensional board.
 
Method Summary
 void displayMessage(String theMessage)
          Sets the message to be displayed under the board.
 void drawLine(int row1, int col1, int row2, int col2)
          Draws a line on the board using the given co-ordinates as endpoints
 Coordinate getClick()
          Accepts input from the user.
 int getColumns()
           Returns the number of columns of the board.
 int getPosition()
          Like getClick(), but for one-dimensional boards.
 int getRows()
           Returns the number of rows of the board.
 void putPeg(String theColour, int col)
          Places a coloured gamepiece in the designated square on the board (used in one-dimensional boards).
 void putPeg(String theColour, int row, int col)
          Places a coloured gamepiece in the designated square on the board.
 void removeLine(int row1, int col1, int row2, int col2)
          Removes a line, if one exists, using the given co-ordinates as endpoints
 void removePeg(int col)
          Removes any gamepiece on the designated square, if one exists.
 void removePeg(int row, int col)
          Removes any gamepiece on the designated square, if one exists.

Constructor Detail

Board

public Board(int cols)
The constructor to build a one-dimensional board: One row and N columns.

Parameters:
cols - The number of columns on the board

Board

public Board(int rows,
             int cols)
The constructor to build a two-dimensional board.

Parameters:
rows - The number of rows on the board
cols - The number of columns on the board

Method Detail

displayMessage

public void displayMessage(String theMessage)
Sets the message to be displayed under the board. This message is printed below the board and can be updated.

Parameters:
theMessage - The text message to be displayed below the board.

putPeg

public void putPeg(String theColour,
                   int row,
                   int col)
Places a coloured gamepiece in the designated square on the board.

Parameters:
theColour - The colour of the gamepiece. Possible values are "yellow", "blue", "cyan", "green", "pink", "black", "white", "red" and "orange"
row - The row on which to place the the gamepiece
col - The column on which to place the gamepiece

putPeg

public void putPeg(String theColour,
                   int col)
Places a coloured gamepiece in the designated square on the board (used in one-dimensional boards). This gamepiece replaces any gamepiece already on that square.

Parameters:
theColour - The colour of the gamepiece. Possible values are "yellow", "blue", "cyan", "green", "pink", "black", "white", "red" and "orange"
col - The column on which to place the gamepiece

removePeg

public void removePeg(int row,
                      int col)
Removes any gamepiece on the designated square, if one exists.

Parameters:
row - The row of the gamepiece to remove
col - The column of the gamepiece to remove

removePeg

public void removePeg(int col)
Removes any gamepiece on the designated square, if one exists.

Parameters:
col - The column of the gamepiece to remove

drawLine

public void drawLine(int row1,
                     int col1,
                     int row2,
                     int col2)
Draws a line on the board using the given co-ordinates as endpoints

Parameters:
row1 - The row of the starting square of the line
col1 - The column of the starting square of the line
row2 - The row of the terminating square of the line
col2 - The column of the terminating square of the line

removeLine

public void removeLine(int row1,
                       int col1,
                       int row2,
                       int col2)
Removes a line, if one exists, using the given co-ordinates as endpoints.

Parameters:
row1 - The row of the starting square of the line
col1 - The column of the starting square of the line
row2 - The row of the terminating square of the line
col2 - The column of the terminating square of the line

getClick

public Coordinate getClick()
Accepts input from the user. When called, this method waits for user to click somewhere on the board and then returns the location of the click.

Returns:
A Coordinate object with the row and column of the square clicked.

getPosition

public int getPosition()
Like getClick(), but for one-dimensional boards. Accepts input from the user. When called, this method waits for user to click somewhere on the board and then returns the location of the click.

Returns:
The column of the square clicked.

getColumns

public int getColumns()
Returns the number of columns of the board

Returns:
The number of columns of the board.

getRows

public int getRows()
Returns the number of rows of the board

Returns:
The number of rows of the board.