OOP - Four in a row

Four in a Row is a game in which players take turns adding tokens to one of the columns on the game board. Tokens fall to the lowest position in the chosen column that does not already have a token in it. Once one of the players has placed four of their tokens in a straight line (either vertically, horizontally or diagonally), they win the game. If the board is full and no player has won, then the game ends in a draw.

Using the following UML class diagram and class descriptions to help you, create a version of Four in a Row. The game must allow for a minimum of two and a maximum of four players, allow each player to enter their name (duplicate names should not be accepted) and give the players the ability to choose how many rows (between four and 10), and how many columns (between four and 10) the game board should have. You may use the Four in a Row skeleton code to help you.

Player

Attribute/Method

Description

playerName

Specifies this player’s name.

playerNumber

Specifies the number of this player’s token.

Player()

Creates a new Player object.

getName()

Accessor for playerName.

getNumber()

Accessor for playerNumber.

makeMove()

Asks the player to pick a column to place their token in until a valid non-full column is given, and adds their token to the given column.

checkWinner()

Returns the player’s name if they have won, or "Nobody" if they haven’t.

Board

Attribute/Method

Description

columns

Specifies the number of columns on the game board.

rows

Specifies the number of rows on the game board.

board

Keeps track of which player’s token (if any) is stored at each location on the game board.

Board()

Creates a new Board object.

display()

Displays the current state of the board.

columnFull()

Checks whether a given column is full.

boardFull()

Checks whether the entire board is full.

getWidth()

Accessor for columns.

addToken()

Adds a given token to a given column.

checkWinner()

Checks the board for a winner, returning the winner’s playerNumber or 0 if there is no winner.

checkVertical()

Checks for vertical lines of four matching tokens, returning the playerNumber of the player who made the line, or 0 if there are no vertical lines of four.

checkHorizontal()

Checks for horizontal lines of four matching tokens, returning the playerNumber of the player who made the line, or 0 if there are no horizontal lines of four.

checkRightDiagonal()

Checks for left-to-right diagonal lines of four matching tokens, returning the playerNumber of the player who made the line, or 0 if there are no high-left to low-right diagonal lines of four.

checkLeftDiagonal()

Checks for right-to-left diagonal lines of four matching tokens, returning the playerNumber of the player who made the line, or 0 if there are no high-right to low-left lines of four.