Print lose if no moves available

This commit is contained in:
Arne Keller 2020-03-03 18:42:38 +01:00
parent f94ddddc9b
commit e13ee8430f
2 changed files with 8 additions and 7 deletions

View File

@ -78,4 +78,5 @@ survived
tiger
survived
thunderstorm
lose
Error, can not get resources: game not started

View File

@ -77,7 +77,7 @@ public class CardGame {
items.remove(FIREPLACE);
}
if (currentCardStack.isEmpty() && getBuildableItems().isEmpty()) {
currentCardStack = null; // game over
endGame(); // TODO: somehow print "lose" ??? (after the card!) [awaiting ILIAS..]
}
return card;
}
@ -105,7 +105,7 @@ public class CardGame {
// remove item used to escape
items.remove(items.size() - 1);
if (roll >= minimumNeeded) {
win();
endGame();
return "win";
} else {
return "lose";
@ -135,16 +135,16 @@ public class CardGame {
items.add(item);
if (item.equals(STEAMBOAT) || item.equals(BALLOON)) {
// player won
win();
endGame();
return "win";
} else if (item.equals(SAILING_RAFT) || item.equals(HANG_GLIDER)) {
// need at least a 4/d6
fightingAnimal = false;
awaitedDiceSize = 6;
minimumDiceRoll = 4;
}
if (currentCardStack != null && currentCardStack.isEmpty() && getBuildableItems().isEmpty()) {
currentCardStack = null; // game over
} else if (currentCardStack != null && currentCardStack.isEmpty() && getBuildableItems().isEmpty()) {
endGame();
return "lose";
}
return "OK";
} else {
@ -198,7 +198,7 @@ public class CardGame {
return Arrays.stream(Item.values()).filter(this::canBuild).collect(Collectors.toSet());
}
private void win() {
private void endGame() {
currentCardStack = null;
}