Requirement 2 – introducing discs

This requirement introduces part of the logic of the game.

Players introduce discs on the top of the columns. The introduced disc drops down the board if the column is empty. Future discs introduced in the same column will stack over the previous ones.

In this part, board bounds become relevant. We need to mark what positions are already taken, using Color.RED to indicate them. Finally, the first private method is created. It is a helper method that calculates the number of discs introduced in a given column:

public void putDisc(int column) { if (column > 0 && column <= COLUMNS) { int numOfDiscs = getNumberOfDiscsInColumn(column - 1); if (numOfDiscs < ROWS) { board[column - 1][numOfDiscs] = Color.RED; } ...

Get Test-Driven Java Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.