diff --git a/src/main/java/cz/jull/Buildable.java b/src/main/java/cz/jull/Buildable.java new file mode 100644 index 0000000..ed052ff --- /dev/null +++ b/src/main/java/cz/jull/Buildable.java @@ -0,0 +1,5 @@ +package cz.jull; + +public interface Buildable { + boolean canBuild(Game game); +} diff --git a/src/main/java/cz/jull/Game.java b/src/main/java/cz/jull/Game.java index b011f3b..be3ad04 100644 --- a/src/main/java/cz/jull/Game.java +++ b/src/main/java/cz/jull/Game.java @@ -4,20 +4,60 @@ import cz.jull.surroundings.ForestType; import cz.jull.surroundings.PathType; import cz.jull.surroundings.SoilType; import cz.jull.surroundings.WaterType; +import lombok.Getter; + +import java.util.ArrayList; +import java.util.List; public class Game { + @Getter private Player player = new Player(); + private ForestType forestType; - private WaterType waterType; + + @Getter private SoilType soilType; + + @Getter private PathType pathType; + @Getter + private WaterType waterType; + + @Getter + private List buildings = new ArrayList<>(); + public void generateStats() { forestType = ForestType.getRandom(); - waterType = WaterType.getRandom(); soilType = SoilType.getRandom(); pathType = PathType.getRandom(); + waterType = WaterType.getRandom(); + + if (waterType == WaterType.WELL) { + buildings.add(Item.WELL); + } player.setCoins(10000); } + + public void build(Item item) { + if (!player.getInventory().contains(item)) { + System.out.println(" "); // TODO + return; + } + + if (item.canBuild(this)) { + buildings.add(item); + player.getInventory().remove(item); + } + } + + public void cutTrees() { + long axeCount = player.getInventory().stream().filter(item -> item == Item.AXE).count(); + if (axeCount < forestType.getAxesNeeded()) { + System.out.println(" "); //TODO + return; + } + forestType.setSize(forestType.getSize() - 1); + } } diff --git a/src/main/java/cz/jull/Item.java b/src/main/java/cz/jull/Item.java index 8714933..67733ed 100644 --- a/src/main/java/cz/jull/Item.java +++ b/src/main/java/cz/jull/Item.java @@ -2,31 +2,147 @@ package cz.jull; import lombok.Getter; -@Getter -public enum Item { - AXE("Axe"), - SCYTHE("Scythe"), +import java.util.List; +import java.util.function.Function; - WOOD("Wood"), - WHEAT("Wheat"), - GRAPES("Grapes"), - HOPS("Hops"), +public enum Item implements Buildable { + AXE("Axe", false), + SCYTHE("Scythe", false), - MILK("Milk"), + WOOD("Wood", false), - VINEYARD("Vineyard"), - FARMLAND("Farmland"), + WHEAT("Wheat", true), + HOPS("Hops", true), + GRAPES("Grapes", true), - FENCE_WITH_COWS("Fence with cows"), + MILK("Milk", false), - VILLAGER_HOUSE("Villager house"), - CHURCH("Church"), - PUB("Pub"); + VINEYARD("Vineyard", true), + FARMLAND("Farmland", true), + FENCE_WITH_COWS("Fence with cows", true), + + CHURCH("Church", true), + VILLAGER_HOUSE("Villager house", true), + PUB("Pub", true), + WINERY("Winery", true), + WELL("Well", true); + + static { + WHEAT.function = game -> { + if (game.getBuildings().stream().filter(building -> building == Item.FARMLAND).count() >= game.getBuildings().stream().filter(building -> building == Item.WHEAT || building == Item.HOPS).count() + 1) { + return true; + } + System.out.println(" "); //TODO + return false; + }; + + HOPS.function = game -> { + if (game.getBuildings().stream().filter(building -> building == Item.FARMLAND).count() >= game.getBuildings().stream().filter(building -> building == Item.WHEAT || building == Item.HOPS).count() + 1) { + return true; + } + System.out.println(" "); //TODO + return false; + }; + + GRAPES.function = game -> { + if (game.getBuildings().stream().filter(building -> building == Item.VINEYARD).count() >= game.getBuildings().stream().filter(building -> building == Item.GRAPES || building == Item.HOPS).count() + 1) { + return true; + } + System.out.println(" "); //TODO + return false; + }; + + VINEYARD.function = game -> { + if (game.getBuildings().stream().filter(building -> building == Item.VINEYARD).count() >= game.getWaterType().getFarmlandAndVineyardCount()) { + return true; + } + System.out.println(" "); //TODO + return false; + }; + + FARMLAND.function = game -> { + if (!game.getBuildings().contains(Item.VILLAGER_HOUSE)) { + System.out.println(" "); // TODO + return false; + } + if (game.getBuildings().stream().filter(building -> building == Item.FARMLAND).count() >= game.getWaterType().getFarmlandAndVineyardCount()) { + System.out.println(" "); // TODO + return false; + } + return true; + }; + + FENCE_WITH_COWS.function = game -> { + if (game.getBuildings().stream().filter(building -> building == Item.VILLAGER_HOUSE).count() >= (game.getBuildings().stream().filter(building -> building == Item.FENCE_WITH_COWS).count() + 1) * 3) { + return true; + } + System.out.println(" "); //TODO + return false; + }; + + CHURCH.function = game -> { + if (!game.getBuildings().contains(Item.CHURCH)) { + return true; + } + System.out.println(" "); //TODO + return false; + }; + + VILLAGER_HOUSE.function = game -> { + if (game.getBuildings().contains(Item.CHURCH)) { + return true; + } + System.out.println(" "); //TODO + return false; + }; + + PUB.function = game -> { + if (!game.getBuildings().contains(Item.VILLAGER_HOUSE)) { + System.out.println(" "); // TODO + return false; + } + + if (!game.getBuildings().contains(Item.HOPS)) { + System.out.println(" "); // TODO + return false; + } + return true; + }; + + WINERY.function = game -> { + if (!game.getBuildings().contains(Item.VILLAGER_HOUSE)) { + System.out.println(" "); // TODO + return false; + } + + if (!game.getBuildings().contains(Item.GRAPES)) { + System.out.println(" "); // TODO + return false; + } + return true; + }; + } + + @Getter private final String name; - Item(String name) { + private final boolean isPLaceable; + + private Function function; + + Item(String name, boolean isPLaceable) { this.name = name; + this.isPLaceable = isPLaceable; + this.function = ignored -> isPLaceable; + } + + @Override + public boolean canBuild(Game game) { + if (!isPLaceable) { + return false; + } + return function.apply(game); } } diff --git a/src/main/java/cz/jull/market/Market.java b/src/main/java/cz/jull/market/Market.java index 6cc036f..f1529a1 100644 --- a/src/main/java/cz/jull/market/Market.java +++ b/src/main/java/cz/jull/market/Market.java @@ -1,5 +1,6 @@ package cz.jull.market; +import cz.jull.Game; import cz.jull.Item; import cz.jull.Player; @@ -11,17 +12,16 @@ public class Market { Item.AXE, Item.SCYTHE, Item.VINEYARD, Item.FARMLAND, Item.VILLAGER_HOUSE, Item.CHURCH, Item.FENCE_WITH_COWS, - Item.PUB + Item.PUB, Item.WINERY )); public void sellItem(Player player, Item item) { player.getInventory().remove(item); } - public void buyItem(Player player, Item item) throws Exception { + public void buyItem(Game game, Item item) throws Exception { if (availableItems.contains(item)) { - player.getInventory().add(item); - availableItems.remove(item); + game.getPlayer().getInventory().add(item); } else { throw new Exception("Item is not available"); } diff --git a/src/main/java/cz/jull/surroundings/ForestType.java b/src/main/java/cz/jull/surroundings/ForestType.java index e470fae..3d1fce9 100644 --- a/src/main/java/cz/jull/surroundings/ForestType.java +++ b/src/main/java/cz/jull/surroundings/ForestType.java @@ -1,11 +1,23 @@ package cz.jull.surroundings; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + import java.util.Random; +@AllArgsConstructor public enum ForestType { - SMALL, - MEDIUM, - LARGE; + SMALL(25, 1), + MEDIUM(50, 3), + LARGE(100, 5); + + @Getter + @Setter + private int size; + + @Getter + private final int axesNeeded; public static ForestType getRandom() { Random random = new Random(); diff --git a/src/main/java/cz/jull/surroundings/WaterType.java b/src/main/java/cz/jull/surroundings/WaterType.java index ad768ce..76b3f8b 100644 --- a/src/main/java/cz/jull/surroundings/WaterType.java +++ b/src/main/java/cz/jull/surroundings/WaterType.java @@ -1,11 +1,18 @@ package cz.jull.surroundings; +import lombok.AllArgsConstructor; +import lombok.Getter; + import java.util.Random; +@AllArgsConstructor public enum WaterType { - WELL, - POND, - RIVER; + WELL(5), + POND(10), + RIVER(15); + + @Getter + private final int farmlandAndVineyardCount; public static WaterType getRandom() { Random random = new Random(); diff --git a/src/main/java/cz/jull/tui/Cli.java b/src/main/java/cz/jull/tui/Cli.java new file mode 100644 index 0000000..f7e0a98 --- /dev/null +++ b/src/main/java/cz/jull/tui/Cli.java @@ -0,0 +1,63 @@ +package cz.jull.tui; + +import java.io.Console; +import java.util.List; +import java.util.Scanner; + +public class Cli { + public static String header(String text) { + int totalWidth = 100; + int padding = (totalWidth - text.length()) / 2; + + StringBuilder stringBuilder = new StringBuilder(totalWidth); + for (int i = 0; i < padding; i++) { + stringBuilder.append("="); + } + + if (!text.isEmpty()) { + stringBuilder.append(" "); + stringBuilder.append(text); + stringBuilder.append(" "); + } + + for (int i = 0; i < padding; i++) { + stringBuilder.append("="); + } + + while (stringBuilder.length() < totalWidth) { + stringBuilder.insert(0, "="); + } + + return stringBuilder.toString(); + } + + public static void pressEnter() { + Console console = System.console(); + console.readLine(); + } + + public static int selectOptionIndex(List options) { + Scanner scanner = new Scanner(System.in); + int choice; + + System.out.println("Chose an option: "); + for (int i = 0; i < options.size(); i++) { + System.out.println((i + 1) + ". " + options.get(i)); + } + + while (true) { + System.out.print("Vlož číslo možnosti: "); + if (scanner.hasNextInt()) { + choice = scanner.nextInt(); + if (choice >= 1 && choice <= options.size()) { + return choice - 1; + } else { + System.out.println("Neplatná možnost, vyber si číslo mezi 1 a " + options.size()); + } + } else { + System.out.println("Neplatný vstup, vlož číslo."); + scanner.next(); + } + } + } +} diff --git a/src/main/java/cz/jull/tui/Colors.java b/src/main/java/cz/jull/tui/Colors.java new file mode 100644 index 0000000..ede546c --- /dev/null +++ b/src/main/java/cz/jull/tui/Colors.java @@ -0,0 +1,45 @@ +package cz.jull.tui; + +public class Colors { + public static final String RESET = "\033[0m"; + + // Text colors + public static final String BLACK = "\033[0;30m"; + public static final String RED = "\033[0;31m"; + public static final String GREEN = "\033[0;32m"; + public static final String YELLOW = "\033[0;33m"; + public static final String BLUE = "\033[0;34m"; + public static final String PURPLE = "\033[0;35m"; + public static final String CYAN = "\033[0;36m"; + public static final String WHITE = "\033[0;37m"; + + // Bold text colors (in bold) + public static final String BOLD_BLACK = "\033[1;30m"; + public static final String BOLD_RED = "\033[1;31m"; + public static final String BOLD_GREEN = "\033[1;32m"; + public static final String BOLD_YELLOW = "\033[1;33m"; + public static final String BOLD_BLUE = "\033[1;34m"; + public static final String BOLD_PURPLE = "\033[1;35m"; + public static final String BOLD_CYAN = "\033[1;36m"; + public static final String BOLD_WHITE = "\033[1;37m"; + + // Background colors + public static final String BLACK_BACKGROUND = "\033[40m"; + public static final String RED_BACKGROUND = "\033[41m"; + public static final String GREEN_BACKGROUND = "\033[42m"; + public static final String YELLOW_BACKGROUND = "\033[43m"; + public static final String BLUE_BACKGROUND = "\033[44m"; + public static final String PURPLE_BACKGROUND = "\033[45m"; + public static final String CYAN_BACKGROUND = "\033[46m"; + public static final String WHITE_BACKGROUND = "\033[47m"; + + // Bold background colors + public static final String BOLD_BLACK_BACKGROUND = "\033[1;40m"; + public static final String BOLD_RED_BACKGROUND = "\033[1;41m"; + public static final String BOLD_GREEN_BACKGROUND = "\033[1;42m"; + public static final String BOLD_YELLOW_BACKGROUND = "\033[1;43m"; + public static final String BOLD_BLUE_BACKGROUND = "\033[1;44m"; + public static final String BOLD_PURPLE_BACKGROUND = "\033[1;45m"; + public static final String BOLD_CYAN_BACKGROUND = "\033[1;46m"; + public static final String BOLD_WHITE_BACKGROUND = "\033[1;47m"; +}