feat: events
This commit is contained in:
@@ -10,9 +10,12 @@ import cz.jull.tui.Cli;
|
||||
import cz.jull.tui.Menu;
|
||||
import cz.jull.tui.Strings;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.w3c.dom.events.Event;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@Getter
|
||||
public class Game {
|
||||
@@ -29,7 +32,8 @@ public class Game {
|
||||
|
||||
private final Strings strings;
|
||||
|
||||
private final List<Item> buildings = new ArrayList<>();
|
||||
@Setter
|
||||
private List<Item> buildings = new ArrayList<>();
|
||||
|
||||
private Market market;
|
||||
|
||||
@@ -37,10 +41,18 @@ public class Game {
|
||||
|
||||
private int milkedToday = 0;
|
||||
|
||||
private Events currentEvent;
|
||||
|
||||
public Game(Strings strings) {
|
||||
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();
|
||||
@@ -48,6 +60,10 @@ public class Game {
|
||||
Menu menu = new Menu(this);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
currentEvent = getRandomEvent();
|
||||
strings.print("event", currentEvent);
|
||||
currentEvent.getAction().accept(this);
|
||||
|
||||
menu.start(i);
|
||||
long wheatSeedsCount = buildings.stream().filter(item -> item == Item.WHEAT_SEEDS).count();
|
||||
for (int j = 0; j < wheatSeedsCount; j++) {
|
||||
|
||||
@@ -1,8 +1,45 @@
|
||||
package cz.jull.stats;
|
||||
|
||||
import cz.jull.Game;
|
||||
import cz.jull.Item;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public enum Events {
|
||||
PEACEFUL_ROUND,
|
||||
FLOOD,
|
||||
ATTACK,
|
||||
FIRE
|
||||
PEACEFUL_ROUND("Peaceful round. enjoy!", game -> {
|
||||
}),
|
||||
FLOOD("Flood", game -> {
|
||||
game.getStrings().print("eventFlood");
|
||||
game.setBuildings(new ArrayList<>(
|
||||
game.getBuildings().stream().filter(
|
||||
building -> !List.of(Item.WHEAT_FARMLAND, Item.HOPS_FARMLAND, Item.VINEYARD).contains(building)
|
||||
).toList())
|
||||
);
|
||||
}),
|
||||
ATTACK("Attack", game -> {
|
||||
game.getStrings().print("eventAttack");
|
||||
game.getPlayer().setCoins(game.getPlayer().getCoins() - 100);
|
||||
}),
|
||||
FIRE("Fire", game -> {
|
||||
game.getStrings().print("eventFire");
|
||||
game.getForestType().setSize(game.getForestType().getSize() - 10);
|
||||
});
|
||||
|
||||
private final String name;
|
||||
|
||||
@Getter
|
||||
private final Consumer<Game> action;
|
||||
|
||||
Events(String name, Consumer<Game> action) {
|
||||
this.name = name;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public class Cli {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
int choice;
|
||||
|
||||
System.out.println();
|
||||
System.out.println("Chose an option: ");
|
||||
for (int i = 0; i < options.size(); i++) {
|
||||
System.out.println((i + 1) + ". " + options.get(i));
|
||||
|
||||
@@ -41,6 +41,10 @@ public class Strings {
|
||||
private String currentDay;
|
||||
private String cantMilkToMuch;
|
||||
private String noTrees;
|
||||
private String event;
|
||||
private String eventFire;
|
||||
private String eventFlood;
|
||||
private String eventAttack;
|
||||
|
||||
/**
|
||||
* Loads strings from json file
|
||||
@@ -53,6 +57,7 @@ public class Strings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated AI
|
||||
* Prints out a String based on the prop
|
||||
* @param prop The name of the field
|
||||
*/
|
||||
@@ -68,6 +73,7 @@ public class Strings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generated AI
|
||||
* Prints out a template with string inserted based on the prop
|
||||
* @param prop The name of the field
|
||||
* @param values Values for the template
|
||||
|
||||
Reference in New Issue
Block a user