Only output win when winning

This commit is contained in:
Arne Keller 2020-03-03 18:34:48 +01:00
parent 72c9922c44
commit f94ddddc9b
4 changed files with 10 additions and 8 deletions

View File

@ -111,4 +111,4 @@ OK
axe
axe
fireplace
OK
win

View File

@ -74,7 +74,7 @@ shack
fireplace
club
axe
OK
win
Error, can not get buildings: game not started
Error, can not get resources: game not started
Error, can not get buildable items: game not started

View File

@ -120,7 +120,7 @@ public class CardGame {
}
}
public boolean build(Item item) throws InvalidInputException {
public String build(Item item) throws InvalidInputException {
if (item == null) {
throw new InvalidInputException("can not build item");
} else if (item.requiresFireplace() && !items.contains(FIREPLACE)) {
@ -136,6 +136,7 @@ public class CardGame {
if (item.equals(STEAMBOAT) || item.equals(BALLOON)) {
// player won
win();
return "win";
} else if (item.equals(SAILING_RAFT) || item.equals(HANG_GLIDER)) {
// need at least a 4/d6
fightingAnimal = false;
@ -145,9 +146,9 @@ public class CardGame {
if (currentCardStack != null && currentCardStack.isEmpty() && getBuildableItems().isEmpty()) {
currentCardStack = null; // game over
}
return true;
return "OK";
} else {
return false;
return null;
}
}

View File

@ -21,10 +21,11 @@ public final class Build extends Command {
@Override
public void apply(CardGame game) throws InvalidInputException {
if (game.build(item)) {
Terminal.printLine("OK");
} else {
final String result = game.build(item);
if (result == null) {
Terminal.printError("could not build item");
} else {
Terminal.printLine(result);
}
}