mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final2.git
synced 2024-11-24 09:24:57 +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
|
||||||
reset the game
|
reset the game
|
||||||
rollD8 5
|
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
|
OK
|
||||||
Error, invalid reset argument: none expected
|
Error, invalid reset argument: none expected
|
||||||
Error, not expecting dice roll
|
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.Deque;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static edu.kit.informatik.model.Item.AXE;
|
import static edu.kit.informatik.model.Item.AXE;
|
||||||
@ -105,7 +106,7 @@ public class CardGame {
|
|||||||
if (canBuild(item)) {
|
if (canBuild(item)) {
|
||||||
// remove used resources
|
// remove used resources
|
||||||
for (Card resource : item.resourcesNeeded()) {
|
for (Card resource : item.resourcesNeeded()) {
|
||||||
assert(resources.removeLastOccurrence(resource)); // TODO: remove assert
|
assert resources.removeLastOccurrence(resource); // TODO: remove assert
|
||||||
}
|
}
|
||||||
items.add(item);
|
items.add(item);
|
||||||
if (item.equals(STEAMBOAT) || item.equals(BALLOON)) {
|
if (item.equals(STEAMBOAT) || item.equals(BALLOON)) {
|
||||||
@ -146,8 +147,8 @@ public class CardGame {
|
|||||||
return new ArrayList<>(items);
|
return new ArrayList<>(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Item> getBuildableItems() {
|
public Set<Item> getBuildableItems() {
|
||||||
return Arrays.stream(Item.values()).filter(this::canBuild).collect(Collectors.toList());
|
return Arrays.stream(Item.values()).filter(this::canBuild).collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
|
@ -17,21 +17,21 @@ public enum Item {
|
|||||||
public Card[] resourcesNeeded() {
|
public Card[] resourcesNeeded() {
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case AXE:
|
case AXE:
|
||||||
return new Card[] { METAL, METAL, METAL };
|
return new Card[] {METAL, METAL, METAL};
|
||||||
case CLUB:
|
case CLUB:
|
||||||
return new Card[] { WOOD, WOOD, WOOD };
|
return new Card[] {WOOD, WOOD, WOOD};
|
||||||
case SHACK:
|
case SHACK:
|
||||||
return new Card[] { WOOD, WOOD, METAL, PLASTIC, PLASTIC };
|
return new Card[] {WOOD, WOOD, METAL, PLASTIC, PLASTIC};
|
||||||
case FIREPLACE:
|
case FIREPLACE:
|
||||||
return new Card[] { WOOD, WOOD, WOOD, METAL };
|
return new Card[] {WOOD, WOOD, WOOD, METAL};
|
||||||
case SAILING_RAFT:
|
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:
|
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:
|
case STEAMBOAT:
|
||||||
return new Card[] { METAL, METAL, METAL, METAL, METAL, METAL, PLASTIC };
|
return new Card[] {METAL, METAL, METAL, METAL, METAL, METAL, PLASTIC};
|
||||||
case BALLOON:
|
case BALLOON:
|
||||||
return new Card[] { WOOD, PLASTIC, PLASTIC, PLASTIC, PLASTIC, PLASTIC, PLASTIC };
|
return new Card[] {WOOD, PLASTIC, PLASTIC, PLASTIC, PLASTIC, PLASTIC, PLASTIC};
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -6,19 +6,18 @@ import edu.kit.informatik.model.Item;
|
|||||||
import edu.kit.informatik.ui.InvalidInputException;
|
import edu.kit.informatik.ui.InvalidInputException;
|
||||||
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.Set;
|
||||||
|
|
||||||
import static edu.kit.informatik.ui.command.CommandFactory.BUILDABLE;
|
import static edu.kit.informatik.ui.command.CommandFactory.BUILDABLE;
|
||||||
|
|
||||||
public class Buildable extends Command {
|
public class Buildable extends Command {
|
||||||
@Override
|
@Override
|
||||||
public void apply(CardGame game) {
|
public void apply(CardGame game) {
|
||||||
List<Item> buildable = game.getBuildableItems();
|
Set<Item> buildable = game.getBuildableItems();
|
||||||
if (buildable.isEmpty()) {
|
if (buildable.isEmpty()) {
|
||||||
Terminal.printLine("EMPTY");
|
Terminal.printLine("EMPTY");
|
||||||
} else {
|
} else {
|
||||||
buildable.sort(Comparator.comparing(Object::toString));
|
buildable.stream().sorted(Comparator.comparing(Object::toString)).forEach(Terminal::printLine);
|
||||||
buildable.forEach(Terminal::printLine);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ import static edu.kit.informatik.ui.command.CommandFactory.LIST_BUILDINGS;
|
|||||||
|
|
||||||
public class ListBuildings extends Command {
|
public class ListBuildings extends Command {
|
||||||
@Override
|
@Override
|
||||||
public void apply(CardGame game) throws InvalidInputException {
|
public void apply(CardGame game) {
|
||||||
List<Item> items = game.getItems();
|
List<Item> items = game.getItems();
|
||||||
if (items.isEmpty()) {
|
if (items.isEmpty()) {
|
||||||
Terminal.printLine("EMPTY");
|
Terminal.printLine("EMPTY");
|
||||||
|
@ -11,7 +11,7 @@ import static edu.kit.informatik.ui.command.CommandFactory.LIST_RESOURCES;
|
|||||||
|
|
||||||
public class ListResources extends Command {
|
public class ListResources extends Command {
|
||||||
@Override
|
@Override
|
||||||
public void apply(CardGame game) throws InvalidInputException {
|
public void apply(CardGame game) {
|
||||||
Deque<Card> resources = game.getResources();
|
Deque<Card> resources = game.getResources();
|
||||||
if (resources.isEmpty()) {
|
if (resources.isEmpty()) {
|
||||||
Terminal.printLine("EMPTY");
|
Terminal.printLine("EMPTY");
|
||||||
|
@ -6,18 +6,12 @@ import edu.kit.informatik.model.CardGame;
|
|||||||
import edu.kit.informatik.ui.InvalidInputException;
|
import edu.kit.informatik.ui.InvalidInputException;
|
||||||
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
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 {
|
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;
|
private Deque<Card> cards;
|
||||||
|
|
||||||
@ -39,13 +33,14 @@ public class Start extends Command {
|
|||||||
if (!matcher.matches()) {
|
if (!matcher.matches()) {
|
||||||
throw new InvalidInputException("invalid start arguments");
|
throw new InvalidInputException("invalid start arguments");
|
||||||
}
|
}
|
||||||
cards = Arrays.stream(matcher.group(1).split(","))
|
cards = new ArrayDeque<>();
|
||||||
.map(Card::parse)
|
for (String s : matcher.group(1).split(",")) {
|
||||||
.collect(Collectors.toCollection(ArrayDeque::new));
|
Card card = Card.parse(s);
|
||||||
if (cards.stream().anyMatch(Objects::isNull)) {
|
if (card == null) {
|
||||||
cards = null;
|
|
||||||
throw new InvalidInputException("invalid start argument value(s)");
|
throw new InvalidInputException("invalid start argument value(s)");
|
||||||
}
|
}
|
||||||
|
cards.add(card);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
Dieser Befehl ermöglicht es dem Benutzer, ein neues Spiel zu starten. Dieser Befehl kann nur
|
Dieser Befehl ermöglicht es dem Benutzer, ein neues Spiel zu starten. Dieser Befehl kann nur
|
||||||
|
Loading…
Reference in New Issue
Block a user