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