Row

Now, we have a Color class and even instances when we need a ColorManager. This is the time to store Color objects in Row objects. The Row class is a bit longer, but not too complex. We look at the code in small fragments in this section with explanations in-between:

package packt.java189fundamentals.example.mastermind;

public class Row {
    final Color[] positions;
    protected int matchedPositions;
    protected 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 are not in the same position in the hidden row:

public static final Row none ...

Get Java Projects - 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.