fix: Fixed some stuff

This commit is contained in:
2025-05-28 14:49:46 +02:00
parent 755f936b5a
commit 70d41b7aee
5 changed files with 46 additions and 44 deletions

View File

@@ -113,7 +113,7 @@ public class Game {
} }
System.out.println(); System.out.println();
player.setCoins(1000); player.setCoins(300);
strings.print("coins", player.getCoins()); strings.print("coins", player.getCoins());
System.out.println(); System.out.println();
@@ -230,51 +230,23 @@ public class Game {
} }
public void produce(Item item) { public void produce(Item item) {
long bakeryProducedMoney;
long pubProducedMoney;
long wineryProducedMoney;
long coalFactoryProducedMoney;
long cheeseFactoryProducedMoney;
if (!buildings.contains(item)) { if (!buildings.contains(item)) {
strings.print("cantProduce", item); strings.print("cantProduce", item);
return; return;
} }
switch (item) {
case BAKERY -> {
long wheatSum = player.getInventory().stream().filter(item1 -> item1 == Item.WHEAT).count();
player.getInventory().removeIf(i -> i == Item.WHEAT);
bakeryProducedMoney = (wheatSum * item.getPrice()/2);
player.setCoins(player.getCoins() + bakeryProducedMoney);
}
case PUB -> { Item productItem = switch (item) {
long hopsSum = player.getInventory().stream().filter(item1 -> item1 == Item.HOPS).count(); case BAKERY -> Item.WHEAT;
player.getInventory().removeIf(i -> i == Item.HOPS); case PUB -> Item.HOPS;
pubProducedMoney = (hopsSum * item.getPrice()/2); case WINERY -> Item.GRAPEVINE;
player.setCoins(player.getCoins() + pubProducedMoney); case COAL_FACTORY -> Item.WOOD;
} case CHEESE_FACTORY -> Item.MILK;
default -> throw new IllegalArgumentException("Error: " + item + " can't produce anything.");
};
case WINERY -> { long sum = player.getInventory().stream().filter(item1 -> item1 == productItem).count();
long grapevineSum = player.getInventory().stream().filter(item1 -> item1 == Item.GRAPEVINE).count(); player.getInventory().removeIf(i -> i == productItem);
player.getInventory().removeIf(i -> i == Item.GRAPEVINE); long producedMoney = (sum * item.getPrice()/2);
wineryProducedMoney = (grapevineSum * item.getPrice()/2); player.setCoins(player.getCoins() + producedMoney);
player.setCoins(player.getCoins() + wineryProducedMoney);
}
case COAL_FACTORY -> {
long woodSum = player.getInventory().stream().filter(item1 -> item1 == Item.WOOD).count();
player.getInventory().remove(Item.WOOD);
coalFactoryProducedMoney = (woodSum * item.getPrice()/2);
player.setCoins(player.getCoins() + coalFactoryProducedMoney);
}
case CHEESE_FACTORY -> {
long milkSum = player.getInventory().stream().filter(item1 -> item1 == Item.MILK).count();
player.getInventory().remove(Item.MILK);
cheeseFactoryProducedMoney = (milkSum * item.getPrice()/2);
player.setCoins(player.getCoins() + cheeseFactoryProducedMoney);
}
}
} }
} }

View File

@@ -34,8 +34,8 @@ public enum Item implements Buildable {
WHEAT("Wheat", false, 0, List.of()), WHEAT("Wheat", false, 0, List.of()),
HOPS("Hops", false, 0, List.of()), HOPS("Hops", false, 0, List.of()),
GRAPEVINE("Grapes", false, 0, List.of()), GRAPEVINE("Grapes", false, 0, List.of()),
WOOD("Wood", false, 0, List.of()), WOOD("Wood", false, 10, List.of()),
MILK("Milk", false, 0, List.of()), MILK("Milk", false, 15, List.of()),
WHEAT_SEEDS("Wheat seeds", true, 5, List.of()), WHEAT_SEEDS("Wheat seeds", true, 5, List.of()),
HOPS_SEEDS("Hops seeds", true, 5, List.of()), HOPS_SEEDS("Hops seeds", true, 5, List.of()),
@@ -57,10 +57,34 @@ public enum Item implements Buildable {
WELL("Well", true, 30, List.of()), WELL("Well", true, 30, List.of()),
COAL_FACTORY("Coal factory", true, 200, List.of(new BuildAction()), List.of(new CoalFactoryProduceAction())), COAL_FACTORY("Coal factory", true, 200, List.of(new BuildAction()), List.of(new CoalFactoryProduceAction())),
CHEESE_FACTORY("Cheese factory", true, 200, List.of(new BuildAction()), List.of(new CheeseFactoryProduceAction())),; CHEESE_FACTORY("Cheese factory", true, 150, List.of(new BuildAction()), List.of(new CheeseFactoryProduceAction())),;
static { static {
WHEAT_FARMLAND.canBeBuiltFunction = game -> {
if (game.getBuildings().contains(Item.VILLAGER_HOUSE)) {
return true;
}
game.getStrings().print("noVillagerHouseMessage");
return false;
};
HOPS_FARMLAND.canBeBuiltFunction = game -> {
if (game.getBuildings().contains(Item.VILLAGER_HOUSE)) {
return true;
}
game.getStrings().print("noVillagerHouseMessage");
return false;
};
VINEYARD.canBeBuiltFunction = game -> {
if (game.getBuildings().contains(Item.VILLAGER_HOUSE)) {
return true;
}
game.getStrings().print("noVillagerHouseMessage");
return false;
};
FENCE_WITH_COWS.canBeBuiltFunction = game -> { FENCE_WITH_COWS.canBeBuiltFunction = 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) { 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; return true;

View File

@@ -45,6 +45,10 @@ public class Market {
game.getPlayer().setCoins(game.getPlayer().getCoins() - item.getPrice()); game.getPlayer().setCoins(game.getPlayer().getCoins() - item.getPrice());
} }
game.getStrings().print("marketBuyMessage", item); game.getStrings().print("marketBuyMessage", item);
if (List.of(Item.WHEAT_FARMLAND, Item.HOPS_FARMLAND, Item.VINEYARD).contains(item)) {
availableItems.remove(item);
}
} else { } else {
throw new ItemNotAvailableException("Item is not available"); throw new ItemNotAvailableException("Item is not available");
} }

View File

@@ -45,6 +45,7 @@ public class Strings {
private String eventFire; private String eventFire;
private String eventFlood; private String eventFlood;
private String eventAttack; private String eventAttack;
private String noVillagerHouseMessage;
/** /**
* Loads strings from json file * Loads strings from json file

View File

@@ -17,6 +17,7 @@
"cantBeBuiltPub": "First you need to built hops farmland before a pub! You need hops you know!", "cantBeBuiltPub": "First you need to built hops farmland before a pub! You need hops you know!",
"cantBeBuiltWinery": "First you need to built vineyard before a winery! You need grapevines you know!", "cantBeBuiltWinery": "First you need to built vineyard before a winery! You need grapevines you know!",
"cantBeBuiltCheeseFactory": "First you need to own cows before a cheese factory! You need milk you know!", "cantBeBuiltCheeseFactory": "First you need to own cows before a cheese factory! You need milk you know!",
"noVillagerHouseMessage": "Build a villager house first!",
"cantBuild": "You don`t have that item in your inventory!", "cantBuild": "You don`t have that item in your inventory!",
"cantCutTrees": "You need {0} axes to cut trees!", "cantCutTrees": "You need {0} axes to cut trees!",
"cantMilkCows": "You don`t own any cows!", "cantMilkCows": "You don`t own any cows!",