feat: a lot of changes
This commit is contained in:
2
.idea/inspectionProfiles/Project_Default.xml
generated
2
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -3,7 +3,7 @@
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<Languages>
|
||||
<language minSize="68" name="Java" />
|
||||
<language minSize="69" name="Java" />
|
||||
</Languages>
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
|
||||
@@ -35,6 +35,8 @@ public class Game {
|
||||
|
||||
private final List<Events> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<Item> inventory = game.getPlayer().getInventory();
|
||||
Map<Item, Integer> grouped = group(inventory);
|
||||
List<String> mapped = new ArrayList<>(grouped.keySet().stream().map(item -> grouped.get(item) + "x " + item).toList());
|
||||
List<Item> keys = grouped.keySet().stream().toList();
|
||||
List<String> 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<Action> actions = item.getActions();
|
||||
actionMenu(item, actions);
|
||||
actionMenu(item, actions, day);
|
||||
}
|
||||
case 1 -> {
|
||||
List<Item> buildings = game.getBuildings();
|
||||
Map<Item, Integer> grouped = group(buildings);
|
||||
List<Item> keys = grouped.keySet().stream().toList();
|
||||
List<String> 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<Action> 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<Action> actions) {
|
||||
private void actionMenu(Item item, List<Action> actions, int day) {
|
||||
List<String> 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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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!"
|
||||
}
|
||||
Reference in New Issue
Block a user