Javadoc + code cleanup

This commit is contained in:
Arne Keller 2020-03-12 23:01:32 +01:00
parent b42d783127
commit ae79b31f3d
2 changed files with 25 additions and 14 deletions

View File

@ -1,12 +1,33 @@
package edu.kit.informatik.cardgame.model; package edu.kit.informatik.cardgame.model;
public enum Card { public enum Card {
/**
* Wood. Basic resource.
*/
WOOD, WOOD,
/**
* Metal. Basic resource.
*/
METAL, METAL,
/**
* Plastic. Basic resource.
*/
PLASTIC, PLASTIC,
/**
* Spider. Deadly animal.
*/
SPIDER, SPIDER,
/**
* Snake. Dangerous animal.
*/
SNAKE, SNAKE,
/**
* Tiger. Strong animal.
*/
TIGER, TIGER,
/**
* Thunderstorm. Lifts up items and blows them away.
*/
THUNDERSTORM; THUNDERSTORM;
public CardCategory category() { public CardCategory category() {
@ -22,18 +43,10 @@ public enum Card {
case THUNDERSTORM: case THUNDERSTORM:
return CardCategory.CATASTROPHE; return CardCategory.CATASTROPHE;
default: default:
return null; throw new IllegalArgumentException("no category defined for this card");
} }
} }
public boolean isResource() {
return this.equals(WOOD) || this.equals(METAL) || this.equals(PLASTIC);
}
public boolean needsDiceRoll() {
return this.diceSizeNeeded() > 0;
}
public int diceSizeNeeded() { public int diceSizeNeeded() {
switch (this) { switch (this) {
case SPIDER: case SPIDER:
@ -60,10 +73,6 @@ public enum Card {
} }
} }
public boolean isCatastrophe() {
return this.equals(THUNDERSTORM);
}
public int requiredAmount() { public int requiredAmount() {
switch (this) { switch (this) {
case WOOD: case WOOD:
@ -120,7 +129,7 @@ public enum Card {
case THUNDERSTORM: case THUNDERSTORM:
return "thunderstorm"; return "thunderstorm";
default: default:
return null; throw new IllegalArgumentException("toString not defined for this card value");
} }
} }
} }

View File

@ -58,6 +58,8 @@ public class CardGame {
clearResources(); clearResources();
items.remove(Item.FIREPLACE); items.remove(Item.FIREPLACE);
break; break;
default:
throw new IllegalStateException("encountered unknown card category!");
} }
checkLost(); checkLost();
return card; return card;