diff --git a/game1_input.txt b/game1_input.txt index b712047..191847f 100644 --- a/game1_input.txt +++ b/game1_input.txt @@ -117,6 +117,8 @@ list-resources build? build steamboat build fireplace +build fireplace +build axe build axe list-buildings build steamboat diff --git a/game1_output.txt b/game1_output.txt index b55ec75..82961c8 100644 --- a/game1_output.txt +++ b/game1_output.txt @@ -107,7 +107,10 @@ shack steamboat Error, need fireplace to build OK +Error, already built OK +OK +axe axe fireplace OK diff --git a/src/edu/kit/informatik/model/CardGame.java b/src/edu/kit/informatik/model/CardGame.java index b584cb5..6892485 100644 --- a/src/edu/kit/informatik/model/CardGame.java +++ b/src/edu/kit/informatik/model/CardGame.java @@ -124,6 +124,8 @@ public class CardGame { throw new InvalidInputException("can not build item"); } else if (item.requiresFireplace() && !items.contains(FIREPLACE)) { throw new InvalidInputException("need fireplace to build"); + } else if (items.contains(item) && !item.canBeBuiltMultipleTimes()) { + throw new InvalidInputException("already built"); } else if (canBuild(item)) { // remove used resources for (Card resource : item.resourcesNeeded()) { diff --git a/src/edu/kit/informatik/model/Item.java b/src/edu/kit/informatik/model/Item.java index 336b17f..0351653 100644 --- a/src/edu/kit/informatik/model/Item.java +++ b/src/edu/kit/informatik/model/Item.java @@ -41,6 +41,10 @@ public enum Item { return this.equals(STEAMBOAT) || this.equals(BALLOON); } + public boolean canBeBuiltMultipleTimes() { + return this.equals(AXE) || this.equals(CLUB); + } + public static Item parse(String input) { switch (input) { case "axe":