fix: coins
This commit is contained in:
@@ -36,6 +36,9 @@ public class Market {
|
||||
|
||||
if (availableItems.contains(item)) {
|
||||
if (List.of(Item.WHEAT_SEEDS, Item.HOPS_SEEDS, Item.GRAPEVINE_SEEDS, Item.WHEAT_FARMLAND, Item.HOPS_FARMLAND, Item.VINEYARD).contains(item)) {
|
||||
if (game.getPlayer().getCoins() < (long) item.getPrice() * game.getWaterType().getFarmlandAndVineyardCount()) {
|
||||
throw new NotSufficientsCoinsException("Not enough coins, you need " + game.getWaterType().getFarmlandAndVineyardCount() * item.getPrice() + " coins");
|
||||
}
|
||||
for (int i = 0; i < game.getWaterType().getFarmlandAndVineyardCount() ; i++) {
|
||||
game.getPlayer().getInventory().add(item);
|
||||
game.getPlayer().setCoins(game.getPlayer().getCoins() - item.getPrice());
|
||||
|
||||
@@ -93,13 +93,15 @@ public class Menu {
|
||||
switch (marketOption) {
|
||||
case 0 -> {
|
||||
game.getStrings().print("marketBuy");
|
||||
System.out.println();
|
||||
game.getStrings().print("coins", game.getPlayer().getCoins());
|
||||
List<String> availableItems = game.getMarket().getAvailableItems().stream().map(item -> item + ": " + "\u001B[0;33m" + item.getPrice() + " Coins\u001B[0m").toList();
|
||||
int itemIndex = Cli.selectOptionIndex(availableItems);
|
||||
Item item = game.getMarket().getAvailableItems().get(itemIndex);
|
||||
try {
|
||||
game.getMarket().buyItem(game, item);
|
||||
} catch (NotSufficientsCoinsException | ItemNotAvailableException e) {
|
||||
System.out.println("Error: " + e.getMessage());
|
||||
System.out.println("\033[4;31mError: " + e.getMessage() + "\033[0m");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user