Allow tools to be built multiple times and buildings only once

This commit is contained in:
Arne Keller 2020-02-29 16:27:50 +01:00
parent 1a93c5d061
commit 554a3a062e
4 changed files with 11 additions and 0 deletions

View File

@ -117,6 +117,8 @@ list-resources
build?
build steamboat
build fireplace
build fireplace
build axe
build axe
list-buildings
build steamboat

View File

@ -107,7 +107,10 @@ shack
steamboat
Error, need fireplace to build
OK
Error, already built
OK
OK
axe
axe
fireplace
OK

View File

@ -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()) {

View File

@ -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":