feat: events
This commit is contained in:
@@ -47,12 +47,6 @@ public class Game {
|
||||
this.strings = strings;
|
||||
}
|
||||
|
||||
private Events getRandomEvent() {
|
||||
Random random = new Random();
|
||||
|
||||
return events.get(random.nextInt(events.size()));
|
||||
}
|
||||
|
||||
public void play() {
|
||||
strings.print("welcome");
|
||||
Cli.pressEnter();
|
||||
@@ -60,11 +54,27 @@ public class Game {
|
||||
Menu menu = new Menu(this);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
strings.print("currentDay", i + 1);
|
||||
|
||||
currentEvent = getRandomEvent();
|
||||
strings.print("event", currentEvent);
|
||||
currentEvent.getAction().accept(this);
|
||||
|
||||
// The event can happen only once
|
||||
if (currentEvent == Events.FIRE) {
|
||||
events.remove(Events.FIRE);
|
||||
}
|
||||
|
||||
if (currentEvent == Events.FLOOD) {
|
||||
events.remove(Events.FLOOD);
|
||||
}
|
||||
|
||||
if (currentEvent == Events.ATTACK) {
|
||||
events.remove(Events.ATTACK);
|
||||
}
|
||||
|
||||
menu.start(i);
|
||||
|
||||
long wheatSeedsCount = buildings.stream().filter(item -> item == Item.WHEAT_SEEDS).count();
|
||||
for (int j = 0; j < wheatSeedsCount; j++) {
|
||||
buildings.remove(Item.WHEAT_SEEDS);
|
||||
@@ -82,6 +92,7 @@ public class Game {
|
||||
buildings.remove(Item.GRAPEVINE_SEEDS);
|
||||
buildings.add(Item.GRAPEVINE);
|
||||
}
|
||||
|
||||
milkedToday = 0;
|
||||
}
|
||||
}
|
||||
@@ -124,6 +135,12 @@ public class Game {
|
||||
Cli.pressEnter();
|
||||
}
|
||||
|
||||
private Events getRandomEvent() {
|
||||
Random random = new Random();
|
||||
|
||||
return events.get(random.nextInt(events.size()));
|
||||
}
|
||||
|
||||
public void build(Item item) {
|
||||
if (!player.getInventory().contains(item)) {
|
||||
strings.print("cantBuild");
|
||||
|
||||
@@ -132,7 +132,6 @@ public class Menu {
|
||||
System.out.println();
|
||||
}
|
||||
case 4 -> {
|
||||
game.getStrings().print("currentDay", day + 2);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user