Correctly handle wrong start input

This commit is contained in:
Arne Keller 2020-02-29 16:08:54 +01:00
parent 74cac150fa
commit 52ab63f578
6 changed files with 193 additions and 2 deletions

View File

@ -9,3 +9,4 @@ 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
start wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,spider,spider,spider,spider,spider,snake,snake,snake,snake,snake,tiger,tiger,tiger,tiger,tiger,thunderstorm

View File

@ -9,3 +9,4 @@ Error, invalid reset argument: none expected
Error, not expecting dice roll
Error, invalid start argument value(s)
Error, invalid start arguments
Error, invalid deck: missing or surplus cards

View File

@ -0,0 +1,82 @@
start wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,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
draw
rollD4 1
draw
rollD4 1
draw
rollD4 2
draw
rollD4 3
draw
rollD4 4
draw
rollD6 2
draw
rollD6 3
draw
rollD6 4
draw
rollD6 5
draw
rollD6 6
draw
rollD8 4
draw
rollD8 5
draw
rollD8 6
draw
rollD8 7
draw
rollD8 8
draw
list-resources
start wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,wood,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,plastic,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,metal,spider,spider,spider,spider,spider,snake,snake,snake,snake,snake,tiger,tiger,tiger,tiger,tiger,thunderstorm

View File

@ -0,0 +1,82 @@
OK
wood
wood
wood
wood
wood
wood
wood
wood
wood
wood
wood
wood
wood
wood
wood
wood
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
plastic
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
metal
spider
lose
spider
lose
spider
lose
spider
survived
spider
survived
snake
lose
snake
lose
snake
survived
snake
survived
snake
survived
tiger
lose
tiger
survived
tiger
survived
tiger
survived
tiger
survived
thunderstorm
EMPTY
OK

View File

@ -28,6 +28,11 @@ class MainTest {
cmpInOut("shack_test_input.txt", "shack_test_output.txt");
}
@Test
void gameOverNoActions() throws IOException {
cmpInOut("game_over_no_actions_input.txt", "game_over_no_actions_output.txt");
}
private void cmpInOut(String in, String out) throws IOException {
System.setIn(new ByteArrayInputStream(readFile(in)));
ByteArrayOutputStream output = new ByteArrayOutputStream();

View File

@ -1,17 +1,24 @@
package edu.kit.informatik.model;
import edu.kit.informatik.Terminal;
import edu.kit.informatik.ui.InvalidInputException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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.Card.METAL;
import static edu.kit.informatik.model.Card.PLASTIC;
import static edu.kit.informatik.model.Card.SNAKE;
import static edu.kit.informatik.model.Card.SPIDER;
import static edu.kit.informatik.model.Card.THUNDERSTORM;
import static edu.kit.informatik.model.Card.TIGER;
import static edu.kit.informatik.model.Card.WOOD;
import static edu.kit.informatik.model.Item.AXE;
import static edu.kit.informatik.model.Item.BALLOON;
import static edu.kit.informatik.model.Item.CLUB;
@ -32,10 +39,17 @@ public class CardGame {
/**
*
* @param cardStack order: 1st element = 1st to take
* @throws InvalidInputException if card stack has wrong distribution of cards
* @return
*/
public boolean start(Deque<Card> cardStack) {
public boolean start(Deque<Card> cardStack) throws InvalidInputException {
if (this.cardStack == null) {
if (Collections.frequency(cardStack, WOOD) != 16 || Collections.frequency(cardStack, PLASTIC) != 16
|| Collections.frequency(cardStack, METAL) != 16 || Collections.frequency(cardStack, SPIDER) != 5
|| Collections.frequency(cardStack, SNAKE) != 5 || Collections.frequency(cardStack, TIGER) != 5
|| Collections.frequency(cardStack, THUNDERSTORM) != 1) {
throw new InvalidInputException("invalid deck: missing or surplus cards");
}
this.cardStack = cardStack;
return true;
} else {
@ -60,6 +74,9 @@ public class CardGame {
clearResources();
items.remove(FIREPLACE);
}
if (cardStack.isEmpty() && getBuildableItems().isEmpty()) {
cardStack = null; // game over
}
return card;
}
@ -120,6 +137,9 @@ public class CardGame {
awaitedDiceSize = 6;
minimumDiceRoll = 4;
}
if (cardStack != null && cardStack.isEmpty() && getBuildableItems().isEmpty()) {
cardStack = null; // game over
}
return true;
} else {
return false;