Only allow build? when not expecting dice roll

This commit is contained in:
Arne Keller 2020-03-11 11:04:07 +01:00
parent 6f5127254d
commit 9d1fbc2ffe

View File

@ -51,7 +51,7 @@ public class CardGame {
public Card draw() throws LogicException {
if (currentCardStack == null || currentCardStack.isEmpty()) {
throw new LogicException("no card to draw exists");
} else if (awaitedDiceSize != null) {
} else if (awaitingDiceRoll()) {
throw new LogicException("roll dice, please");
}
final Card card = currentCardStack.removeFirst();
@ -72,7 +72,7 @@ public class CardGame {
}
public String rollDice(int size, int roll) throws LogicException {
if (awaitedDiceSize == null) {
if (!awaitingDiceRoll()) {
throw new LogicException("not expecting dice roll");
} else if (awaitedDiceSize != size) {
throw new LogicException("unexpected dice size");
@ -164,6 +164,10 @@ public class CardGame {
return currentCardStack != null;
}
private boolean awaitingDiceRoll() {
return awaitedDiceSize != null;
}
public Deque<Card> getResources() throws LogicException {
if (!gameStarted()) {
throw new LogicException("can not get resources: game not started");
@ -184,6 +188,9 @@ public class CardGame {
if (!gameStarted()) {
throw new LogicException("can not get buildable items: game not started");
}
if (awaitingDiceRoll()) {
throw new LogicException("can not get buildable items: awaiting dice roll");
}
return Arrays.stream(Item.values()).filter(this::canBuild).collect(Collectors.toSet());
}