mirror of
https://gitlab.com/arnekeller/kit-programmieren-ws1920-final2.git
synced 2024-11-08 09:50:38 +00:00
Javadoc + code style
This commit is contained in:
parent
64f517d201
commit
6333f3d6a5
@ -3,11 +3,12 @@ package edu.kit.informatik.cardgame.model;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Game card.
|
* Game card. These can be used to {@link Inventory#build build items},
|
||||||
|
* start a fight with an {@link CardCategory#ANIMAL animal} or clear some of the player's belongings.
|
||||||
*
|
*
|
||||||
* @see CardCategory
|
* @see CardCategory
|
||||||
* @author Arne Keller
|
* @author Arne Keller
|
||||||
* @version 1.0
|
* @version 1.1
|
||||||
*/
|
*/
|
||||||
public enum Card implements RequireDice {
|
public enum Card implements RequireDice {
|
||||||
/**
|
/**
|
||||||
@ -35,7 +36,7 @@ public enum Card implements RequireDice {
|
|||||||
*/
|
*/
|
||||||
TIGER,
|
TIGER,
|
||||||
/**
|
/**
|
||||||
* Thunderstorm. Lifts up items and blows them away.
|
* Thunderstorm. Lifts up items and takes them away. Also blows out the fireplace.
|
||||||
*/
|
*/
|
||||||
THUNDERSTORM;
|
THUNDERSTORM;
|
||||||
|
|
||||||
@ -77,10 +78,10 @@ public enum Card implements RequireDice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> activate(CardGame game, int diceSize, int roll) {
|
public Optional<String> activate(CardGame game, int size, int roll) {
|
||||||
if (!this.diceSizeNeeded().isPresent()) {
|
if (!this.diceSizeNeeded().isPresent()) {
|
||||||
throw new IllegalStateException("can not process dice roll");
|
throw new IllegalStateException("can not process dice roll");
|
||||||
} else if (this.diceSizeNeeded().get() != diceSize || roll > diceSize || roll < 1) {
|
} else if (this.diceSizeNeeded().get() != size || roll > size || roll < 1) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +115,7 @@ public enum Card implements RequireDice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private Optional<Integer> diceSizeNeeded() {
|
||||||
public Optional<Integer> diceSizeNeeded() {
|
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case SPIDER:
|
case SPIDER:
|
||||||
return Optional.of(4);
|
return Optional.of(4);
|
||||||
@ -128,8 +128,7 @@ public enum Card implements RequireDice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private Optional<Integer> minimumDiceRollNeeded() {
|
||||||
public Optional<Integer> minimumDiceRollNeeded() {
|
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case SPIDER:
|
case SPIDER:
|
||||||
return Optional.of(3);
|
return Optional.of(3);
|
||||||
|
@ -10,8 +10,8 @@ import java.util.stream.Collectors;
|
|||||||
/**
|
/**
|
||||||
* Simple card game. Features:
|
* Simple card game. Features:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>100% deterministic</li>
|
* <li>100% deterministic (user tells game dice roll results)</li>
|
||||||
* <li>64! different card stacks</li>
|
* <li>64! different card stacks (including functionally equivalent stacks)</li>
|
||||||
* <li>8 buildable {@link Item} items</li>
|
* <li>8 buildable {@link Item} items</li>
|
||||||
* <li>7 exciting {@link Card card} types</li>
|
* <li>7 exciting {@link Card card} types</li>
|
||||||
* <li>3 dice needed</li>
|
* <li>3 dice needed</li>
|
||||||
@ -100,9 +100,6 @@ public class CardGame {
|
|||||||
* @param requireDice something that requires a dice roll
|
* @param requireDice something that requires a dice roll
|
||||||
*/
|
*/
|
||||||
public void startDiceRoll(RequireDice requireDice) {
|
public void startDiceRoll(RequireDice requireDice) {
|
||||||
if (!requireDice.diceSizeNeeded().isPresent()) {
|
|
||||||
throw new IllegalArgumentException("object does not require dice");
|
|
||||||
}
|
|
||||||
this.requireDice = requireDice;
|
this.requireDice = requireDice;
|
||||||
phase = Phase.AWAITING_DICE_ROLL;
|
phase = Phase.AWAITING_DICE_ROLL;
|
||||||
}
|
}
|
||||||
|
@ -10,13 +10,18 @@ import static edu.kit.informatik.cardgame.model.Card.WOOD;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Game item that can be built by the player. Categorized into several {@link ItemCategory categories}.
|
* Game item that can be built by the player. Categorized into several {@link ItemCategory categories}.
|
||||||
|
* An item can give a {@link #fightingBonus fighting bonus} against {@link CardCategory#ANIMAL animals},
|
||||||
|
* {@link #itemsSecured secure items} or let the player {@link ItemCategory#ESCAPE escape}.
|
||||||
|
* Some items require a dice to be rolled (see {@link #activate(CardGame, int, int)}).
|
||||||
*
|
*
|
||||||
|
* @see ItemCategory
|
||||||
* @author Arne Keller
|
* @author Arne Keller
|
||||||
* @version 1.0
|
* @version 1.1
|
||||||
*/
|
*/
|
||||||
public enum Item implements RequireDice {
|
public enum Item implements RequireDice {
|
||||||
/**
|
/**
|
||||||
* Axe. Provides an {@link #fightingBonus attack bonus} of two.
|
* Axe. Provides an {@link #fightingBonus attack bonus} of two.
|
||||||
|
* Should be used in preference to the {@link #CLUB club} if available.
|
||||||
*/
|
*/
|
||||||
AXE,
|
AXE,
|
||||||
/**
|
/**
|
||||||
@ -24,7 +29,8 @@ public enum Item implements RequireDice {
|
|||||||
*/
|
*/
|
||||||
CLUB,
|
CLUB,
|
||||||
/**
|
/**
|
||||||
* Shack. Can {@link #itemsSecured save} the last five items in case of animal attacks or catastrophic events.
|
* Shack. Can {@link #itemsSecured save} the last five items in case of {@link CardCategory#ANIMAL animal} attacks
|
||||||
|
* or {@link CardCategory#CATASTROPHE catastrophic events}.
|
||||||
*/
|
*/
|
||||||
SHACK,
|
SHACK,
|
||||||
/**
|
/**
|
||||||
@ -32,7 +38,7 @@ public enum Item implements RequireDice {
|
|||||||
*/
|
*/
|
||||||
FIREPLACE,
|
FIREPLACE,
|
||||||
/**
|
/**
|
||||||
* Sailing raft. Can be used to attempt an escape.
|
* Sailing raft. Can be used to {@link #activate(CardGame, int, int) attempt} an escape.
|
||||||
*/
|
*/
|
||||||
SAILING_RAFT,
|
SAILING_RAFT,
|
||||||
/**
|
/**
|
||||||
@ -40,14 +46,14 @@ public enum Item implements RequireDice {
|
|||||||
*/
|
*/
|
||||||
HANG_GLIDER,
|
HANG_GLIDER,
|
||||||
/**
|
/**
|
||||||
* Steam boat. Can be used to escape.
|
* Steam boat. Can be used to escape. Requires a fireplace to build.
|
||||||
*/
|
*/
|
||||||
STEAMBOAT,
|
STEAMBOAT,
|
||||||
/**
|
/**
|
||||||
* Ballon: making it seem as though a [stranded person] effortlessly becomes airborne,
|
* A misspelled hot-air balloon. Requires a fireplace to build.
|
||||||
* floats in the air, and lands softly.
|
|
||||||
*/
|
*/
|
||||||
BALLON;
|
BALLON;
|
||||||
|
// note: new items require changes in resourcesNeeded, parse and toString
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return value indicating success.
|
* Return value indicating success.
|
||||||
@ -91,10 +97,10 @@ public enum Item implements RequireDice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> activate(CardGame game, int diceSize, int roll) {
|
public Optional<String> activate(CardGame game, int size, int roll) {
|
||||||
if (!this.diceSizeNeeded().isPresent()) {
|
if (!this.diceSizeNeeded().isPresent()) {
|
||||||
throw new IllegalStateException("can not process dice roll");
|
throw new IllegalStateException("can not process dice roll");
|
||||||
} else if (this.diceSizeNeeded().get() != diceSize || roll > diceSize || roll < 1) {
|
} else if (this.diceSizeNeeded().get() != size || roll > size || roll < 1) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,8 +180,7 @@ public enum Item implements RequireDice {
|
|||||||
return this == Item.SHACK ? 5 : 0;
|
return this == Item.SHACK ? 5 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private Optional<Integer> diceSizeNeeded() {
|
||||||
public Optional<Integer> diceSizeNeeded() {
|
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case HANG_GLIDER:
|
case HANG_GLIDER:
|
||||||
case SAILING_RAFT:
|
case SAILING_RAFT:
|
||||||
@ -185,8 +190,7 @@ public enum Item implements RequireDice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private Optional<Integer> minimumDiceRollNeeded() {
|
||||||
public Optional<Integer> minimumDiceRollNeeded() {
|
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case HANG_GLIDER:
|
case HANG_GLIDER:
|
||||||
case SAILING_RAFT:
|
case SAILING_RAFT:
|
||||||
|
@ -6,30 +6,16 @@ import java.util.Optional;
|
|||||||
* Objects of classes implementing this optionally require a dice to be rolled.
|
* Objects of classes implementing this optionally require a dice to be rolled.
|
||||||
*
|
*
|
||||||
* @author Arne Keller
|
* @author Arne Keller
|
||||||
* @version 1.0
|
* @version 2.0
|
||||||
*/
|
*/
|
||||||
public interface RequireDice {
|
public interface RequireDice {
|
||||||
/**
|
/**
|
||||||
* Get the size of the dice needed to activate this object.
|
* Activate this object in a game if the dice roll is good enough.
|
||||||
*
|
|
||||||
* @return dice size needed to use this item (empty if dice not required)
|
|
||||||
*/
|
|
||||||
Optional<Integer> diceSizeNeeded();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the minimum dice roll needed to activate this object.
|
|
||||||
*
|
|
||||||
* @return minimum dice roll needed to use this item (empty if dice not required)
|
|
||||||
*/
|
|
||||||
Optional<Integer> minimumDiceRollNeeded();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Activate this object in a game, if the dice roll is good enough.
|
|
||||||
*
|
*
|
||||||
* @param game card game to use
|
* @param game card game to use
|
||||||
* @param diceSize size of the dice rolled
|
* @param size size of the dice rolled
|
||||||
* @param roll result of the dice roll
|
* @param roll result of the dice roll
|
||||||
* @return activation result (empty if dice roll is incorrect)
|
* @return activation result (empty if dice roll is incorrect)
|
||||||
*/
|
*/
|
||||||
Optional<String> activate(CardGame game, int diceSize, int roll);
|
Optional<String> activate(CardGame game, int size, int roll);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user