mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final2.git
synced 2024-11-24 01:15:03 +00:00
Only output win when winning
This commit is contained in:
parent
72c9922c44
commit
f94ddddc9b
@ -111,4 +111,4 @@ OK
|
||||
axe
|
||||
axe
|
||||
fireplace
|
||||
OK
|
||||
win
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user