Merge pull request 'added second option to game selection menu, finished stickfight(added timer to stick fight)' (#9) from develop-jannis into develop

Reviewed-on: #9
Reviewed-by: Elias Müller <elias@elias-mueller.com>
This commit was merged in pull request #9.
This commit is contained in:
2026-01-11 19:07:05 +00:00
2 changed files with 11 additions and 3 deletions

View File

@@ -28,7 +28,8 @@ public class StickFightFactory implements GameFactory {
@Override
public ConfigManager configuration() {
return new ConfigManager()
.addOption(new NumericOption("length", Material.SANDSTONE, TranslatedComponent.byId("optionCommon#length"), 7, 10, 13, 16, 19));
.addOption(new NumericOption("length", Material.SANDSTONE, TranslatedComponent.byId("optionCommon#length"), 7, 10, 13, 16, 19))
.addOption(new NumericOption("seconds", Material.CLOCK, TranslatedComponent.byId("optionCommon#seconds"), 30, 60, 90, 120));
}
@Override
@@ -40,7 +41,7 @@ public class StickFightFactory implements GameFactory {
@Override
public Game manufacture(Room parent, Map<String, Option<?>> configuration) {
return new Stickfight(configuration.get("length").getAsInt()).setParent(parent);
return new Stickfight(configuration.get("length").getAsInt(), configuration.get("seconds").getAsInt()).setParent(parent);
}
@Override

View File

@@ -24,10 +24,12 @@ public class Stickfight extends StatelessGame {
private final WeakHashMap<Player, Pos> spawnPoints = new WeakHashMap<>();
private final Map<Player, Integer> scoreMap = new WeakHashMap<>();
private boolean countdownStarted = false;
private final int seconds;
public Stickfight(int length) {
public Stickfight(int length, int seconds) {
super(Dimension.OVERWORLD.key, "Stickfight", new LowestPointsWinScore());
this.radius = length;
this.seconds = seconds;
this.eventNode().addChild(
CombatFeatures.empty()
@@ -88,6 +90,11 @@ public class Stickfight extends StatelessGame {
super.start();
}
@Override
protected void onStart() {
this.setTimeLimit(this.seconds);
}
@Override
protected void onStop() {
this.scoreMap.forEach((player, score) -> this.getScore().insertResult(player, score));