fix: Fixed some stuff
This commit is contained in:
@@ -113,7 +113,7 @@ public class Game {
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
player.setCoins(1000);
|
||||
player.setCoins(300);
|
||||
strings.print("coins", player.getCoins());
|
||||
System.out.println();
|
||||
|
||||
@@ -230,51 +230,23 @@ public class Game {
|
||||
}
|
||||
|
||||
public void produce(Item item) {
|
||||
long bakeryProducedMoney;
|
||||
long pubProducedMoney;
|
||||
long wineryProducedMoney;
|
||||
long coalFactoryProducedMoney;
|
||||
long cheeseFactoryProducedMoney;
|
||||
|
||||
if (!buildings.contains(item)) {
|
||||
strings.print("cantProduce", item);
|
||||
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 -> {
|
||||
long hopsSum = player.getInventory().stream().filter(item1 -> item1 == Item.HOPS).count();
|
||||
player.getInventory().removeIf(i -> i == Item.HOPS);
|
||||
pubProducedMoney = (hopsSum * item.getPrice()/2);
|
||||
player.setCoins(player.getCoins() + pubProducedMoney);
|
||||
}
|
||||
Item productItem = switch (item) {
|
||||
case BAKERY -> Item.WHEAT;
|
||||
case PUB -> Item.HOPS;
|
||||
case WINERY -> Item.GRAPEVINE;
|
||||
case COAL_FACTORY -> Item.WOOD;
|
||||
case CHEESE_FACTORY -> Item.MILK;
|
||||
default -> throw new IllegalArgumentException("Error: " + item + " can't produce anything.");
|
||||
};
|
||||
|
||||
case WINERY -> {
|
||||
long grapevineSum = player.getInventory().stream().filter(item1 -> item1 == Item.GRAPEVINE).count();
|
||||
player.getInventory().removeIf(i -> i == Item.GRAPEVINE);
|
||||
wineryProducedMoney = (grapevineSum * item.getPrice()/2);
|
||||
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);
|
||||
}
|
||||
}
|
||||
long sum = player.getInventory().stream().filter(item1 -> item1 == productItem).count();
|
||||
player.getInventory().removeIf(i -> i == productItem);
|
||||
long producedMoney = (sum * item.getPrice()/2);
|
||||
player.setCoins(player.getCoins() + producedMoney);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ public enum Item implements Buildable {
|
||||
WHEAT("Wheat", false, 0, List.of()),
|
||||
HOPS("Hops", false, 0, List.of()),
|
||||
GRAPEVINE("Grapes", false, 0, List.of()),
|
||||
WOOD("Wood", false, 0, List.of()),
|
||||
MILK("Milk", false, 0, List.of()),
|
||||
WOOD("Wood", false, 10, List.of()),
|
||||
MILK("Milk", false, 15, List.of()),
|
||||
|
||||
WHEAT_SEEDS("Wheat 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()),
|
||||
|
||||
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 {
|
||||
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 -> {
|
||||
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;
|
||||
|
||||
@@ -45,6 +45,10 @@ public class Market {
|
||||
game.getPlayer().setCoins(game.getPlayer().getCoins() - item.getPrice());
|
||||
}
|
||||
game.getStrings().print("marketBuyMessage", item);
|
||||
|
||||
if (List.of(Item.WHEAT_FARMLAND, Item.HOPS_FARMLAND, Item.VINEYARD).contains(item)) {
|
||||
availableItems.remove(item);
|
||||
}
|
||||
} else {
|
||||
throw new ItemNotAvailableException("Item is not available");
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public class Strings {
|
||||
private String eventFire;
|
||||
private String eventFlood;
|
||||
private String eventAttack;
|
||||
private String noVillagerHouseMessage;
|
||||
|
||||
/**
|
||||
* Loads strings from json file
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
"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!",
|
||||
"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!",
|
||||
"cantCutTrees": "You need {0} axes to cut trees!",
|
||||
"cantMilkCows": "You don`t own any cows!",
|
||||
|
||||
Reference in New Issue
Block a user