diff --git a/src/main/java/cz/jull/Game.java b/src/main/java/cz/jull/Game.java index 24d4262..d8a71be 100644 --- a/src/main/java/cz/jull/Game.java +++ b/src/main/java/cz/jull/Game.java @@ -123,7 +123,7 @@ public class Game { } System.out.println(); - player.setCoins(300); + player.setCoins(1000); strings.print("coins", player.getCoins()); System.out.println(); @@ -197,14 +197,17 @@ public class Game { } /** - * Function that picks an item for harvesting and puts teh produce in inventory + * Function that picks an item for harvesting and puts the produce in inventory * * @param item Item that is being harvested */ public void harvest(Item item) { Item item2 = switch (item) { - - } + case WHEAT_FARMLAND -> Item.WHEAT; + case HOPS_FARMLAND -> Item.HOPS; + case VINEYARD -> Item.GRAPEVINE; + default -> throw new IllegalArgumentException("Error: You can't harvest " + item); + }; if (waterType.getFarmlandCount() > buildings.stream().filter(item1 -> item1 == item2).count()) { System.out.println("You can't harvest"); @@ -214,42 +217,6 @@ public class Game { buildings.remove(item2); player.getInventory().add(item2); } - - - switch (item) { - case WHEAT_FARMLAND -> { - if (waterType.getFarmlandCount() > buildings.stream().filter(item1 -> item1 == Item.WHEAT).count()) { - System.out.println("You can't harvest"); - return; - } - for (int i = 0; i < waterType.getFarmlandCount() ; i++) { - buildings.remove(Item.WHEAT); - player.getInventory().add(Item.WHEAT); - } - } - - case HOPS_FARMLAND -> { - if (waterType.getFarmlandCount() > buildings.stream().filter(item1 -> item1 == Item.HOPS).count()) { - System.out.println("You can't harvest"); - return; - } - for (int i = 0; i < waterType.getFarmlandCount() ; i++) { - buildings.remove(Item.HOPS); - player.getInventory().add(Item.HOPS); - } - } - - case VINEYARD -> { - if (waterType.getFarmlandCount() > buildings.stream().filter(item1 -> item1 == Item.GRAPEVINE).count()) { - System.out.println("You can't harvest"); - return; - } - for (int i = 0; i < waterType.getFarmlandCount() ; i++) { - buildings.remove(Item.GRAPEVINE); - player.getInventory().add(Item.GRAPEVINE); - } - } - } } /** diff --git a/src/main/java/cz/jull/exceptions/ItemNotAvailableException.java b/src/main/java/cz/jull/exceptions/ItemNotAvailableException.java index 1e5254c..4fc78fd 100644 --- a/src/main/java/cz/jull/exceptions/ItemNotAvailableException.java +++ b/src/main/java/cz/jull/exceptions/ItemNotAvailableException.java @@ -1,6 +1,15 @@ package cz.jull.exceptions; +/** + * Exception thrown when an item is not available for an action (e.g., purchase). + */ public class ItemNotAvailableException extends RuntimeException { + + /** + * Constructs a new exception with the specified detail message. + * + * @param message the detail message explaining the reason for the exception + */ public ItemNotAvailableException(String message) { super(message); } diff --git a/src/main/java/cz/jull/exceptions/NotSufficientCoinsException.java b/src/main/java/cz/jull/exceptions/NotSufficientCoinsException.java new file mode 100644 index 0000000..5b1e160 --- /dev/null +++ b/src/main/java/cz/jull/exceptions/NotSufficientCoinsException.java @@ -0,0 +1,16 @@ +package cz.jull.exceptions; + +/** + * Exception thrown when a player does not have enough coins to perform an action. + */ +public class NotSufficientCoinsException extends RuntimeException { + + /** + * Constructs a new exception with the specified detail message. + * + * @param message the detail message explaining the reason for the exception + */ + public NotSufficientCoinsException(String message) { + super(message); + } +} diff --git a/src/main/java/cz/jull/exceptions/NotSufficientsCoinsException.java b/src/main/java/cz/jull/exceptions/NotSufficientsCoinsException.java deleted file mode 100644 index 9c21dee..0000000 --- a/src/main/java/cz/jull/exceptions/NotSufficientsCoinsException.java +++ /dev/null @@ -1,7 +0,0 @@ -package cz.jull.exceptions; - -public class NotSufficientsCoinsException extends RuntimeException { - public NotSufficientsCoinsException(String message) { - super(message); - } -} diff --git a/src/main/java/cz/jull/items/Buildable.java b/src/main/java/cz/jull/items/Buildable.java index 30ad308..c633109 100644 --- a/src/main/java/cz/jull/items/Buildable.java +++ b/src/main/java/cz/jull/items/Buildable.java @@ -2,6 +2,17 @@ package cz.jull.items; import cz.jull.Game; +/** + * Represents an item that can be built within the game. + * Implementing classes should define the logic that determines + * whether the item can currently be built, based on the game state. + */ public interface Buildable { + /** + * Determines whether the item can be built + * + * @param game The game + * @return {@code true} if the item can be built; {@code false} otherwise + */ boolean canBuild(Game game); } diff --git a/src/main/java/cz/jull/items/actions/Action.java b/src/main/java/cz/jull/items/actions/Action.java index 31fd0b1..6432db9 100644 --- a/src/main/java/cz/jull/items/actions/Action.java +++ b/src/main/java/cz/jull/items/actions/Action.java @@ -3,8 +3,22 @@ package cz.jull.items.actions; import cz.jull.Game; import cz.jull.items.Item; +/** + * Represents an abstract action that can be performed on an item within the game + */ public abstract class Action { + /** + * Returns the name or description of the action + * + * @return a string representing the action + */ public abstract String toString(); + /** + * Executes the action on the given item + * + * @param game The game + * @param item The item on which the action is performed + */ public abstract void execute(Game game, Item item); } diff --git a/src/main/java/cz/jull/items/actions/BuildAction.java b/src/main/java/cz/jull/items/actions/BuildAction.java index 17f8336..9f50037 100644 --- a/src/main/java/cz/jull/items/actions/BuildAction.java +++ b/src/main/java/cz/jull/items/actions/BuildAction.java @@ -3,12 +3,26 @@ package cz.jull.items.actions; import cz.jull.Game; import cz.jull.items.Item; +/** + * Represents a build action that can be performed on an item. + */ public class BuildAction extends Action { + /** + * Returns the name of the action. + * + * @return the string "Build" + */ @Override public String toString() { return "Build"; } + /** + * Executes the build action on the given item + * + * @param game The game + * @param item The item to be built + */ @Override public void execute(Game game, Item item) { game.build(item); diff --git a/src/main/java/cz/jull/items/actions/axe/AxeCutTreesAction.java b/src/main/java/cz/jull/items/actions/axe/AxeCutTreesAction.java index 9478fa3..39aab2b 100644 --- a/src/main/java/cz/jull/items/actions/axe/AxeCutTreesAction.java +++ b/src/main/java/cz/jull/items/actions/axe/AxeCutTreesAction.java @@ -4,12 +4,30 @@ import cz.jull.Game; import cz.jull.items.Item; import cz.jull.items.actions.Action; +/** + * Represents the action of cutting trees using an axe. + */ public class AxeCutTreesAction extends Action { + + /** + * Returns the name of the action. + * + * @return the string "Cut trees" + */ @Override public String toString() { return "Cut trees"; } + /** + * Executes the tree-cutting action. + *
+ * This method calls {@link Game#cutTrees()} to perform the action. + * The provided {@code item} parameter is not used in this implementation. + * + * @param game The game + * @param item The item related to the action (not used here) + */ @Override public void execute(Game game, Item item) { game.cutTrees(); diff --git a/src/main/java/cz/jull/items/actions/bakery/BakeryProduceAction.java b/src/main/java/cz/jull/items/actions/bakery/BakeryProduceAction.java index 45f7637..c4569cc 100644 --- a/src/main/java/cz/jull/items/actions/bakery/BakeryProduceAction.java +++ b/src/main/java/cz/jull/items/actions/bakery/BakeryProduceAction.java @@ -4,12 +4,27 @@ import cz.jull.Game; import cz.jull.items.Item; import cz.jull.items.actions.Action; +/** + * Represents an action for producing bread in the bakery + */ public class BakeryProduceAction extends Action { + + /** + * Returns the name of the action. + * + * @return the string "Produce bread" + */ @Override public String toString() { return "Produce bread"; } + /** + * Executes the bread production action on the given item + * + * @param game The game + * @param item The item on which the action is performed + */ @Override public void execute(Game game, Item item) { game.produce(item); diff --git a/src/main/java/cz/jull/items/actions/cheese_factory/CheeseFactoryProduceAction.java b/src/main/java/cz/jull/items/actions/cheese_factory/CheeseFactoryProduceAction.java index 9b0e573..19206c0 100644 --- a/src/main/java/cz/jull/items/actions/cheese_factory/CheeseFactoryProduceAction.java +++ b/src/main/java/cz/jull/items/actions/cheese_factory/CheeseFactoryProduceAction.java @@ -4,12 +4,27 @@ import cz.jull.Game; import cz.jull.items.Item; import cz.jull.items.actions.Action; +/** + * Represents an action for producing cheese in the cheese factory + */ public class CheeseFactoryProduceAction extends Action { + + /** + * Returns the name of the action. + * + * @return the string "Produce cheese" + */ @Override public String toString() { return "Produce cheese"; } + /** + * Executes the cheese production action on the given item + * + * @param game The game + * @param item The item on which the action is performed + */ @Override public void execute(Game game, Item item) { game.produce(item); diff --git a/src/main/java/cz/jull/items/actions/coal_factory/CoalFactoryProduceAction.java b/src/main/java/cz/jull/items/actions/coal_factory/CoalFactoryProduceAction.java index 9f81be8..0cfa2f9 100644 --- a/src/main/java/cz/jull/items/actions/coal_factory/CoalFactoryProduceAction.java +++ b/src/main/java/cz/jull/items/actions/coal_factory/CoalFactoryProduceAction.java @@ -4,12 +4,27 @@ import cz.jull.Game; import cz.jull.items.Item; import cz.jull.items.actions.Action; +/** + * Represents an action for producing coal in the coal factory + */ public class CoalFactoryProduceAction extends Action { + + /** + * Returns the name of the action + * + * @return the string "Produce coal" + */ @Override public String toString() { return "Produce coal"; } + /** + * Executes the coal production action on the given item + * + * @param game The game + * @param item The item on which the action is performed + */ @Override public void execute(Game game, Item item) { game.produce(item); diff --git a/src/main/java/cz/jull/items/actions/cow/CowMilkAction.java b/src/main/java/cz/jull/items/actions/cow/CowMilkAction.java index d50a9b0..ab49b94 100644 --- a/src/main/java/cz/jull/items/actions/cow/CowMilkAction.java +++ b/src/main/java/cz/jull/items/actions/cow/CowMilkAction.java @@ -4,12 +4,30 @@ import cz.jull.Game; import cz.jull.items.Item; import cz.jull.items.actions.Action; +/** + * Represents the action of milking a cow + */ public class CowMilkAction extends Action { + + /** + * Returns the name of the action + * + * @return the string "Get milk" + */ @Override public String toString() { return "Get milk"; } + /** + * Executes the milking action + *
+ * This method calls {@link Game#milkCow()} to perform the milking operation.
+ * The provided {@code item} parameter is not used in this implementation.
+ *
+ * @param game The game
+ * @param item The item related to the action (not used here)
+ */
@Override
public void execute(Game game, Item item) {
game.milkCow();
diff --git a/src/main/java/cz/jull/items/actions/hops_farmland/HopsFarmlandHarvestAction.java b/src/main/java/cz/jull/items/actions/hops_farmland/HopsFarmlandHarvestAction.java
index f64b138..d43122a 100644
--- a/src/main/java/cz/jull/items/actions/hops_farmland/HopsFarmlandHarvestAction.java
+++ b/src/main/java/cz/jull/items/actions/hops_farmland/HopsFarmlandHarvestAction.java
@@ -4,12 +4,27 @@ import cz.jull.Game;
import cz.jull.items.Item;
import cz.jull.items.actions.Action;
+/**
+ * Represents the action of harvesting hops from a hops farmland
+ */
public class HopsFarmlandHarvestAction extends Action {
+
+ /**
+ * Returns the name of the action
+ *
+ * @return the string "Harvest hops"
+ */
@Override
public String toString() {
return "Harvest hops";
}
+ /**
+ * Executes the hops harvest action on the given item
+ *
+ * @param game The game
+ * @param item The item on which the action is performed
+ */
@Override
public void execute(Game game, Item item) {
game.harvest(Item.HOPS_FARMLAND);
diff --git a/src/main/java/cz/jull/items/actions/hops_farmland/HopsFarmlandPlantAction.java b/src/main/java/cz/jull/items/actions/hops_farmland/HopsFarmlandPlantAction.java
index 2edf5b9..e529cab 100644
--- a/src/main/java/cz/jull/items/actions/hops_farmland/HopsFarmlandPlantAction.java
+++ b/src/main/java/cz/jull/items/actions/hops_farmland/HopsFarmlandPlantAction.java
@@ -4,12 +4,27 @@ import cz.jull.Game;
import cz.jull.items.Item;
import cz.jull.items.actions.Action;
+/**
+ * Represents the action of planting hops seeds on a hops farmland
+ */
public class HopsFarmlandPlantAction extends Action {
+
+ /**
+ * Returns the name of the action
+ *
+ * @return the string "Plant hops seeds"
+ */
@Override
public String toString() {
return "Plant hops seeds";
}
+ /**
+ * Executes the hops seeds plant action on the given item
+ *
+ * @param game The game
+ * @param item The item on which the action is performed
+ */
@Override
public void execute(Game game, Item item) {
game.build(Item.HOPS_SEEDS);
diff --git a/src/main/java/cz/jull/items/actions/pub/PubProduceAction.java b/src/main/java/cz/jull/items/actions/pub/PubProduceAction.java
index 66bef3f..990e343 100644
--- a/src/main/java/cz/jull/items/actions/pub/PubProduceAction.java
+++ b/src/main/java/cz/jull/items/actions/pub/PubProduceAction.java
@@ -4,12 +4,27 @@ import cz.jull.Game;
import cz.jull.items.Item;
import cz.jull.items.actions.Action;
+/**
+ * Represents an action for producing beer in the pub
+ */
public class PubProduceAction extends Action {
+
+ /**
+ * Returns the name of the action.
+ *
+ * @return the string "Produce beer"
+ */
@Override
public String toString() {
return "Produce beer";
}
+ /**
+ * Executes the beer production action on the given item
+ *
+ * @param game The game
+ * @param item The item on which the action is performed
+ */
@Override
public void execute(Game game, Item item) {
game.produce(item);
diff --git a/src/main/java/cz/jull/items/actions/vineyard/VineyardHarvestAction.java b/src/main/java/cz/jull/items/actions/vineyard/VineyardHarvestAction.java
index 5cf18e8..26fbcb2 100644
--- a/src/main/java/cz/jull/items/actions/vineyard/VineyardHarvestAction.java
+++ b/src/main/java/cz/jull/items/actions/vineyard/VineyardHarvestAction.java
@@ -4,12 +4,27 @@ import cz.jull.Game;
import cz.jull.items.Item;
import cz.jull.items.actions.Action;
+/**
+ * Represents the action of harvesting grapevines from a vineyard
+ */
public class VineyardHarvestAction extends Action {
+
+ /**
+ * Returns the name of the action
+ *
+ * @return the string "Harvest grapevines"
+ */
@Override
public String toString() {
- return "Harverst grapevines";
+ return "Harvest grapevines";
}
+ /**
+ * Executes the grapevine harvest action on the given item
+ *
+ * @param game The game
+ * @param item The item on which the action is performed
+ */
@Override
public void execute(Game game, Item item) {
game.harvest(Item.VINEYARD);
diff --git a/src/main/java/cz/jull/items/actions/vineyard/VineyardPlantAction.java b/src/main/java/cz/jull/items/actions/vineyard/VineyardPlantAction.java
index 1c11c0d..282e0be 100644
--- a/src/main/java/cz/jull/items/actions/vineyard/VineyardPlantAction.java
+++ b/src/main/java/cz/jull/items/actions/vineyard/VineyardPlantAction.java
@@ -4,12 +4,27 @@ import cz.jull.Game;
import cz.jull.items.Item;
import cz.jull.items.actions.Action;
+/**
+ * Represents the action of planting grapevines on a vineyard
+ */
public class VineyardPlantAction extends Action {
+
+ /**
+ * Returns the name of the action
+ *
+ * @return the string "Plant grapevine seeds"
+ */
@Override
public String toString() {
return "Plant grapevine seeds";
}
+ /**
+ * Executes the grapevine plant action on the given item
+ *
+ * @param game The game
+ * @param item The item on which the action is performed
+ */
@Override
public void execute(Game game, Item item) {
game.build(Item.GRAPEVINE_SEEDS);
diff --git a/src/main/java/cz/jull/items/actions/wheat_farmland/WheatFarmlandHarvestAction.java b/src/main/java/cz/jull/items/actions/wheat_farmland/WheatFarmlandHarvestAction.java
index ab03d9d..0b16fa7 100644
--- a/src/main/java/cz/jull/items/actions/wheat_farmland/WheatFarmlandHarvestAction.java
+++ b/src/main/java/cz/jull/items/actions/wheat_farmland/WheatFarmlandHarvestAction.java
@@ -4,12 +4,27 @@ import cz.jull.Game;
import cz.jull.items.Item;
import cz.jull.items.actions.Action;
+/**
+ * Represents the action of harvesting wheat from a wheat farmland
+ */
public class WheatFarmlandHarvestAction extends Action {
+
+ /**
+ * Returns the name of the action
+ *
+ * @return the string "Harvest wheat"
+ */
@Override
public String toString() {
- return "Harvest wheats";
+ return "Harvest wheat";
}
+ /**
+ * Executes the wheat harvest action on the given item
+ *
+ * @param game The game
+ * @param item The item on which the action is performed
+ */
@Override
public void execute(Game game, Item item) {
game.harvest(Item.WHEAT_FARMLAND);
diff --git a/src/main/java/cz/jull/items/actions/wheat_farmland/WheatFarmlandPlantAction.java b/src/main/java/cz/jull/items/actions/wheat_farmland/WheatFarmlandPlantAction.java
index d64cb2c..2485c88 100644
--- a/src/main/java/cz/jull/items/actions/wheat_farmland/WheatFarmlandPlantAction.java
+++ b/src/main/java/cz/jull/items/actions/wheat_farmland/WheatFarmlandPlantAction.java
@@ -4,12 +4,27 @@ import cz.jull.Game;
import cz.jull.items.Item;
import cz.jull.items.actions.Action;
+/**
+ * Represents the action of planting wheat seeds on a wheat farmland
+ */
public class WheatFarmlandPlantAction extends Action {
+
+ /**
+ * Returns the name of the action
+ *
+ * @return the string "Plant wheat seeds"
+ */
@Override
public String toString() {
return "Plant wheat seeds";
}
+ /**
+ * Executes the wheat seeds plant action on the given item
+ *
+ * @param game The game
+ * @param item The item on which the action is performed
+ */
@Override
public void execute(Game game, Item item) {
game.build(Item.WHEAT_SEEDS);
diff --git a/src/main/java/cz/jull/items/actions/winery/WineryProduceAction.java b/src/main/java/cz/jull/items/actions/winery/WineryProduceAction.java
index ad3e2aa..c08bc47 100644
--- a/src/main/java/cz/jull/items/actions/winery/WineryProduceAction.java
+++ b/src/main/java/cz/jull/items/actions/winery/WineryProduceAction.java
@@ -4,12 +4,27 @@ import cz.jull.Game;
import cz.jull.items.Item;
import cz.jull.items.actions.Action;
+/**
+ * Represents an action for producing wine in a winery
+ */
public class WineryProduceAction extends Action {
+
+ /**
+ * Returns the name of the action
+ *
+ * @return the string "Produce wine"
+ */
@Override
public String toString() {
return "Produce wine";
}
+ /**
+ * Executes the wine production action on the given item
+ *
+ * @param game The game
+ * @param item The item on which the action is performed
+ */
@Override
public void execute(Game game, Item item) {
game.produce(item);
diff --git a/src/main/java/cz/jull/market/Market.java b/src/main/java/cz/jull/market/Market.java
index 0b5557b..8acbf99 100644
--- a/src/main/java/cz/jull/market/Market.java
+++ b/src/main/java/cz/jull/market/Market.java
@@ -3,7 +3,7 @@ package cz.jull.market;
import cz.jull.Game;
import cz.jull.items.Item;
import cz.jull.exceptions.ItemNotAvailableException;
-import cz.jull.exceptions.NotSufficientsCoinsException;
+import cz.jull.exceptions.NotSufficientCoinsException;
import cz.jull.stats.surroundings.PathType;
import cz.jull.stats.surroundings.SoilType;
import lombok.Getter;
@@ -11,13 +11,28 @@ import lombok.Getter;
import java.util.ArrayList;
import java.util.List;
+/**
+ * Class that manages buying and selling logic
+ */
@Getter
public class Market {
+ /**
+ * The available items
+ */
private final List
+ * If the item is in the player's inventory, it is removed and its price is added to the player's coins.
+ * If the item is not in the inventory, a message is printed and no action is taken.
+ *
+ * @param game The game
+ * @param item Item that is being sold
+ */
public void sellItem(Game game, Item item) {
if (!game.getPlayer().getInventory().contains(item)) {
game.getStrings().print("cantSell");
@@ -29,17 +44,28 @@ public class Market {
game.getStrings().print("marketSellMessage", item);
}
- public void buyItem(Game game, Item item) throws ItemNotAvailableException, NotSufficientsCoinsException {
+ /**
+ * Buys an item from the {@link #availableItems}
+ *
+ * Function that takes item from the {@link #availableItems} and then adds it to player's inventory.
+ * If the item is a farmland or seed item, it is added multiple times based on the player's water type.
+ *
+ * @param game The game
+ * @param item Item that is being bought
+ * @throws ItemNotAvailableException If the item is not present in {@link #availableItems}
+ * @throws NotSufficientCoinsException If the player does not have enough coins to buy the item (or enough for multiple copies)
+ */
+ public void buyItem(Game game, Item item) throws ItemNotAvailableException, NotSufficientCoinsException {
if (game.getPlayer().getCoins() < item.getPrice()) {
- throw new NotSufficientsCoinsException("Not enough coins");
+ throw new NotSufficientCoinsException("Not enough coins");
}
if (availableItems.contains(item)) {
if (List.of(Item.WHEAT_SEEDS, Item.HOPS_SEEDS, Item.GRAPEVINE_SEEDS, Item.WHEAT_FARMLAND, Item.HOPS_FARMLAND, Item.VINEYARD).contains(item)) {
- if (game.getPlayer().getCoins() < (long) item.getPrice() * game.getWaterType().getFarmlandAndVineyardCount()) {
- throw new NotSufficientsCoinsException("Not enough coins, you need " + game.getWaterType().getFarmlandAndVineyardCount() * item.getPrice() + " coins");
+ if (game.getPlayer().getCoins() < (long) item.getPrice() * game.getWaterType().getFarmlandCount()) {
+ throw new NotSufficientCoinsException("Not enough coins, you need " + game.getWaterType().getFarmlandCount() * item.getPrice() + " coins");
}
- for (int i = 0; i < game.getWaterType().getFarmlandAndVineyardCount() ; i++) {
+ for (int i = 0; i < game.getWaterType().getFarmlandCount() ; i++) {
game.getPlayer().getInventory().add(item);
game.getPlayer().setCoins(game.getPlayer().getCoins() - item.getPrice());
}
@@ -57,6 +83,11 @@ public class Market {
}
}
+ /**
+ * Constructor that adds different items for different stats
+ *
+ * @param game The game
+ */
public Market(Game game) {
// Soil Type
if (game.getSoilType() == SoilType.STONY) {
diff --git a/src/main/java/cz/jull/stats/surroundings/ForestType.java b/src/main/java/cz/jull/stats/surroundings/ForestType.java
index 2ec4687..3ceeb89 100644
--- a/src/main/java/cz/jull/stats/surroundings/ForestType.java
+++ b/src/main/java/cz/jull/stats/surroundings/ForestType.java
@@ -6,21 +6,38 @@ import lombok.Setter;
import java.util.Random;
+/**
+ * Enum that manages forest types for the game
+ */
@AllArgsConstructor
public enum ForestType {
SMALL("Small", 25, 1),
MEDIUM("Medium",50, 3),
LARGE("Large", 100, 5);
+ /**
+ * Human-readable name
+ */
private final String name;
+ /**
+ * Size of the forest type
+ */
@Getter
@Setter
private int size;
+ /**
+ * Axes needed for cutting trees
+ */
@Getter
private final int axesNeeded;
+ /**
+ * Function that returns random path type
+ *
+ * @return random enum
+ */
public static ForestType getRandom() {
Random random = new Random();
ForestType[] types = values();
@@ -28,6 +45,11 @@ public enum ForestType {
return types[random.nextInt(types.length)];
}
+ /**
+ * Returns human-readable name
+ *
+ * @return Human-readable name
+ */
@Override
public String toString() {
return name;
diff --git a/src/main/java/cz/jull/stats/surroundings/PathType.java b/src/main/java/cz/jull/stats/surroundings/PathType.java
index b1fa266..4729fe5 100644
--- a/src/main/java/cz/jull/stats/surroundings/PathType.java
+++ b/src/main/java/cz/jull/stats/surroundings/PathType.java
@@ -2,17 +2,28 @@ package cz.jull.stats.surroundings;
import java.util.Random;
+/**
+ * Enum that manages path types for the game
+ */
public enum PathType {
DEAD_END("Dead end"),
SIDE_PATH("Side path"),
MAIN_PATH("Main path"),;
+ /**
+ * Human-readable name
+ */
private final String name;
PathType(String name) {
this.name = name;
}
+ /**
+ * Function that returns random path type
+ *
+ * @return random enum
+ */
public static PathType getRandom() {
Random random = new Random();
PathType[] types = values();
@@ -20,6 +31,11 @@ public enum PathType {
return types[random.nextInt(types.length)];
}
+ /**
+ * Returns human-readable name
+ *
+ * @return Human-readable name
+ */
@Override
public String toString() {
return name;
diff --git a/src/main/java/cz/jull/stats/surroundings/SoilType.java b/src/main/java/cz/jull/stats/surroundings/SoilType.java
index 6c5ee13..a60bb7e 100644
--- a/src/main/java/cz/jull/stats/surroundings/SoilType.java
+++ b/src/main/java/cz/jull/stats/surroundings/SoilType.java
@@ -2,13 +2,28 @@ package cz.jull.stats.surroundings;
import java.util.Random;
+/**
+ * Enum that manages soil types for the game
+ */
public enum SoilType {
STONY("Stony"),
LESS_FERTILE("Moderately fertile"),
FERTILE("Fertile"),;
+ /**
+ * Human-readable name
+ */
private final String name;
+ SoilType(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Function that returns random soil type
+ *
+ * @return random enum
+ */
public static SoilType getRandom() {
Random random = new Random();
SoilType[] types = values();
@@ -16,10 +31,11 @@ public enum SoilType {
return types[random.nextInt(types.length)];
}
- SoilType(String name) {
- this.name = name;
- }
-
+ /**
+ * Returns human-readable name
+ *
+ * @return Human-readable name
+ */
@Override
public String toString() {
return name;
diff --git a/src/main/java/cz/jull/stats/surroundings/WaterType.java b/src/main/java/cz/jull/stats/surroundings/WaterType.java
index fe2b0ec..c687d46 100644
--- a/src/main/java/cz/jull/stats/surroundings/WaterType.java
+++ b/src/main/java/cz/jull/stats/surroundings/WaterType.java
@@ -5,6 +5,9 @@ import lombok.Getter;
import java.util.Random;
+/**
+ * Enum that manages water types for the game
+ */
@AllArgsConstructor
public enum WaterType {
WELL("Well",5),
@@ -19,6 +22,11 @@ public enum WaterType {
@Getter
private final int farmlandCount;
+ /**
+ * Function that returns random water type
+ *
+ * @return random enum
+ */
public static WaterType getRandom() {
Random random = new Random();
WaterType[] types = values();
diff --git a/src/main/java/cz/jull/tui/Menu.java b/src/main/java/cz/jull/tui/Menu.java
index 055ae30..9960d5c 100644
--- a/src/main/java/cz/jull/tui/Menu.java
+++ b/src/main/java/cz/jull/tui/Menu.java
@@ -4,7 +4,7 @@ import cz.jull.Game;
import cz.jull.items.Item;
import cz.jull.items.actions.Action;
import cz.jull.exceptions.ItemNotAvailableException;
-import cz.jull.exceptions.NotSufficientsCoinsException;
+import cz.jull.exceptions.NotSufficientCoinsException;
import lombok.RequiredArgsConstructor;
import java.io.IOException;
@@ -95,7 +95,7 @@ public class Menu {
Item item = game.getMarket().getAvailableItems().get(itemIndex);
try {
game.getMarket().buyItem(game, item);
- } catch (NotSufficientsCoinsException | ItemNotAvailableException e) {
+ } catch (NotSufficientCoinsException | ItemNotAvailableException e) {
System.out.println("\033[4;31mError: " + e.getMessage() + "\033[0m");
}