chore: testing all methods again
This commit is contained in:
@@ -29,7 +29,7 @@ public class Game {
|
||||
private final List<Item> buildings = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
private final Market market = new Market(this);
|
||||
private Market market;
|
||||
|
||||
public void generateStats() {
|
||||
forestType = ForestType.getRandom();
|
||||
@@ -45,6 +45,8 @@ public class Game {
|
||||
buildings.add(Item.WELL);
|
||||
}
|
||||
player.setCoins(1000);
|
||||
|
||||
market = new Market(this);
|
||||
}
|
||||
|
||||
public void build(Item item) {
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.util.function.Function;
|
||||
|
||||
public enum Item implements Buildable {
|
||||
AXE("Axe", false, 5),
|
||||
SCYTHE("Scythe", false, 5),
|
||||
|
||||
WHEAT("Wheat", false, 0),
|
||||
HOPS("Hops", false, 0),
|
||||
@@ -112,7 +111,7 @@ public enum Item implements Buildable {
|
||||
};
|
||||
|
||||
BAKERY.canBeBuiltFunction = game -> {
|
||||
if (!game.getBuildings().contains(Item.WHEAT_SEEDS)) {
|
||||
if (!game.getBuildings().contains(Item.WHEAT_FARMLAND)) {
|
||||
System.out.println(" "); // TODO
|
||||
return false;
|
||||
}
|
||||
@@ -120,7 +119,7 @@ public enum Item implements Buildable {
|
||||
};
|
||||
|
||||
PUB.canBeBuiltFunction = game -> {
|
||||
if (!game.getBuildings().contains(Item.HOPS_SEEDS)) {
|
||||
if (!game.getBuildings().contains(Item.HOPS_FARMLAND)) {
|
||||
System.out.println(" "); // TODO
|
||||
return false;
|
||||
}
|
||||
@@ -128,7 +127,7 @@ public enum Item implements Buildable {
|
||||
};
|
||||
|
||||
WINERY.canBeBuiltFunction = game -> {
|
||||
if (!game.getBuildings().contains(Item.GRAPEVINE_SEEDS)) {
|
||||
if (!game.getBuildings().contains(Item.VINEYARD)) {
|
||||
System.out.println(" "); // TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ public class Main {
|
||||
} catch (ItemNotAvailableException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
System.out.println("coins: " + game.getPlayer().getCoins());
|
||||
System.out.println("inventory: " + game.getPlayer().getInventory());
|
||||
System.out.println();
|
||||
@@ -95,6 +96,13 @@ public class Main {
|
||||
System.out.println("buildings: " + game.getBuildings());
|
||||
System.out.println();
|
||||
|
||||
game.build(Item.BAKERY);
|
||||
|
||||
System.out.println("coins: " + game.getPlayer().getCoins());
|
||||
System.out.println("inventory: " + game.getPlayer().getInventory());
|
||||
System.out.println("buildings: " + game.getBuildings());
|
||||
System.out.println();
|
||||
|
||||
game.produce(Item.BAKERY);
|
||||
|
||||
System.out.println("coins: " + game.getPlayer().getCoins());
|
||||
@@ -102,6 +110,68 @@ public class Main {
|
||||
System.out.println("buildings: " + game.getBuildings());
|
||||
System.out.println();
|
||||
|
||||
try {
|
||||
game.getMarket().buyItem(game, Item.AXE);
|
||||
|
||||
} catch (ItemNotAvailableException e) {
|
||||
System.out.println(" idk ");;
|
||||
}
|
||||
|
||||
System.out.println("coins: " + game.getPlayer().getCoins());
|
||||
System.out.println("inventory: " + game.getPlayer().getInventory());
|
||||
System.out.println("buildings: " + game.getBuildings());
|
||||
System.out.println();
|
||||
|
||||
game.cutTrees();
|
||||
|
||||
System.out.println("coins: " + game.getPlayer().getCoins());
|
||||
System.out.println("inventory: " + game.getPlayer().getInventory());
|
||||
System.out.println("buildings: " + game.getBuildings());
|
||||
System.out.println();
|
||||
|
||||
try {
|
||||
game.getMarket().buyItem(game, Item.COAL_FACTORY);
|
||||
|
||||
} catch (ItemNotAvailableException e) {
|
||||
System.out.println(" idk ");;
|
||||
}
|
||||
|
||||
System.out.println("coins: " + game.getPlayer().getCoins());
|
||||
System.out.println("inventory: " + game.getPlayer().getInventory());
|
||||
System.out.println("buildings: " + game.getBuildings());
|
||||
System.out.println();
|
||||
|
||||
game.build(Item.COAL_FACTORY);
|
||||
|
||||
System.out.println("coins: " + game.getPlayer().getCoins());
|
||||
System.out.println("inventory: " + game.getPlayer().getInventory());
|
||||
System.out.println("buildings: " + game.getBuildings());
|
||||
System.out.println();
|
||||
|
||||
game.produce(Item.COAL_FACTORY);
|
||||
|
||||
System.out.println("coins: " + game.getPlayer().getCoins());
|
||||
System.out.println("inventory: " + game.getPlayer().getInventory());
|
||||
System.out.println("buildings: " + game.getBuildings());
|
||||
System.out.println();
|
||||
|
||||
try {
|
||||
game.getMarket().buyItem(game, Item.COAL_FACTORY);
|
||||
|
||||
} catch (ItemNotAvailableException e) {
|
||||
System.out.println(" idk ");;
|
||||
}
|
||||
|
||||
System.out.println("coins: " + game.getPlayer().getCoins());
|
||||
System.out.println("inventory: " + game.getPlayer().getInventory());
|
||||
System.out.println("buildings: " + game.getBuildings());
|
||||
System.out.println();
|
||||
|
||||
game.getMarket().sellItem(game, Item.COAL_FACTORY);
|
||||
|
||||
System.out.println("coins: " + game.getPlayer().getCoins());
|
||||
System.out.println("inventory: " + game.getPlayer().getInventory());
|
||||
System.out.println("buildings: " + game.getBuildings());
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,18 @@ import java.util.List;
|
||||
|
||||
public class Market {
|
||||
private final List<Item> availableItems = new ArrayList<>(List.of(
|
||||
Item.AXE, Item.SCYTHE,
|
||||
Item.AXE,
|
||||
Item.VILLAGER_HOUSE, Item.CHURCH
|
||||
));
|
||||
|
||||
public void sellItem(Player player, Item item) {
|
||||
player.setCoins(player.getCoins() + item.getPrice());
|
||||
player.getInventory().remove(item);
|
||||
public void sellItem(Game game, Item item) {
|
||||
if (!game.getPlayer().getInventory().contains(item)) {
|
||||
System.out.println(" "); // TODO
|
||||
return;
|
||||
}
|
||||
|
||||
game.getPlayer().setCoins(game.getPlayer().getCoins() + item.getPrice());
|
||||
game.getPlayer().getInventory().remove(item);
|
||||
}
|
||||
|
||||
public void buyItem(Game game, Item item) throws ItemNotAvailableException, NotSufficientsCoinsException {
|
||||
@@ -32,6 +37,7 @@ public class Market {
|
||||
System.out.println(" "); //TODO
|
||||
return;
|
||||
}
|
||||
System.out.println(availableItems);
|
||||
if (availableItems.contains(item)) {
|
||||
game.getPlayer().getInventory().add(item);
|
||||
game.getPlayer().setCoins(game.getPlayer().getCoins() - item.getPrice());
|
||||
|
||||
Reference in New Issue
Block a user