Private invalid guess constant

This commit is contained in:
Charles Gould 2017-10-15 15:18:38 -04:00
parent e667be1bab
commit 547b10a440
3 changed files with 11 additions and 7 deletions

View File

@ -303,7 +303,7 @@ public class MultiplayerPresenter implements FxmlController {
final int[] result = report.getResult();
log.info("My result: " + Arrays.toString(result));
Platform.runLater(() -> {
if (Arrays.equals(result, Game.INVALID_GUESS)) {
if (Game.isInvalid(result)) {
playerBoard.addGuess("-----");
} else {
for (int i = 0; i < Game.WORD_LENGTH; i++) {

View File

@ -128,7 +128,7 @@ public class SinglePlayerPresenter {
final int[] result = report.getResult();
log.info("My result: " + Arrays.toString(result));
Platform.runLater(() -> {
if (Arrays.equals(result, Game.INVALID_GUESS)) {
if (Game.isInvalid(result)) {
gameBoard.addGuess("-----");
} else {
for (int i = 0; i < Game.WORD_LENGTH; i++) {

View File

@ -1,5 +1,6 @@
package lingo.common;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@ -12,6 +13,9 @@ public class Game {
public static final int CORRECT_CHARACTER = 2;
public static final int WORD_LENGTH = 5;
/** Nein nein nein nein nein! */
private static final int[] INVALID_GUESS = new int[] { 9, 9, 9, 9, 9 };
private static final AtomicInteger idCounter = new AtomicInteger(0);
public final int id;
@ -42,10 +46,6 @@ public class Game {
return -1;
}
private static int[] invalidGuess() {
return new int[] { 9, 9, 9, 9, 9 };
}
public static boolean isCorrect(int[] result) {
for (int i = 0; i < WORD_LENGTH; i++) {
if (result[i] != CORRECT_CHARACTER) {
@ -55,9 +55,13 @@ public class Game {
return true;
}
public static boolean isInvalid(int[] result) {
return Arrays.equals(result, INVALID_GUESS);
}
public int[] evaluate(String guess) {
if (!acceptableGuesses.contains(guess)) {
return invalidGuess();
return INVALID_GUESS;
}
// the guess is acceptable