diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index f9a6ec1..b04cd77 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -3,7 +3,7 @@
-
+
diff --git a/src/main/java/cz/jull/Game.java b/src/main/java/cz/jull/Game.java
index d7578ad..73f312d 100644
--- a/src/main/java/cz/jull/Game.java
+++ b/src/main/java/cz/jull/Game.java
@@ -35,6 +35,8 @@ public class Game {
private final List events = new ArrayList<>();
+ private int milkedToday = 0;
+
public Game(Strings strings) {
this.strings = strings;
}
@@ -46,9 +48,26 @@ public class Game {
Menu menu = new Menu(this);
for (int i = 0; i < 10; i++) {
- menu.start();
+ menu.start(i);
+ long wheatSeedsCount = buildings.stream().filter(item -> item == Item.WHEAT_SEEDS).count();
+ for (int j = 0; j < wheatSeedsCount; j++) {
+ buildings.remove(Item.WHEAT_SEEDS);
+ buildings.add(Item.WHEAT);
+ }
+
+ long hopsSeedsCount = buildings.stream().filter(item -> item == Item.HOPS_SEEDS).count();
+ for (int k = 0; k < hopsSeedsCount; k++) {
+ buildings.remove(Item.HOPS_SEEDS);
+ buildings.add(Item.HOPS);
+ }
+
+ long grapevineSeedsCount = buildings.stream().filter(item -> item == Item.GRAPEVINE_SEEDS).count();
+ for (int l = 0; l < grapevineSeedsCount; l++) {
+ buildings.remove(Item.GRAPEVINE_SEEDS);
+ buildings.add(Item.GRAPEVINE);
+ }
+ milkedToday = 0;
}
- // TODO the whole game
}
public void generateStats() {
@@ -109,6 +128,10 @@ public class Game {
}
public void cutTrees() {
+ if (forestType.getSize() <= 0 ) {
+ strings.print("noTrees");
+ return;
+ }
long axeCount = player.getInventory().stream().filter(item -> item == Item.AXE).count();
if (axeCount < forestType.getAxesNeeded()) {
strings.print("cantCutTrees", forestType.getAxesNeeded());
@@ -124,22 +147,34 @@ public class Game {
public void harvest(Item item) {
switch (item) {
case WHEAT_FARMLAND -> {
+ if (waterType.getFarmlandAndVineyardCount() > buildings.stream().filter(item1 -> item1 == Item.WHEAT).count()) {
+ System.out.println("You can't harvest");
+ return;
+ }
for (int i = 0; i < waterType.getFarmlandAndVineyardCount() ; i++) {
- buildings.remove(Item.WHEAT_SEEDS);
+ buildings.remove(Item.WHEAT);
player.getInventory().add(Item.WHEAT);
}
}
case HOPS_FARMLAND -> {
+ if (waterType.getFarmlandAndVineyardCount() > buildings.stream().filter(item1 -> item1 == Item.HOPS).count()) {
+ System.out.println("You can't harvest");
+ return;
+ }
for (int i = 0; i < waterType.getFarmlandAndVineyardCount() ; i++) {
- buildings.remove(Item.HOPS_SEEDS);
+ buildings.remove(Item.HOPS);
player.getInventory().add(Item.HOPS);
}
}
case VINEYARD -> {
+ if (waterType.getFarmlandAndVineyardCount() > buildings.stream().filter(item1 -> item1 == Item.GRAPEVINE).count()) {
+ System.out.println("You can't harvest");
+ return;
+ }
for (int i = 0; i < waterType.getFarmlandAndVineyardCount() ; i++) {
- buildings.remove(Item.GRAPEVINE_SEEDS);
+ buildings.remove(Item.GRAPEVINE);
player.getInventory().add(Item.GRAPEVINE);
}
}
@@ -147,11 +182,16 @@ public class Game {
}
public void milkCow() {
+ if (milkedToday >= 3) {
+ strings.print("cantMilkToMuch");
+ return;
+ }
+
if (!buildings.contains(Item.FENCE_WITH_COWS)) {
strings.print("cantMilkCows");
return;
}
-
+ milkedToday++;
player.getInventory().add(Item.MILK);
}
diff --git a/src/main/java/cz/jull/tui/Cli.java b/src/main/java/cz/jull/tui/Cli.java
index 92e4b72..75d4b24 100644
--- a/src/main/java/cz/jull/tui/Cli.java
+++ b/src/main/java/cz/jull/tui/Cli.java
@@ -54,7 +54,7 @@ public class Cli {
if (choice >= 1 && choice <= options.size()) {
return choice - 1;
} else {
- System.out.println("Invalid option, choose a number between 1 and" + options.size());
+ System.out.println("Invalid option, choose a number between 1 and " + options.size());
System.out.println();
}
} else {
diff --git a/src/main/java/cz/jull/tui/Menu.java b/src/main/java/cz/jull/tui/Menu.java
index 4ea4f90..15bf13f 100644
--- a/src/main/java/cz/jull/tui/Menu.java
+++ b/src/main/java/cz/jull/tui/Menu.java
@@ -30,52 +30,55 @@ public class Menu {
}
}
- public void start() {
+ public void start(int day) {
int index = Cli.selectOptionIndex(List.of(
"See your inventory",
"See what you have built",
"Go to Market",
- "See your stats" ));
+ "See your stats",
+ "Next Day"));
switch (index) {
case 0 -> {
List- inventory = game.getPlayer().getInventory();
Map
- grouped = group(inventory);
- List mapped = new ArrayList<>(grouped.keySet().stream().map(item -> grouped.get(item) + "x " + item).toList());
+ List
- keys = grouped.keySet().stream().toList();
+ List mapped = new ArrayList<>(keys.stream().map(item -> grouped.get(item) + "x " + item).toList());
mapped.add("Go back");
int itemIndex = Cli.selectOptionIndex(mapped);
if (itemIndex == mapped.size() - 1) {
- start();
+ start(day);
return;
}
- Item item = game.getPlayer().getInventory().get(itemIndex);
+ Item item = keys.get(itemIndex);
String art = loadResource("item_art/" + item.name() + ".txt");
System.out.println(art);
System.out.println();
List actions = item.getActions();
- actionMenu(item, actions);
+ actionMenu(item, actions, day);
}
case 1 -> {
List
- buildings = game.getBuildings();
Map
- grouped = group(buildings);
+ List
- keys = grouped.keySet().stream().toList();
List mapped = new ArrayList<>(grouped.keySet().stream().map(item -> grouped.get(item) + "x " + item).toList());
mapped.add("Go back");
int itemIndex = Cli.selectOptionIndex(mapped);
- if (itemIndex == buildings.size() - 1) {
- start();
+ if (itemIndex == mapped.size() - 1) {
+ start(day);
return;
}
- Item item = game.getBuildings().get(itemIndex);
+ Item item = keys.get(itemIndex);
String art = loadResource("item_art/" + item.name() + ".txt");
System.out.println(art);
System.out.println();
List actions = item.getBuildActions();
- actionMenu(item, actions);
+ actionMenu(item, actions, day);
}
case 2 -> {
game.getStrings().print("marketGreeting");
@@ -105,7 +108,7 @@ public class Menu {
Item item = game.getMarket().getAvailableItems().get(itemIndex);
game.getMarket().sellItem(game, item);
}
- case 2 -> start();
+ case 2 -> start(day);
}
}
case 3 -> {
@@ -121,15 +124,20 @@ public class Menu {
game.getStrings().print("forestSize", game.getForestType().getSize());
System.out.println();
}
+ case 4 -> {
+ game.getStrings().print("currentDay", day + 2);
+ return;
+ }
}
+ start(day);
}
- private void actionMenu(Item item, List actions) {
+ private void actionMenu(Item item, List actions, int day) {
List actionStrings = new ArrayList<>(actions.stream().map(Action::toString).toList());
actionStrings.add("Go back");
int actionIndex = Cli.selectOptionIndex(actionStrings);
if (actionIndex == actionStrings.size() - 1) {
- start();
+ start(day);
return;
}
Action action = actions.get(actionIndex);
diff --git a/src/main/java/cz/jull/tui/Strings.java b/src/main/java/cz/jull/tui/Strings.java
index 9b65818..bbef677 100644
--- a/src/main/java/cz/jull/tui/Strings.java
+++ b/src/main/java/cz/jull/tui/Strings.java
@@ -38,7 +38,9 @@ public class Strings {
private String cantBuy;
private String forestSize;
private String stats;
-
+ private String currentDay;
+ private String cantMilkToMuch;
+ private String noTrees;
/**
* Loads strings from json file
diff --git a/strings.json b/strings.json
index 6a6b25e..7b4dde1 100644
--- a/strings.json
+++ b/strings.json
@@ -23,5 +23,8 @@
"cantProduce": "You can`t produce when you dont have {0}",
"cantSell": "You can`t sell this item! You don`t have it!",
"forestSize": "The size of your forest is {0} trees",
- "stats": "Your stats: "
+ "stats": "Your stats: ",
+ "currentDay": "Day: {0}",
+ "cantMilkToMuch": "You milked the cow already 3 times today!",
+ "noTrees": "You don't have any trees left!"
}
\ No newline at end of file