feat: added method for producing
This commit is contained in:
@@ -39,8 +39,7 @@ public class Game {
|
|||||||
if (waterType == WaterType.WELL) {
|
if (waterType == WaterType.WELL) {
|
||||||
buildings.add(Item.WELL);
|
buildings.add(Item.WELL);
|
||||||
}
|
}
|
||||||
|
player.setCoins(1000);
|
||||||
player.setCoins(10000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void build(Item item) {
|
public void build(Item item) {
|
||||||
@@ -87,15 +86,51 @@ public class Game {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void milkCow() {
|
||||||
|
player.getInventory().add(Item.MILK);
|
||||||
|
}
|
||||||
|
|
||||||
public void produce(Item item) {
|
public void produce(Item item) {
|
||||||
int bakeryProducedMoney = 0;
|
long bakeryProducedMoney = 0;
|
||||||
int pubProducedMoney = 0;
|
long pubProducedMoney = 0;
|
||||||
int wineryProducedMoney = 0;
|
long wineryProducedMoney = 0;
|
||||||
|
long coalFactoryProducedMoney = 0;
|
||||||
|
long cheeseFactoryProducedMoney = 0;
|
||||||
|
|
||||||
switch (item) {
|
switch (item) {
|
||||||
case BAKERY -> {
|
case BAKERY -> {
|
||||||
|
long wheatSum = player.getInventory().stream().filter(item1 -> item1 == Item.WHEAT).count();
|
||||||
player.getInventory().remove(Item.WHEAT);
|
player.getInventory().remove(Item.WHEAT);
|
||||||
// TODO dodelat ostatni factories a vymyslet logiku na delani penez tak ze to bude brat kolik harvestnul napr obili a pote to nejak vynasobit a to budou money
|
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().remove(Item.HOPS);
|
||||||
|
pubProducedMoney = (hopsSum * item.getPrice()/2);
|
||||||
|
player.setCoins(player.getCoins() + pubProducedMoney);
|
||||||
|
}
|
||||||
|
|
||||||
|
case WINERY -> {
|
||||||
|
long grapevineSum = player.getInventory().stream().filter(item1 -> item1 == Item.GRAPEVINE).count();
|
||||||
|
player.getInventory().remove(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,6 +168,7 @@ public enum Item implements Buildable {
|
|||||||
|
|
||||||
private final boolean isPLaceable;
|
private final boolean isPLaceable;
|
||||||
|
|
||||||
|
@Getter
|
||||||
private final int price;
|
private final int price;
|
||||||
|
|
||||||
private Function<Game, Boolean> function;
|
private Function<Game, Boolean> function;
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import java.util.List;
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class Player {
|
public class Player {
|
||||||
private int coins;
|
private long coins;
|
||||||
|
|
||||||
private List<Item> inventory = new ArrayList<>();
|
private List<Item> inventory = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,17 +16,15 @@ public class Market {
|
|||||||
Item.VILLAGER_HOUSE, Item.CHURCH
|
Item.VILLAGER_HOUSE, Item.CHURCH
|
||||||
));
|
));
|
||||||
|
|
||||||
private void play() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sellItem(Player player, Item item) {
|
public void sellItem(Player player, Item item) {
|
||||||
|
player.setCoins(player.getCoins() + item.getPrice());
|
||||||
player.getInventory().remove(item);
|
player.getInventory().remove(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void buyItem(Game game, Item item) throws Exception {
|
public void buyItem(Game game, Item item) throws Exception {
|
||||||
if (availableItems.contains(item)) {
|
if (availableItems.contains(item)) {
|
||||||
game.getPlayer().getInventory().add(item);
|
game.getPlayer().getInventory().add(item);
|
||||||
|
game.getPlayer().setCoins(game.getPlayer().getCoins() - item.getPrice());
|
||||||
} else {
|
} else {
|
||||||
if (item == Item.WHEAT_SEEDS) {
|
if (item == Item.WHEAT_SEEDS) {
|
||||||
for (int i = 0; i < game.getWaterType().getFarmlandAndVineyardCount() ; i++) {
|
for (int i = 0; i < game.getWaterType().getFarmlandAndVineyardCount() ; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user