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
98ee0975a3
commit
3bd70a5350
@ -1,4 +1,5 @@
|
|||||||
build?
|
build?
|
||||||
|
draw
|
||||||
list-buildings
|
list-buildings
|
||||||
list-resources
|
list-resources
|
||||||
list-buildings I can build
|
list-buildings I can build
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
EMPTY
|
EMPTY
|
||||||
|
Error, no card to draw exists
|
||||||
EMPTY
|
EMPTY
|
||||||
EMPTY
|
EMPTY
|
||||||
Error, invalid list-buildings argument: none expected
|
Error, invalid list-buildings argument: none expected
|
||||||
|
@ -119,6 +119,8 @@ build shack
|
|||||||
build sailingraft
|
build sailingraft
|
||||||
rollD6 1
|
rollD6 1
|
||||||
build hangglider
|
build hangglider
|
||||||
|
draw
|
||||||
rollD6 3
|
rollD6 3
|
||||||
|
build anything
|
||||||
list-buildings
|
list-buildings
|
||||||
build ballon
|
build ballon
|
||||||
|
@ -62,7 +62,9 @@ OK
|
|||||||
OK
|
OK
|
||||||
lose
|
lose
|
||||||
OK
|
OK
|
||||||
|
Error, roll dice, please
|
||||||
lose
|
lose
|
||||||
|
Error, can not build item
|
||||||
shack
|
shack
|
||||||
fireplace
|
fireplace
|
||||||
club
|
club
|
||||||
|
@ -45,8 +45,7 @@ public class CardGame {
|
|||||||
public Card draw() throws InvalidInputException {
|
public Card draw() throws InvalidInputException {
|
||||||
if (cardStack == null || cardStack.isEmpty()) {
|
if (cardStack == null || cardStack.isEmpty()) {
|
||||||
throw new InvalidInputException("no card to draw exists");
|
throw new InvalidInputException("no card to draw exists");
|
||||||
}
|
} else if (awaitedDiceSize != null) {
|
||||||
if (awaitedDiceSize != null) {
|
|
||||||
throw new InvalidInputException("roll dice, please");
|
throw new InvalidInputException("roll dice, please");
|
||||||
}
|
}
|
||||||
Card card = cardStack.removeFirst();
|
Card card = cardStack.removeFirst();
|
||||||
@ -66,22 +65,26 @@ public class CardGame {
|
|||||||
public String rollDice(int size, int roll) throws InvalidInputException {
|
public String rollDice(int size, int roll) throws InvalidInputException {
|
||||||
if (awaitedDiceSize == null) {
|
if (awaitedDiceSize == null) {
|
||||||
throw new InvalidInputException("not expecting dice roll");
|
throw new InvalidInputException("not expecting dice roll");
|
||||||
}
|
} else if (awaitedDiceSize != size) {
|
||||||
if (awaitedDiceSize != size) {
|
|
||||||
throw new InvalidInputException("unexpected dice size");
|
throw new InvalidInputException("unexpected dice size");
|
||||||
|
} else if (roll > awaitedDiceSize || roll < 1) {
|
||||||
|
throw new InvalidInputException("impossible roll");
|
||||||
}
|
}
|
||||||
|
awaitedDiceSize = null;
|
||||||
|
int minimumNeeded = minimumDiceRoll;
|
||||||
|
minimumDiceRoll = null;
|
||||||
if (fightingAnimal) {
|
if (fightingAnimal) {
|
||||||
int bonus = items.contains(AXE) ? 2 : items.contains(CLUB) ? 1 : 0;
|
int bonus = items.contains(AXE) ? 2 : items.contains(CLUB) ? 1 : 0;
|
||||||
if (roll + bonus >= minimumDiceRoll) {
|
if (roll + bonus >= minimumNeeded) {
|
||||||
return "survived";
|
return "survived";
|
||||||
} else {
|
} else {
|
||||||
clearResources();
|
clearResources();
|
||||||
return "lose";
|
return "lose";
|
||||||
}
|
}
|
||||||
} else {
|
} else { // attempting to escape
|
||||||
// remove item used to escape
|
// remove item used to escape
|
||||||
items.remove(items.size() - 1);
|
items.remove(items.size() - 1);
|
||||||
if (roll >= minimumDiceRoll) {
|
if (roll >= minimumNeeded) {
|
||||||
return "win";
|
return "win";
|
||||||
} else {
|
} else {
|
||||||
return "lose";
|
return "lose";
|
||||||
@ -98,12 +101,10 @@ public class CardGame {
|
|||||||
|
|
||||||
public boolean build(Item item) throws InvalidInputException {
|
public boolean build(Item item) throws InvalidInputException {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
throw new InvalidInputException("can not build null item");
|
throw new InvalidInputException("can not build item");
|
||||||
}
|
} else if (item.requiresFireplace() && !items.contains(FIREPLACE)) {
|
||||||
if (item.requiresFireplace() && !items.contains(FIREPLACE)) {
|
|
||||||
throw new InvalidInputException("need fireplace to build");
|
throw new InvalidInputException("need fireplace to build");
|
||||||
}
|
} else 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
|
||||||
|
@ -32,8 +32,8 @@ public enum Item {
|
|||||||
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: // we don't have any such items, but could add some eventually
|
||||||
return null;
|
throw new IllegalArgumentException("item does not need resources");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user