mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final2.git
synced 2024-11-08 18:00:37 +00:00
Checkstyle and tests
This commit is contained in:
parent
b2d3e2e6e6
commit
f274b25ae2
@ -6,3 +6,5 @@ list-resources I can buy
|
||||
reset
|
||||
reset the game
|
||||
rollD8 5
|
||||
start creating,good,task,specifications,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a,a
|
||||
start with,less,cards
|
||||
|
@ -6,3 +6,5 @@ Error, invalid list-resources argument: none expected
|
||||
OK
|
||||
Error, invalid reset argument: none expected
|
||||
Error, not expecting dice roll
|
||||
Error, invalid start argument value(s)
|
||||
Error, invalid start arguments
|
||||
|
@ -8,6 +8,7 @@ import java.util.Arrays;
|
||||
import java.util.Deque;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static edu.kit.informatik.model.Item.AXE;
|
||||
@ -105,7 +106,7 @@ public class CardGame {
|
||||
if (canBuild(item)) {
|
||||
// remove used resources
|
||||
for (Card resource : item.resourcesNeeded()) {
|
||||
assert(resources.removeLastOccurrence(resource)); // TODO: remove assert
|
||||
assert resources.removeLastOccurrence(resource); // TODO: remove assert
|
||||
}
|
||||
items.add(item);
|
||||
if (item.equals(STEAMBOAT) || item.equals(BALLOON)) {
|
||||
@ -146,8 +147,8 @@ public class CardGame {
|
||||
return new ArrayList<>(items);
|
||||
}
|
||||
|
||||
public List<Item> getBuildableItems() {
|
||||
return Arrays.stream(Item.values()).filter(this::canBuild).collect(Collectors.toList());
|
||||
public Set<Item> getBuildableItems() {
|
||||
return Arrays.stream(Item.values()).filter(this::canBuild).collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
|
@ -17,21 +17,21 @@ public enum Item {
|
||||
public Card[] resourcesNeeded() {
|
||||
switch (this) {
|
||||
case AXE:
|
||||
return new Card[] { METAL, METAL, METAL };
|
||||
return new Card[] {METAL, METAL, METAL};
|
||||
case CLUB:
|
||||
return new Card[] { WOOD, WOOD, WOOD };
|
||||
return new Card[] {WOOD, WOOD, WOOD};
|
||||
case SHACK:
|
||||
return new Card[] { WOOD, WOOD, METAL, PLASTIC, PLASTIC };
|
||||
return new Card[] {WOOD, WOOD, METAL, PLASTIC, PLASTIC};
|
||||
case FIREPLACE:
|
||||
return new Card[] { WOOD, WOOD, WOOD, METAL };
|
||||
return new Card[] {WOOD, WOOD, WOOD, METAL};
|
||||
case SAILING_RAFT:
|
||||
return new Card[] { WOOD, WOOD, WOOD, WOOD, METAL, METAL, PLASTIC, PLASTIC };
|
||||
return new Card[] {WOOD, WOOD, WOOD, WOOD, METAL, METAL, PLASTIC, PLASTIC};
|
||||
case HANG_GLIDER:
|
||||
return new Card[] { WOOD, WOOD, METAL, METAL, PLASTIC, PLASTIC, PLASTIC, PLASTIC };
|
||||
return new Card[] {WOOD, WOOD, METAL, METAL, PLASTIC, PLASTIC, PLASTIC, PLASTIC};
|
||||
case STEAMBOAT:
|
||||
return new Card[] { METAL, METAL, METAL, METAL, METAL, METAL, PLASTIC };
|
||||
return new Card[] {METAL, METAL, METAL, METAL, METAL, METAL, PLASTIC};
|
||||
case BALLOON:
|
||||
return new Card[] { WOOD, PLASTIC, PLASTIC, PLASTIC, PLASTIC, PLASTIC, PLASTIC };
|
||||
return new Card[] {WOOD, PLASTIC, PLASTIC, PLASTIC, PLASTIC, PLASTIC, PLASTIC};
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
@ -6,19 +6,18 @@ import edu.kit.informatik.model.Item;
|
||||
import edu.kit.informatik.ui.InvalidInputException;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static edu.kit.informatik.ui.command.CommandFactory.BUILDABLE;
|
||||
|
||||
public class Buildable extends Command {
|
||||
@Override
|
||||
public void apply(CardGame game) {
|
||||
List<Item> buildable = game.getBuildableItems();
|
||||
Set<Item> buildable = game.getBuildableItems();
|
||||
if (buildable.isEmpty()) {
|
||||
Terminal.printLine("EMPTY");
|
||||
} else {
|
||||
buildable.sort(Comparator.comparing(Object::toString));
|
||||
buildable.forEach(Terminal::printLine);
|
||||
buildable.stream().sorted(Comparator.comparing(Object::toString)).forEach(Terminal::printLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ import static edu.kit.informatik.ui.command.CommandFactory.LIST_BUILDINGS;
|
||||
|
||||
public class ListBuildings extends Command {
|
||||
@Override
|
||||
public void apply(CardGame game) throws InvalidInputException {
|
||||
public void apply(CardGame game) {
|
||||
List<Item> items = game.getItems();
|
||||
if (items.isEmpty()) {
|
||||
Terminal.printLine("EMPTY");
|
||||
|
@ -11,7 +11,7 @@ import static edu.kit.informatik.ui.command.CommandFactory.LIST_RESOURCES;
|
||||
|
||||
public class ListResources extends Command {
|
||||
@Override
|
||||
public void apply(CardGame game) throws InvalidInputException {
|
||||
public void apply(CardGame game) {
|
||||
Deque<Card> resources = game.getResources();
|
||||
if (resources.isEmpty()) {
|
||||
Terminal.printLine("EMPTY");
|
||||
|
@ -6,18 +6,12 @@ import edu.kit.informatik.model.CardGame;
|
||||
import edu.kit.informatik.ui.InvalidInputException;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
import java.util.Deque;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static edu.kit.informatik.ui.command.CommandFactory.CARD;
|
||||
|
||||
public class Start extends Command {
|
||||
private static final Pattern START_ARGUMENTS = Pattern.compile("start ((?:(?:" + CARD + "),){63}(?:" + CARD + "))");
|
||||
private static final Pattern START_ARGUMENTS = Pattern.compile("start ((\\w+,){63}(\\w+))");
|
||||
|
||||
private Deque<Card> cards;
|
||||
|
||||
@ -39,12 +33,13 @@ public class Start extends Command {
|
||||
if (!matcher.matches()) {
|
||||
throw new InvalidInputException("invalid start arguments");
|
||||
}
|
||||
cards = Arrays.stream(matcher.group(1).split(","))
|
||||
.map(Card::parse)
|
||||
.collect(Collectors.toCollection(ArrayDeque::new));
|
||||
if (cards.stream().anyMatch(Objects::isNull)) {
|
||||
cards = null;
|
||||
throw new InvalidInputException("invalid start argument value(s)");
|
||||
cards = new ArrayDeque<>();
|
||||
for (String s : matcher.group(1).split(",")) {
|
||||
Card card = Card.parse(s);
|
||||
if (card == null) {
|
||||
throw new InvalidInputException("invalid start argument value(s)");
|
||||
}
|
||||
cards.add(card);
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user