From e13ee8430f18576eb593e63a87e217ffc5eb83b4 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Tue, 3 Mar 2020 18:42:38 +0100 Subject: [PATCH] Print lose if no moves available --- game_over_no_actions_output.txt | 1 + src/edu/kit/informatik/model/CardGame.java | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/game_over_no_actions_output.txt b/game_over_no_actions_output.txt index 299a1c8..ac1d711 100644 --- a/game_over_no_actions_output.txt +++ b/game_over_no_actions_output.txt @@ -78,4 +78,5 @@ survived tiger survived thunderstorm +lose Error, can not get resources: game not started diff --git a/src/edu/kit/informatik/model/CardGame.java b/src/edu/kit/informatik/model/CardGame.java index 7de1abc..c195800 100644 --- a/src/edu/kit/informatik/model/CardGame.java +++ b/src/edu/kit/informatik/model/CardGame.java @@ -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; }