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 1 – the game's board

Let us start with the first requirement.

The board is composed of seven horizontal and six vertical empty positions.

The implementation of this requirement is pretty straightforward. We just need the representation of an empty position and the data structure to hold the game. Note that the colors used by the players are also defined:

public class Connect4 {
  public enum Color {
    RED('R'), GREEN('G'), EMPTY(' ');
     private final char value;
     Color(char value) { this.value = value; }
 @Override public String toString() { return String.valueOf(value); } } public static final int COLUMNS = 7; public static final int ROWS = 6; private Color[][] board = new Color[COLUMNS][ROWS]; public Connect4() { for (Color[] column ...

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