From 554a3a062e3236314b77dece77ff482491ed6933 Mon Sep 17 00:00:00 2001 From: Arne Keller Date: Sat, 29 Feb 2020 16:27:50 +0100 Subject: [PATCH] Allow tools to be built multiple times and buildings only once --- game1_input.txt | 2 ++ game1_output.txt | 3 +++ src/edu/kit/informatik/model/CardGame.java | 2 ++ src/edu/kit/informatik/model/Item.java | 4 ++++ 4 files changed, 11 insertions(+) diff --git a/game1_input.txt b/game1_input.txt index b712047..191847f 100644 --- a/game1_input.txt +++ b/game1_input.txt @@ -117,6 +117,8 @@ list-resources build? build steamboat build fireplace +build fireplace +build axe build axe list-buildings build steamboat diff --git a/game1_output.txt b/game1_output.txt index b55ec75..82961c8 100644 --- a/game1_output.txt +++ b/game1_output.txt @@ -107,7 +107,10 @@ shack steamboat Error, need fireplace to build OK +Error, already built OK +OK +axe axe fireplace OK diff --git a/src/edu/kit/informatik/model/CardGame.java b/src/edu/kit/informatik/model/CardGame.java index b584cb5..6892485 100644 --- a/src/edu/kit/informatik/model/CardGame.java +++ b/src/edu/kit/informatik/model/CardGame.java @@ -124,6 +124,8 @@ 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()) { + throw new InvalidInputException("already built"); } else if (canBuild(item)) { // remove used resources for (Card resource : item.resourcesNeeded()) { diff --git a/src/edu/kit/informatik/model/Item.java b/src/edu/kit/informatik/model/Item.java index 336b17f..0351653 100644 --- a/src/edu/kit/informatik/model/Item.java +++ b/src/edu/kit/informatik/model/Item.java @@ -41,6 +41,10 @@ public enum Item { return this.equals(STEAMBOAT) || this.equals(BALLOON); } + public boolean canBeBuiltMultipleTimes() { + return this.equals(AXE) || this.equals(CLUB); + } + public static Item parse(String input) { switch (input) { case "axe":