feat: a lot of changes
This commit is contained in:
5
src/main/java/cz/jull/Buildable.java
Normal file
5
src/main/java/cz/jull/Buildable.java
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package cz.jull;
|
||||||
|
|
||||||
|
public interface Buildable {
|
||||||
|
boolean canBuild(Game game);
|
||||||
|
}
|
||||||
@@ -4,20 +4,60 @@ import cz.jull.surroundings.ForestType;
|
|||||||
import cz.jull.surroundings.PathType;
|
import cz.jull.surroundings.PathType;
|
||||||
import cz.jull.surroundings.SoilType;
|
import cz.jull.surroundings.SoilType;
|
||||||
import cz.jull.surroundings.WaterType;
|
import cz.jull.surroundings.WaterType;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Game {
|
public class Game {
|
||||||
|
@Getter
|
||||||
private Player player = new Player();
|
private Player player = new Player();
|
||||||
|
|
||||||
private ForestType forestType;
|
private ForestType forestType;
|
||||||
private WaterType waterType;
|
|
||||||
|
@Getter
|
||||||
private SoilType soilType;
|
private SoilType soilType;
|
||||||
|
|
||||||
|
@Getter
|
||||||
private PathType pathType;
|
private PathType pathType;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private WaterType waterType;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private List<Item> buildings = new ArrayList<>();
|
||||||
|
|
||||||
public void generateStats() {
|
public void generateStats() {
|
||||||
forestType = ForestType.getRandom();
|
forestType = ForestType.getRandom();
|
||||||
waterType = WaterType.getRandom();
|
|
||||||
soilType = SoilType.getRandom();
|
soilType = SoilType.getRandom();
|
||||||
pathType = PathType.getRandom();
|
pathType = PathType.getRandom();
|
||||||
|
waterType = WaterType.getRandom();
|
||||||
|
|
||||||
|
if (waterType == WaterType.WELL) {
|
||||||
|
buildings.add(Item.WELL);
|
||||||
|
}
|
||||||
|
|
||||||
player.setCoins(10000);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,31 +2,147 @@ package cz.jull;
|
|||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
@Getter
|
import java.util.List;
|
||||||
public enum Item {
|
import java.util.function.Function;
|
||||||
AXE("Axe"),
|
|
||||||
SCYTHE("Scythe"),
|
|
||||||
|
|
||||||
WOOD("Wood"),
|
|
||||||
|
|
||||||
WHEAT("Wheat"),
|
public enum Item implements Buildable {
|
||||||
GRAPES("Grapes"),
|
AXE("Axe", false),
|
||||||
HOPS("Hops"),
|
SCYTHE("Scythe", false),
|
||||||
|
|
||||||
MILK("Milk"),
|
WOOD("Wood", false),
|
||||||
|
|
||||||
VINEYARD("Vineyard"),
|
WHEAT("Wheat", true),
|
||||||
FARMLAND("Farmland"),
|
HOPS("Hops", true),
|
||||||
|
GRAPES("Grapes", true),
|
||||||
|
|
||||||
FENCE_WITH_COWS("Fence with cows"),
|
MILK("Milk", false),
|
||||||
|
|
||||||
VILLAGER_HOUSE("Villager house"),
|
VINEYARD("Vineyard", true),
|
||||||
CHURCH("Church"),
|
FARMLAND("Farmland", true),
|
||||||
PUB("Pub");
|
|
||||||
|
|
||||||
|
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;
|
private final String name;
|
||||||
|
|
||||||
Item(String name) {
|
private final boolean isPLaceable;
|
||||||
|
|
||||||
|
private Function<Game, Boolean> function;
|
||||||
|
|
||||||
|
Item(String name, boolean isPLaceable) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.isPLaceable = isPLaceable;
|
||||||
|
this.function = ignored -> isPLaceable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canBuild(Game game) {
|
||||||
|
if (!isPLaceable) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return function.apply(game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package cz.jull.market;
|
package cz.jull.market;
|
||||||
|
|
||||||
|
import cz.jull.Game;
|
||||||
import cz.jull.Item;
|
import cz.jull.Item;
|
||||||
import cz.jull.Player;
|
import cz.jull.Player;
|
||||||
|
|
||||||
@@ -11,17 +12,16 @@ public class Market {
|
|||||||
Item.AXE, Item.SCYTHE,
|
Item.AXE, Item.SCYTHE,
|
||||||
Item.VINEYARD, Item.FARMLAND,
|
Item.VINEYARD, Item.FARMLAND,
|
||||||
Item.VILLAGER_HOUSE, Item.CHURCH, Item.FENCE_WITH_COWS,
|
Item.VILLAGER_HOUSE, Item.CHURCH, Item.FENCE_WITH_COWS,
|
||||||
Item.PUB
|
Item.PUB, Item.WINERY
|
||||||
));
|
));
|
||||||
|
|
||||||
public void sellItem(Player player, Item item) {
|
public void sellItem(Player player, Item item) {
|
||||||
player.getInventory().remove(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)) {
|
if (availableItems.contains(item)) {
|
||||||
player.getInventory().add(item);
|
game.getPlayer().getInventory().add(item);
|
||||||
availableItems.remove(item);
|
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Item is not available");
|
throw new Exception("Item is not available");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,23 @@
|
|||||||
package cz.jull.surroundings;
|
package cz.jull.surroundings;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
public enum ForestType {
|
public enum ForestType {
|
||||||
SMALL,
|
SMALL(25, 1),
|
||||||
MEDIUM,
|
MEDIUM(50, 3),
|
||||||
LARGE;
|
LARGE(100, 5);
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
private int size;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final int axesNeeded;
|
||||||
|
|
||||||
public static ForestType getRandom() {
|
public static ForestType getRandom() {
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
|||||||
@@ -1,11 +1,18 @@
|
|||||||
package cz.jull.surroundings;
|
package cz.jull.surroundings;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
public enum WaterType {
|
public enum WaterType {
|
||||||
WELL,
|
WELL(5),
|
||||||
POND,
|
POND(10),
|
||||||
RIVER;
|
RIVER(15);
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
private final int farmlandAndVineyardCount;
|
||||||
|
|
||||||
public static WaterType getRandom() {
|
public static WaterType getRandom() {
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
|||||||
63
src/main/java/cz/jull/tui/Cli.java
Normal file
63
src/main/java/cz/jull/tui/Cli.java
Normal file
@@ -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<String> 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
45
src/main/java/cz/jull/tui/Colors.java
Normal file
45
src/main/java/cz/jull/tui/Colors.java
Normal file
@@ -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";
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user