From 6c8f172d3fd81c4dd750a11596338e464b8dc994 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Tue, 3 Mar 2020 18:21:36 +0100 Subject: [PATCH] Only print buildable items if they can be built in addition to existing --- game2_input.txt | 1 + game2_output.txt | 7 +++++++ src/edu/kit/informatik/model/CardGame.java | 5 ++++- src/edu/kit/informatik/model/Item.java | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/game2_input.txt b/game2_input.txt index 2bab6cf..a53e5b8 100644 --- a/game2_input.txt +++ b/game2_input.txt @@ -115,6 +115,7 @@ build? build axe build club build fireplace +build? build shack build sailingraft rollD6 1 diff --git a/game2_output.txt b/game2_output.txt index 87efd12..2c5b59b 100644 --- a/game2_output.txt +++ b/game2_output.txt @@ -56,6 +56,13 @@ shack OK OK OK +axe +ballon +club +hangglider +sailingraft +shack +steamboat OK OK lose diff --git a/src/edu/kit/informatik/model/CardGame.java b/src/edu/kit/informatik/model/CardGame.java index 0eeb1ae..16dc033 100644 --- a/src/edu/kit/informatik/model/CardGame.java +++ b/src/edu/kit/informatik/model/CardGame.java @@ -124,7 +124,7 @@ public class CardGame { throw new InvalidInputException("can not build item"); } else if (item.requiresFireplace() && !items.contains(FIREPLACE)) { throw new InvalidInputException("need fireplace to build"); - } else if (items.contains(item) && !item.canBeBuiltMultipleTimes()) { + } else if (items.contains(item) && !item.canHaveMoreThanOne()) { throw new InvalidInputException("already built"); } else if (canBuild(item)) { // remove used resources @@ -154,6 +154,9 @@ public class CardGame { if (item.requiresFireplace() && !items.contains(FIREPLACE)) { return false; } + if (!item.canHaveMoreThanOne() && items.contains(item)) { + return false; + } final Card[] resourcesNeeded = item.resourcesNeeded(); for (final Card resource : resources) { for (int j = 0; j < resourcesNeeded.length; j++) { diff --git a/src/edu/kit/informatik/model/Item.java b/src/edu/kit/informatik/model/Item.java index 0351653..283b653 100644 --- a/src/edu/kit/informatik/model/Item.java +++ b/src/edu/kit/informatik/model/Item.java @@ -41,7 +41,7 @@ public enum Item { return this.equals(STEAMBOAT) || this.equals(BALLOON); } - public boolean canBeBuiltMultipleTimes() { + public boolean canHaveMoreThanOne() { return this.equals(AXE) || this.equals(CLUB); }