improved sidebar (ordered and colored)

This commit is contained in:
2025-10-04 16:29:03 +02:00
parent 2fac287e1e
commit 61aa7543be

View File

@@ -84,7 +84,7 @@ class TurtleGame extends StatelessGame {
.forEach(snack -> { .forEach(snack -> {
this.eat(p, snack); this.eat(p, snack);
this.generateNewSnack(); this.generateNewSnack();
if(this.scoreMap.values().stream().mapToInt(Integer::intValue).sum() % 3 == 0) this.generateNewBomb(); if(this.scoreMap.values().stream().mapToInt(Integer::intValue).sum() % 4 == 0) this.generateNewBomb();
}); });
this.bombs.stream() this.bombs.stream()
.filter(bomb -> bomb.getBoundingBox().intersectBox(turtle.getPosition().sub(bomb.getPosition()), turtle.getBoundingBox())) .filter(bomb -> bomb.getBoundingBox().intersectBox(turtle.getPosition().sub(bomb.getPosition()), turtle.getBoundingBox()))
@@ -93,7 +93,9 @@ class TurtleGame extends StatelessGame {
this.explode(p, bomb); this.explode(p, bomb);
this.generateNewBomb(2); this.generateNewBomb(2);
this.speed += this.maxSpeedIncrease / this.getPlayers().size(); this.speed += this.maxSpeedIncrease / this.getPlayers().size();
this.sidebarMap.values().forEach(sidebar -> sidebar.updateLineScore("1", (int) this.speed)); this.sidebarMap.values().forEach(sidebar -> sidebar.updateLineContent("1",
Component.text("Speed: ").color(NamedTextColor.BLUE)
.append(Component.text(String.format("%3d", (int) this.speed)).color(NamedTextColor.RED))));
}); });
} }
} }
@@ -106,7 +108,9 @@ class TurtleGame extends StatelessGame {
this.snacks.remove(snack); this.snacks.remove(snack);
snack.remove(); snack.remove();
this.scoreMap.put(p, this.scoreMap.get(p) + 1); this.scoreMap.put(p, this.scoreMap.get(p) + 1);
this.sidebarMap.get(p).updateLineScore("0", this.scoreMap.get(p)); this.sidebarMap.get(p).updateLineContent("0",
Component.text("Score: ").color(NamedTextColor.GREEN)
.append(Component.text(String.format("%3d", this.scoreMap.get(p))).color(NamedTextColor.RED)));
} }
protected void explode(Player p, Entity bomb) { protected void explode(Player p, Entity bomb) {
@@ -122,7 +126,9 @@ class TurtleGame extends StatelessGame {
this.getScore().insertResult(p, this.scoreMap.get(p)); this.getScore().insertResult(p, this.scoreMap.get(p));
this.bombs.remove(bomb); this.bombs.remove(bomb);
bomb.remove(); bomb.remove();
this.sidebarMap.values().forEach(sidebar -> sidebar.updateLineScore("2", (int) this.turtlePlayerMap.keySet().stream().filter(player -> !player.isFlying()).count())); this.sidebarMap.values().forEach(sidebar -> sidebar.updateLineContent("2",
Component.text("Players: ").color(NamedTextColor.AQUA)
.append(Component.text(String.format("%3d", (int) this.turtlePlayerMap.keySet().stream().filter(player -> !player.isFlying()).count())).color(NamedTextColor.RED))));
} }
@Override @Override
@@ -136,21 +142,29 @@ class TurtleGame extends StatelessGame {
Sidebar sidebar = this.sidebarMap.get(p); Sidebar sidebar = this.sidebarMap.get(p);
sidebar.createLine(new Sidebar.ScoreboardLine( sidebar.createLine(new Sidebar.ScoreboardLine(
"0", "0",
Component.text("Score: ").color(NamedTextColor.DARK_GREEN), Component.text("Score: ").color(NamedTextColor.GREEN)
this.scoreMap.get(p) .append(Component.text(String.format("%3d", this.scoreMap.get(p))).color(NamedTextColor.RED)),
3,
Sidebar.NumberFormat.blank()
)); ));
sidebar.createLine(new Sidebar.ScoreboardLine( sidebar.createLine(new Sidebar.ScoreboardLine(
"1", "1",
Component.text("Speed: ").color(NamedTextColor.DARK_BLUE), Component.text("Speed: ").color(NamedTextColor.BLUE)
(int) this.speed .append(Component.text(String.format("%3d", (int) this.speed)).color(NamedTextColor.RED)),
2,
Sidebar.NumberFormat.blank()
)); ));
sidebar.createLine(new Sidebar.ScoreboardLine( sidebar.createLine(new Sidebar.ScoreboardLine(
"2", "2",
Component.text("Players: ").color(NamedTextColor.AQUA), Component.text("Players: ").color(NamedTextColor.AQUA)
this.turtlePlayerMap.size() .append(Component.text(String.format("%3d", (int) this.turtlePlayerMap.keySet().stream().filter(player -> !player.isFlying()).count())).color(NamedTextColor.RED)),
1,
Sidebar.NumberFormat.blank()
)); ));
sidebar.addViewer(p); sidebar.addViewer(p);
this.sidebarMap.values().forEach(bar -> bar.updateLineScore("2", this.turtlePlayerMap.size())); this.sidebarMap.values().forEach(bar -> bar.updateLineContent("2",
Component.text("Players: ").color(NamedTextColor.AQUA)
.append(Component.text(String.format("%3d", (int) this.turtlePlayerMap.keySet().stream().filter(player -> !player.isFlying()).count())).color(NamedTextColor.RED))));
EntityCreature turtle = this.turtlePlayerMap.get(p); EntityCreature turtle = this.turtlePlayerMap.get(p);
MinecraftServer.getSchedulerManager().scheduleNextTick(() -> { MinecraftServer.getSchedulerManager().scheduleNextTick(() -> {