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?
build steamboat build steamboat
build fireplace build fireplace
build fireplace
build axe
build axe build axe
list-buildings list-buildings
build steamboat build steamboat

View File

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

View File

@ -124,6 +124,8 @@ public class CardGame {
throw new InvalidInputException("can not build item"); throw new InvalidInputException("can not build item");
} else if (item.requiresFireplace() && !items.contains(FIREPLACE)) { } else if (item.requiresFireplace() && !items.contains(FIREPLACE)) {
throw new InvalidInputException("need fireplace to build"); throw new InvalidInputException("need fireplace to build");
} else if (items.contains(item) && !item.canBeBuiltMultipleTimes()) {
throw new InvalidInputException("already built");
} else if (canBuild(item)) { } else if (canBuild(item)) {
// remove used resources // remove used resources
for (Card resource : item.resourcesNeeded()) { for (Card resource : item.resourcesNeeded()) {

View File

@ -41,6 +41,10 @@ public enum Item {
return this.equals(STEAMBOAT) || this.equals(BALLOON); return this.equals(STEAMBOAT) || this.equals(BALLOON);
} }
public boolean canBeBuiltMultipleTimes() {
return this.equals(AXE) || this.equals(CLUB);
}
public static Item parse(String input) { public static Item parse(String input) {
switch (input) { switch (input) {
case "axe": case "axe":