mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final2.git
synced 2024-11-08 09:50:38 +00:00
Only allow build? when not expecting dice roll
This commit is contained in:
parent
6f5127254d
commit
9d1fbc2ffe
@ -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());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user