Checkstyle and tests

This commit is contained in:
Arne Keller 2020-02-28 15:39:49 +01:00
parent 98ee0975a3
commit 3bd70a5350
6 changed files with 21 additions and 14 deletions

View File

@ -1,4 +1,5 @@
build?
draw
list-buildings
list-resources
list-buildings I can build

View File

@ -1,4 +1,5 @@
EMPTY
Error, no card to draw exists
EMPTY
EMPTY
Error, invalid list-buildings argument: none expected

View File

@ -119,6 +119,8 @@ build shack
build sailingraft
rollD6 1
build hangglider
draw
rollD6 3
build anything
list-buildings
build ballon

View File

@ -62,7 +62,9 @@ OK
OK
lose
OK
Error, roll dice, please
lose
Error, can not build item
shack
fireplace
club

View File

@ -45,8 +45,7 @@ public class CardGame {
public Card draw() throws InvalidInputException {
if (cardStack == null || cardStack.isEmpty()) {
throw new InvalidInputException("no card to draw exists");
}
if (awaitedDiceSize != null) {
} else if (awaitedDiceSize != null) {
throw new InvalidInputException("roll dice, please");
}
Card card = cardStack.removeFirst();
@ -66,22 +65,26 @@ public class CardGame {
public String rollDice(int size, int roll) throws InvalidInputException {
if (awaitedDiceSize == null) {
throw new InvalidInputException("not expecting dice roll");
}
if (awaitedDiceSize != size) {
} else if (awaitedDiceSize != size) {
throw new InvalidInputException("unexpected dice size");
} else if (roll > awaitedDiceSize || roll < 1) {
throw new InvalidInputException("impossible roll");
}
awaitedDiceSize = null;
int minimumNeeded = minimumDiceRoll;
minimumDiceRoll = null;
if (fightingAnimal) {
int bonus = items.contains(AXE) ? 2 : items.contains(CLUB) ? 1 : 0;
if (roll + bonus >= minimumDiceRoll) {
if (roll + bonus >= minimumNeeded) {
return "survived";
} else {
clearResources();
return "lose";
}
} else {
} else { // attempting to escape
// remove item used to escape
items.remove(items.size() - 1);
if (roll >= minimumDiceRoll) {
if (roll >= minimumNeeded) {
return "win";
} else {
return "lose";
@ -98,12 +101,10 @@ public class CardGame {
public boolean build(Item item) throws InvalidInputException {
if (item == null) {
throw new InvalidInputException("can not build null item");
}
if (item.requiresFireplace() && !items.contains(FIREPLACE)) {
throw new InvalidInputException("can not build item");
} else if (item.requiresFireplace() && !items.contains(FIREPLACE)) {
throw new InvalidInputException("need fireplace to build");
}
if (canBuild(item)) {
} else if (canBuild(item)) {
// remove used resources
for (Card resource : item.resourcesNeeded()) {
assert resources.removeLastOccurrence(resource); // TODO: remove assert

View File

@ -32,8 +32,8 @@ public enum Item {
return new Card[] {METAL, METAL, METAL, METAL, METAL, METAL, PLASTIC};
case BALLOON:
return new Card[] {WOOD, PLASTIC, PLASTIC, PLASTIC, PLASTIC, PLASTIC, PLASTIC};
default:
return null;
default: // we don't have any such items, but could add some eventually
throw new IllegalArgumentException("item does not need resources");
}
}