mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final2.git
synced 2024-11-23 17:04:59 +00:00
Handle item requirements when building better
This commit is contained in:
parent
ed5170ebfc
commit
172e085d28
@ -103,7 +103,7 @@ fireplace
|
||||
hangglider
|
||||
sailingraft
|
||||
shack
|
||||
Error, need fireplace to build
|
||||
Error, could not build item
|
||||
OK
|
||||
Error, already built
|
||||
OK
|
||||
|
@ -111,8 +111,6 @@ public class CardGame {
|
||||
throw new LogicException("can not build item");
|
||||
} else if (awaitingDiceRoll()) {
|
||||
throw new LogicException("awaiting dice roll, can not build");
|
||||
} else if (item.requiresFireplace() && !items.contains(FIREPLACE)) {
|
||||
throw new LogicException("need fireplace to build");
|
||||
} else if (items.contains(item)) {
|
||||
throw new LogicException("already built");
|
||||
} else if (canBuild(item)) {
|
||||
@ -141,7 +139,7 @@ public class CardGame {
|
||||
}
|
||||
|
||||
private boolean canBuild(Item item) {
|
||||
if (item.requiresFireplace() && !items.contains(FIREPLACE)) {
|
||||
if (!items.containsAll(item.itemsNeededToBuild())) {
|
||||
return false;
|
||||
}
|
||||
if (items.contains(item)) {
|
||||
|
@ -1,5 +1,10 @@
|
||||
package edu.kit.informatik.cardgame.model;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static edu.kit.informatik.cardgame.model.Card.METAL;
|
||||
import static edu.kit.informatik.cardgame.model.Card.PLASTIC;
|
||||
import static edu.kit.informatik.cardgame.model.Card.WOOD;
|
||||
@ -32,13 +37,19 @@ public enum Item {
|
||||
return new Card[] {METAL, METAL, METAL, METAL, METAL, METAL, PLASTIC};
|
||||
case BALLON:
|
||||
return new Card[] {WOOD, PLASTIC, PLASTIC, PLASTIC, PLASTIC, PLASTIC, PLASTIC};
|
||||
default: // we don't have any such items, but could add some eventually
|
||||
throw new IllegalArgumentException("item does not need resources");
|
||||
default:
|
||||
return new Card[0];
|
||||
}
|
||||
}
|
||||
|
||||
public boolean requiresFireplace() {
|
||||
return this.equals(STEAMBOAT) || this.equals(BALLON);
|
||||
public Collection<Item> itemsNeededToBuild() {
|
||||
switch (this) {
|
||||
case BALLON:
|
||||
case STEAMBOAT:
|
||||
return Arrays.asList(FIREPLACE);
|
||||
default:
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
||||
public int fightingBonus() {
|
||||
|
Loading…
Reference in New Issue
Block a user