O'Reilly logo

Test-Driven Java Development - Second Edition by Viktor Farcic, Alex Garcia

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Requirement 8 – win condition (IV)

The last requirement is the last win condition. It is pretty similar to the last two; in this case, in a diagonal direction.

If a player inserts a disc and connects more than three discs of his color in a straight diagonal line, then that player wins.

This is a possible implementation for this last requirement. The code is very similar to the other win conditions because the same statement must be fulfilled:

... private void checkWinCondition(int col, int row) { ... // Diagonal checks int startOffset = Math.min(col, row); int column = col - startOffset, auxRow = row - startOffset; stringJoiner = new StringJoiner(""); do { stringJoiner.add(board[column++][auxRow++].toString()); } while (column < COLUMNS && ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required