The Game class
An instance of the Game
class contains a Row
holding the secret color values and also contains a Table
. When there is a new guess the Game
instance stores the guess into the Table
and also sets the number of positions and colors matching the secret row.
package packt.java9.by.example.mastermind; Â public class Game { Â Â Â Â final Table table; Â Â Â final private Row secretRow; Â Â Â boolean finished = false; Â Â Â Â public Game(Table table, Color[] secret ) { Â Â Â Â Â Â Â this.table = table; Â Â Â Â Â Â Â this.secretRow = new Row(secret); Â Â Â } Â Â Â Â public void addNewGuess(Row row) { Â Â Â Â Â Â Â if( isFinished()){ Â Â Â Â Â Â Â Â Â Â Â throw new IllegalArgumentException( Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "You can not guess on a finished game."); Â Â Â Â Â Â Â } Â Â Â Â Â Â Â final int positionMatch = secretRow. Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â nrMatchingPositions(row.positions); Â Â Â Â Â Â Â final int colorMatch = secretRow. Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â nrMatchingColors(row.positions); Â Â Â Â Â Â Â row.setMatch...