mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final2.git
synced 2024-11-08 18:00:37 +00:00
Allow tools to be built multiple times and buildings only once
This commit is contained in:
parent
1a93c5d061
commit
554a3a062e
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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()) {
|
||||||
|
@ -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":
|
||||||
|
Loading…
Reference in New Issue
Block a user