From c0aa7d29e69d61d32e628dc6999d9e6adcd60fda Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Fri, 28 Feb 2020 12:14:28 +0100 Subject: [PATCH] Correctly roll dice and print result --- game2_input.txt | 124 ++++++++++++++++++ game2_output.txt | 70 ++++++++++ src/edu/kit/informatik/MainTest.java | 5 + src/edu/kit/informatik/model/CardGame.java | 7 +- .../informatik/ui/command/ListResources.java | 9 -- .../kit/informatik/ui/command/RollDice.java | 3 +- 6 files changed, 205 insertions(+), 13 deletions(-) create mode 100644 game2_input.txt create mode 100644 game2_output.txt diff --git a/game2_input.txt b/game2_input.txt new file mode 100644 index 0000000..0ed3cff --- /dev/null +++ b/game2_input.txt @@ -0,0 +1,124 @@ +startn +metal +metal +metal +metal +metal +metal +metal +metal +metal +metal +metal +metal +metal +metal +plastic +plastic +plastic +plastic +plastic +plastic +plastic +plastic +plastic +plastic +wood +wood +wood +wood +wood +wood +metal +metal +plastic +plastic +wood +wood +wood +wood +wood +wood +wood +wood +wood +wood +plastic +plastic +plastic +plastic +spider +spider +spider +spider +spider +snake +snake +snake +snake +snake +tiger +tiger +tiger +tiger +tiger +thunderstorm +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +draw +build? +build axe +build club +build fireplace +build shack +build sailingraft +rollD6 1 +build hangglider +rollD6 3 +list-buildings +build ballon diff --git a/game2_output.txt b/game2_output.txt new file mode 100644 index 0000000..6987ad4 --- /dev/null +++ b/game2_output.txt @@ -0,0 +1,70 @@ +OK +metal +metal +metal +metal +metal +metal +metal +metal +metal +metal +metal +metal +metal +metal +plastic +plastic +plastic +plastic +plastic +plastic +plastic +plastic +plastic +plastic +wood +wood +wood +wood +wood +wood +metal +metal +plastic +plastic +wood +wood +wood +wood +wood +wood +wood +wood +wood +wood +plastic +plastic +plastic +plastic +axe +ballon +club +fireplace +hangglider +sailingraft +shack +steamboat +OK +OK +OK +OK +OK +lose +OK +lose +shack +fireplace +club +axe +OK diff --git a/src/edu/kit/informatik/MainTest.java b/src/edu/kit/informatik/MainTest.java index fcec58a..592b626 100644 --- a/src/edu/kit/informatik/MainTest.java +++ b/src/edu/kit/informatik/MainTest.java @@ -13,6 +13,11 @@ class MainTest { cmpInOut("game1_input.txt", "game1_output.txt"); } + @Test + void game2() throws IOException { + cmpInOut("game2_input.txt", "game2_output.txt"); + } + @Test void commands1() throws IOException { cmpInOut("commands1_input.txt", "commands1_output.txt"); diff --git a/src/edu/kit/informatik/model/CardGame.java b/src/edu/kit/informatik/model/CardGame.java index 2997307..f3083d0 100644 --- a/src/edu/kit/informatik/model/CardGame.java +++ b/src/edu/kit/informatik/model/CardGame.java @@ -78,6 +78,8 @@ public class CardGame { return "lose"; } } else { + // remove item used to escape + items.remove(items.size() - 1); if (roll >= minimumDiceRoll) { return "win"; } else { @@ -106,11 +108,10 @@ public class CardGame { assert(resources.removeLastOccurrence(resource)); // TODO: remove assert } items.add(item); - // TODO: building to flee - if (items.equals(STEAMBOAT) || items.equals(BALLOON)) { + if (item.equals(STEAMBOAT) || item.equals(BALLOON)) { // player won reset(); - } else if (items.equals(SAILING_RAFT) || items.equals(HANG_GLIDER)) { + } else if (item.equals(SAILING_RAFT) || item.equals(HANG_GLIDER)) { // need at least a 4/d6 fightingAnimal = false; awaitedDiceSize = 6; diff --git a/src/edu/kit/informatik/ui/command/ListResources.java b/src/edu/kit/informatik/ui/command/ListResources.java index a23b471..d5d4d0e 100644 --- a/src/edu/kit/informatik/ui/command/ListResources.java +++ b/src/edu/kit/informatik/ui/command/ListResources.java @@ -29,13 +29,4 @@ public class ListResources extends Command { throw new InvalidInputException("invalid list-resources argument: none expected"); } } - - /* - Im Erfolgsfall werden alle aktuell im Besitz befindlichen Ressourcen zeilenweise ausgegeben. Die - Ausgabe ist geordnet absteigend nach dem Aufnahmezeitpunkt der Ressourcen. Folglich sind die - obersten fünf Ressourcen die, die in der Hütte gesichert werden. Besitzt der Spieler keine Ressourcen,wird - EMPTY - ausgegeben.Im Fehlerfall (z.B. bei einem fehlerhaften Eingabeformat) wird eine aussagekräftige Fehlermeldung - beginnend mitError, ausgegeben - */ } diff --git a/src/edu/kit/informatik/ui/command/RollDice.java b/src/edu/kit/informatik/ui/command/RollDice.java index 75287e0..0bcc092 100644 --- a/src/edu/kit/informatik/ui/command/RollDice.java +++ b/src/edu/kit/informatik/ui/command/RollDice.java @@ -1,5 +1,6 @@ package edu.kit.informatik.ui.command; +import edu.kit.informatik.Terminal; import edu.kit.informatik.model.CardGame; import edu.kit.informatik.ui.InvalidInputException; @@ -17,7 +18,7 @@ public class RollDice extends Command { @Override public void apply(CardGame game) throws InvalidInputException { - + Terminal.printLine(game.rollDice(size, rolledNumber)); } @Override