Only print buildable items if they can be built in addition to existing

This commit is contained in:
Arne Keller 2020-03-03 18:21:36 +01:00
parent 58f30fbf39
commit 6c8f172d3f
4 changed files with 13 additions and 2 deletions

View File

@ -115,6 +115,7 @@ build?
build axe
build club
build fireplace
build?
build shack
build sailingraft
rollD6 1

View File

@ -56,6 +56,13 @@ shack
OK
OK
OK
axe
ballon
club
hangglider
sailingraft
shack
steamboat
OK
OK
lose

View File

@ -124,7 +124,7 @@ 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()) {
} else if (items.contains(item) && !item.canHaveMoreThanOne()) {
throw new InvalidInputException("already built");
} else if (canBuild(item)) {
// remove used resources
@ -154,6 +154,9 @@ public class CardGame {
if (item.requiresFireplace() && !items.contains(FIREPLACE)) {
return false;
}
if (!item.canHaveMoreThanOne() && items.contains(item)) {
return false;
}
final Card[] resourcesNeeded = item.resourcesNeeded();
for (final Card resource : resources) {
for (int j = 0; j < resourcesNeeded.length; j++) {

View File

@ -41,7 +41,7 @@ public enum Item {
return this.equals(STEAMBOAT) || this.equals(BALLOON);
}
public boolean canBeBuiltMultipleTimes() {
public boolean canHaveMoreThanOne() {
return this.equals(AXE) || this.equals(CLUB);
}