Requirement 3 – player shifts

More game logic is introduced with this requirement.

It is a two-person game, so there is one colour for each player. One player uses red (R) and the other one uses green (G). Players alternate turns, inserting one disc every time.

We need to save the current player to determine which player is playing this turn. We also need a function to switch the players to recreate the logic of turns. Some lines of code become relevant in the putDisc function. Specifically, the board position assignment is made using the current player, and it is switched after every move, as the game rules say:

... private Color currentPlayer = Color.RED; private void switchPlayer() { if (Color.RED == currentPlayer) { currentPlayer = Color.GREEN; ...

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.