Package cs251.lab2
Interface GomokuInterface
public interface GomokuInterface
This is the interface that describes the methods that must be
present in the class you are writing that interfaces with the
GUI. The game of Gomoku is very similar to tic-tac-toe, only that
you are playing on a larger board, and the goal is to get
five-in-a-row. You are allowed to place your marker anywhere
there's an empty square on the board.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enum
Type to represent the status of each square on the board.static enum
Type to report correct outcome status of the game. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Default number of horizontal squares on the boardstatic final int
Default number of vertical squares on the boardstatic final int
Default squares in a line required for a win -
Method Summary
Modifier and TypeMethodDescriptionGet a string representation of the board.Get which player's turn it is.int
Get the number of columns for the game board.int
Get the number in a line needed for a win.int
Get the number of rows for the game board.handleClickAt
(int row, int col) Attempt a move at a given location on the board.void
initComputerPlayer
(String opponent) Configure whether a computer player will be used.void
Initialize state for a new game.
-
Field Details
-
DEFAULT_NUM_COLS
static final int DEFAULT_NUM_COLSDefault number of horizontal squares on the board- See Also:
-
DEFAULT_NUM_ROWS
static final int DEFAULT_NUM_ROWSDefault number of vertical squares on the board- See Also:
-
SQUARES_IN_LINE_FOR_WIN
static final int SQUARES_IN_LINE_FOR_WINDefault squares in a line required for a win- See Also:
-
-
Method Details
-
getNumCols
int getNumCols()Get the number of columns for the game board. (If you aren't playing around with the board size, just return DEFAULT_NUM_COLS.)- Returns:
- Number of horizontal squares on the board
-
getNumRows
int getNumRows()Get the number of rows for the game board. (If you aren't playing around with the board size, just return DEFAULT_NUM_ROWS.)- Returns:
- Number of vertical squares on the board
-
getNumInLineForWin
int getNumInLineForWin()Get the number in a line needed for a win. (If you aren't playing around with the game rules, just return SQUARES_IN_LINE_FOR_WIN.)- Returns:
- Number of squares in a line required for a win
-
handleClickAt
Attempt a move at a given location on the board. This method is called when the user clicks in the board. If the square is already occupied, nothing about the state of the game changes. If however, an empty square is clicked, then it should be filled with a value representing the player currently in turn. On a failure, the turn doesn't change, but that player gets to go again. Called from the GUI.- Parameters:
row
- 0-based row that was clickedcol
- 0-based column that was clicked- Returns:
- State of this game after this move occurred
-
initializeGame
void initializeGame()Initialize state for a new game. Starts a new game, resets the game board to empty. Pick a random player to go first the first time. In games after that, you should make it so that the player who won the last game gets to go first in the next round. This method is called by the GUI whenever a new game is supposed to be started, including before the first game when the program begins. -
getCurrentBoardAsString
String getCurrentBoardAsString()Get a string representation of the board. The characters are given by the Square.toChar method, so a hyphen in the string is an empty square, an uppercase 'O' represents the ring, and uppercase 'X' is the cross. Each line in the board is separated by a new line character '\n'. An example of a small board might look like this if viewed in a text file:OX--X XOXOO XXOOX OOXOX XOXOO
In this case, O must have started, and just won the game through a diagonal.- Returns:
- String representation of the board
-
getCurrentTurn
GomokuInterface.Square getCurrentTurn()Get which player's turn it is. As long as the game as still going, will toggle between RING and CROSS after each successful move. Current turn does not change after the last move of the game.- Returns:
- RING or CROSS, depending on current player.
-
initComputerPlayer
Configure whether a computer player will be used. At the very least, recognize the following options- NONE - no computer player (the default)
- COMPUTER - one of the players is the computer
- Parameters:
opponent
- String for computer player type.
-