diff --git a/commands1_input.txt b/commands1_input.txt index 5fdb34b..3709e69 100644 --- a/commands1_input.txt +++ b/commands1_input.txt @@ -1,4 +1,5 @@ build? +draw list-buildings list-resources list-buildings I can build diff --git a/commands1_output.txt b/commands1_output.txt index de1d67f..c7cf735 100644 --- a/commands1_output.txt +++ b/commands1_output.txt @@ -1,4 +1,5 @@ EMPTY +Error, no card to draw exists EMPTY EMPTY Error, invalid list-buildings argument: none expected diff --git a/game2_input.txt b/game2_input.txt index 0ed3cff..2bab6cf 100644 --- a/game2_input.txt +++ b/game2_input.txt @@ -119,6 +119,8 @@ build shack build sailingraft rollD6 1 build hangglider +draw rollD6 3 +build anything list-buildings build ballon diff --git a/game2_output.txt b/game2_output.txt index 6987ad4..b2f0841 100644 --- a/game2_output.txt +++ b/game2_output.txt @@ -62,7 +62,9 @@ OK OK lose OK +Error, roll dice, please lose +Error, can not build item shack fireplace club diff --git a/src/edu/kit/informatik/model/CardGame.java b/src/edu/kit/informatik/model/CardGame.java index e305585..f6d2e2a 100644 --- a/src/edu/kit/informatik/model/CardGame.java +++ b/src/edu/kit/informatik/model/CardGame.java @@ -45,8 +45,7 @@ public class CardGame { public Card draw() throws InvalidInputException { if (cardStack == null || cardStack.isEmpty()) { throw new InvalidInputException("no card to draw exists"); - } - if (awaitedDiceSize != null) { + } else if (awaitedDiceSize != null) { throw new InvalidInputException("roll dice, please"); } Card card = cardStack.removeFirst(); @@ -66,22 +65,26 @@ public class CardGame { public String rollDice(int size, int roll) throws InvalidInputException { if (awaitedDiceSize == null) { throw new InvalidInputException("not expecting dice roll"); - } - if (awaitedDiceSize != size) { + } else if (awaitedDiceSize != size) { throw new InvalidInputException("unexpected dice size"); + } else if (roll > awaitedDiceSize || roll < 1) { + throw new InvalidInputException("impossible roll"); } + awaitedDiceSize = null; + int minimumNeeded = minimumDiceRoll; + minimumDiceRoll = null; if (fightingAnimal) { int bonus = items.contains(AXE) ? 2 : items.contains(CLUB) ? 1 : 0; - if (roll + bonus >= minimumDiceRoll) { + if (roll + bonus >= minimumNeeded) { return "survived"; } else { clearResources(); return "lose"; } - } else { + } else { // attempting to escape // remove item used to escape items.remove(items.size() - 1); - if (roll >= minimumDiceRoll) { + if (roll >= minimumNeeded) { return "win"; } else { return "lose"; @@ -98,12 +101,10 @@ public class CardGame { public boolean build(Item item) throws InvalidInputException { if (item == null) { - throw new InvalidInputException("can not build null item"); - } - if (item.requiresFireplace() && !items.contains(FIREPLACE)) { + throw new InvalidInputException("can not build item"); + } else if (item.requiresFireplace() && !items.contains(FIREPLACE)) { throw new InvalidInputException("need fireplace to build"); - } - if (canBuild(item)) { + } else if (canBuild(item)) { // remove used resources for (Card resource : item.resourcesNeeded()) { assert resources.removeLastOccurrence(resource); // TODO: remove assert diff --git a/src/edu/kit/informatik/model/Item.java b/src/edu/kit/informatik/model/Item.java index 7d663f4..336b17f 100644 --- a/src/edu/kit/informatik/model/Item.java +++ b/src/edu/kit/informatik/model/Item.java @@ -32,8 +32,8 @@ public enum Item { return new Card[] {METAL, METAL, METAL, METAL, METAL, METAL, PLASTIC}; case BALLOON: return new Card[] {WOOD, PLASTIC, PLASTIC, PLASTIC, PLASTIC, PLASTIC, PLASTIC}; - default: - return null; + default: // we don't have any such items, but could add some eventually + throw new IllegalArgumentException("item does not need resources"); } }