feat: JavaDoc
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package cz.jull.exceptions;
|
||||
|
||||
public class NotSufficientsCoinsException extends RuntimeException {
|
||||
public NotSufficientsCoinsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
* <p>
|
||||
* 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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
* <p>
|
||||
* 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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<Item> availableItems = new ArrayList<>(List.of(
|
||||
Item.AXE,
|
||||
Item.VILLAGER_HOUSE, Item.CHURCH
|
||||
));
|
||||
|
||||
/**
|
||||
* Sells an item from the player's inventory.
|
||||
* <p>
|
||||
* 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}
|
||||
* <p>
|
||||
* 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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user