From 9d1fbc2ffe46eca9b5d4089040af9ccf010a59de Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Wed, 11 Mar 2020 11:04:07 +0100 Subject: [PATCH] Only allow build? when not expecting dice roll --- src/edu/kit/informatik/model/CardGame.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/edu/kit/informatik/model/CardGame.java b/src/edu/kit/informatik/model/CardGame.java index f9be260..15b4bf7 100644 --- a/src/edu/kit/informatik/model/CardGame.java +++ b/src/edu/kit/informatik/model/CardGame.java @@ -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 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()); }