Lose game after encountering animal with no actions left

This commit is contained in:
Arne Keller 2020-03-12 22:25:01 +01:00
parent 22446ea8aa
commit 48d014e4de
3 changed files with 51 additions and 17 deletions

View File

@ -9,6 +9,23 @@ public enum Card {
TIGER,
THUNDERSTORM;
public CardCategory category() {
switch (this) {
case WOOD:
case METAL:
case PLASTIC:
return CardCategory.RESOURCE;
case SPIDER:
case SNAKE:
case TIGER:
return CardCategory.ANIMAL;
case THUNDERSTORM:
return CardCategory.CATASTROPHE;
default:
return null;
}
}
public boolean isResource() {
return this.equals(WOOD) || this.equals(METAL) || this.equals(PLASTIC);
}

View File

@ -0,0 +1,7 @@
package edu.kit.informatik.cardgame.model;
public enum CardCategory {
RESOURCE,
ANIMAL,
CATASTROPHE
}

View File

@ -45,20 +45,21 @@ public class CardGame {
throw new LogicException("can only draw cards in scavenge phase");
}
final Card card = currentCardStack.removeFirst();
if (card.isResource()) {
switch (card.category()) {
case RESOURCE:
resources.add(card);
} else if (card.needsDiceRoll()) {
break;
case ANIMAL:
awaitedDiceSize = card.diceSizeNeeded();
minimumDiceRoll = card.minimumDiceRollNeeded();
phase = Phase.ENCOUNTER;
} else if (card.isCatastrophe()) {
break;
case CATASTROPHE:
clearResources();
items.remove(Item.FIREPLACE);
break;
}
if (currentCardStack.isEmpty() && getBuildableItems().isEmpty()) {
endGame();
this.phase = Phase.LOST;
}
checkLost();
return card;
}
@ -76,6 +77,7 @@ public class CardGame {
if (phase == Phase.ENCOUNTER) {
final int bonus = items.stream().mapToInt(Item::fightingBonus).max().orElse(0);
phase = Phase.SCAVENGE;
checkLost();
if (roll + bonus >= minimumNeeded) {
return "survived";
} else {
@ -90,6 +92,7 @@ public class CardGame {
return "win";
} else {
phase = Phase.SCAVENGE;
checkLost();
return "lose";
}
}
@ -130,10 +133,7 @@ public class CardGame {
}
break;
case DEFAULT:
if (currentCardStack != null && currentCardStack.isEmpty() && getBuildableItems().isEmpty()) {
endGame();
phase = Phase.LOST;
}
checkLost();
break;
}
@ -170,6 +170,16 @@ public class CardGame {
return gameStarted() && phase != Phase.WON && phase != Phase.LOST;
}
private void checkLost() {
if (phase != Phase.LOST
&& currentCardStack != null && currentCardStack.isEmpty()
&& phase != Phase.ENCOUNTER && phase != Phase.ENDEAVOR
&& !Arrays.stream(Item.values()).anyMatch(this::canBuild)) {
endGame();
phase = Phase.LOST;
}
}
public boolean gameLost() {
return phase == Phase.LOST;
}