mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final2.git
synced 2024-11-24 01:15:03 +00:00
Lose game after encountering animal with no actions left
This commit is contained in:
parent
22446ea8aa
commit
48d014e4de
@ -9,6 +9,23 @@ public enum Card {
|
|||||||
TIGER,
|
TIGER,
|
||||||
THUNDERSTORM;
|
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() {
|
public boolean isResource() {
|
||||||
return this.equals(WOOD) || this.equals(METAL) || this.equals(PLASTIC);
|
return this.equals(WOOD) || this.equals(METAL) || this.equals(PLASTIC);
|
||||||
}
|
}
|
||||||
|
7
src/edu/kit/informatik/cardgame/model/CardCategory.java
Normal file
7
src/edu/kit/informatik/cardgame/model/CardCategory.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package edu.kit.informatik.cardgame.model;
|
||||||
|
|
||||||
|
public enum CardCategory {
|
||||||
|
RESOURCE,
|
||||||
|
ANIMAL,
|
||||||
|
CATASTROPHE
|
||||||
|
}
|
@ -45,20 +45,21 @@ public class CardGame {
|
|||||||
throw new LogicException("can only draw cards in scavenge phase");
|
throw new LogicException("can only draw cards in scavenge phase");
|
||||||
}
|
}
|
||||||
final Card card = currentCardStack.removeFirst();
|
final Card card = currentCardStack.removeFirst();
|
||||||
if (card.isResource()) {
|
switch (card.category()) {
|
||||||
|
case RESOURCE:
|
||||||
resources.add(card);
|
resources.add(card);
|
||||||
} else if (card.needsDiceRoll()) {
|
break;
|
||||||
|
case ANIMAL:
|
||||||
awaitedDiceSize = card.diceSizeNeeded();
|
awaitedDiceSize = card.diceSizeNeeded();
|
||||||
minimumDiceRoll = card.minimumDiceRollNeeded();
|
minimumDiceRoll = card.minimumDiceRollNeeded();
|
||||||
phase = Phase.ENCOUNTER;
|
phase = Phase.ENCOUNTER;
|
||||||
} else if (card.isCatastrophe()) {
|
break;
|
||||||
|
case CATASTROPHE:
|
||||||
clearResources();
|
clearResources();
|
||||||
items.remove(Item.FIREPLACE);
|
items.remove(Item.FIREPLACE);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (currentCardStack.isEmpty() && getBuildableItems().isEmpty()) {
|
checkLost();
|
||||||
endGame();
|
|
||||||
this.phase = Phase.LOST;
|
|
||||||
}
|
|
||||||
return card;
|
return card;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +77,7 @@ public class CardGame {
|
|||||||
if (phase == Phase.ENCOUNTER) {
|
if (phase == Phase.ENCOUNTER) {
|
||||||
final int bonus = items.stream().mapToInt(Item::fightingBonus).max().orElse(0);
|
final int bonus = items.stream().mapToInt(Item::fightingBonus).max().orElse(0);
|
||||||
phase = Phase.SCAVENGE;
|
phase = Phase.SCAVENGE;
|
||||||
|
checkLost();
|
||||||
if (roll + bonus >= minimumNeeded) {
|
if (roll + bonus >= minimumNeeded) {
|
||||||
return "survived";
|
return "survived";
|
||||||
} else {
|
} else {
|
||||||
@ -90,6 +92,7 @@ public class CardGame {
|
|||||||
return "win";
|
return "win";
|
||||||
} else {
|
} else {
|
||||||
phase = Phase.SCAVENGE;
|
phase = Phase.SCAVENGE;
|
||||||
|
checkLost();
|
||||||
return "lose";
|
return "lose";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -130,10 +133,7 @@ public class CardGame {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DEFAULT:
|
case DEFAULT:
|
||||||
if (currentCardStack != null && currentCardStack.isEmpty() && getBuildableItems().isEmpty()) {
|
checkLost();
|
||||||
endGame();
|
|
||||||
phase = Phase.LOST;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -170,6 +170,16 @@ public class CardGame {
|
|||||||
return gameStarted() && phase != Phase.WON && phase != Phase.LOST;
|
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() {
|
public boolean gameLost() {
|
||||||
return phase == Phase.LOST;
|
return phase == Phase.LOST;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user