Private invalid guess constant
This commit is contained in:
parent
e667be1bab
commit
547b10a440
@ -303,7 +303,7 @@ public class MultiplayerPresenter implements FxmlController {
|
|||||||
final int[] result = report.getResult();
|
final int[] result = report.getResult();
|
||||||
log.info("My result: " + Arrays.toString(result));
|
log.info("My result: " + Arrays.toString(result));
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
if (Arrays.equals(result, Game.INVALID_GUESS)) {
|
if (Game.isInvalid(result)) {
|
||||||
playerBoard.addGuess("-----");
|
playerBoard.addGuess("-----");
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < Game.WORD_LENGTH; i++) {
|
for (int i = 0; i < Game.WORD_LENGTH; i++) {
|
||||||
|
@ -128,7 +128,7 @@ public class SinglePlayerPresenter {
|
|||||||
final int[] result = report.getResult();
|
final int[] result = report.getResult();
|
||||||
log.info("My result: " + Arrays.toString(result));
|
log.info("My result: " + Arrays.toString(result));
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
if (Arrays.equals(result, Game.INVALID_GUESS)) {
|
if (Game.isInvalid(result)) {
|
||||||
gameBoard.addGuess("-----");
|
gameBoard.addGuess("-----");
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < Game.WORD_LENGTH; i++) {
|
for (int i = 0; i < Game.WORD_LENGTH; i++) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package lingo.common;
|
package lingo.common;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -12,6 +13,9 @@ public class Game {
|
|||||||
public static final int CORRECT_CHARACTER = 2;
|
public static final int CORRECT_CHARACTER = 2;
|
||||||
public static final int WORD_LENGTH = 5;
|
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);
|
private static final AtomicInteger idCounter = new AtomicInteger(0);
|
||||||
|
|
||||||
public final int id;
|
public final int id;
|
||||||
@ -42,10 +46,6 @@ public class Game {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int[] invalidGuess() {
|
|
||||||
return new int[] { 9, 9, 9, 9, 9 };
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isCorrect(int[] result) {
|
public static boolean isCorrect(int[] result) {
|
||||||
for (int i = 0; i < WORD_LENGTH; i++) {
|
for (int i = 0; i < WORD_LENGTH; i++) {
|
||||||
if (result[i] != CORRECT_CHARACTER) {
|
if (result[i] != CORRECT_CHARACTER) {
|
||||||
@ -55,9 +55,13 @@ public class Game {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isInvalid(int[] result) {
|
||||||
|
return Arrays.equals(result, INVALID_GUESS);
|
||||||
|
}
|
||||||
|
|
||||||
public int[] evaluate(String guess) {
|
public int[] evaluate(String guess) {
|
||||||
if (!acceptableGuesses.contains(guess)) {
|
if (!acceptableGuesses.contains(guess)) {
|
||||||
return invalidGuess();
|
return INVALID_GUESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the guess is acceptable
|
// the guess is acceptable
|
||||||
|
Loading…
x
Reference in New Issue
Block a user