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
axe axe
fireplace fireplace
OK win

View File

@ -74,7 +74,7 @@ shack
fireplace fireplace
club club
axe axe
OK win
Error, can not get buildings: game not started Error, can not get buildings: game not started
Error, can not get resources: game not started Error, can not get resources: game not started
Error, can not get buildable items: 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) { if (item == null) {
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)) {
@ -136,6 +136,7 @@ public class CardGame {
if (item.equals(STEAMBOAT) || item.equals(BALLOON)) { if (item.equals(STEAMBOAT) || item.equals(BALLOON)) {
// player won // player won
win(); win();
return "win";
} else if (item.equals(SAILING_RAFT) || item.equals(HANG_GLIDER)) { } else if (item.equals(SAILING_RAFT) || item.equals(HANG_GLIDER)) {
// need at least a 4/d6 // need at least a 4/d6
fightingAnimal = false; fightingAnimal = false;
@ -145,9 +146,9 @@ public class CardGame {
if (currentCardStack != null && currentCardStack.isEmpty() && getBuildableItems().isEmpty()) { if (currentCardStack != null && currentCardStack.isEmpty() && getBuildableItems().isEmpty()) {
currentCardStack = null; // game over currentCardStack = null; // game over
} }
return true; return "OK";
} else { } else {
return false; return null;
} }
} }

View File

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