Row

Now, we have Colors and even instances if we need having a ColorManager. This is the time to store Colors in Rows. The Row class is a bit longer, but not too complex.

package packt.java9.by.example.mastermind;    import java.util.Arrays;    public class Row {      final Color[] positions;      private int matchedPositions;      private int matchedColors;

A Row contains three fields. One is the positions array. Each element of the array is a Color. The matchedPositions is the number of positions that are matched and matchedColors is the number of colors that match a color in the hidden row but is not on the position as in the hidden row.

    public static final Row none = new Row(Guesser.none);

The none is a constant that contains a special Row instance ...

Get Java 9 Programming By Example 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.