Finalized ColorJump #13

Merged
jannis merged 6 commits from develop-jannis into develop 2026-07-15 16:15:14 +00:00
Showing only changes of commit 410f7b4027 - Show all commits
@@ -32,6 +32,7 @@ public class ColorJump extends StatelessGame {
Block.PINK_CONCRETE Block.PINK_CONCRETE
); );
private Block currentBlock; private Block currentBlock;
private Block blockLastRound;
private double roundTime = 5; private double roundTime = 5;
private final double multiplierNextRoundTime = 0.9; private final double multiplierNextRoundTime = 0.9;
@@ -56,6 +57,8 @@ public class ColorJump extends StatelessGame {
this.generate(); this.generate();
this.currentBlock = this.blocks.get(ThreadLocalRandom.current().nextInt(this.blocks.size())); this.currentBlock = this.blocks.get(ThreadLocalRandom.current().nextInt(this.blocks.size()));
if(this.currentBlock == this.blockLastRound) this.nextRound();
this.blockLastRound = this.currentBlock;
ItemStack item = ItemStack.of(Objects.requireNonNull(this.currentBlock.registry().material())); ItemStack item = ItemStack.of(Objects.requireNonNull(this.currentBlock.registry().material()));
this.getPlayers().forEach(player -> { this.getPlayers().forEach(player -> {
player.getInventory().clear(); player.getInventory().clear();
@@ -80,15 +83,31 @@ public class ColorJump extends StatelessGame {
if(this.roundTime > 0.5) if(this.roundTime > 0.5)
this.roundTime = this.roundTime * this.multiplierNextRoundTime; this.roundTime = this.roundTime * this.multiplierNextRoundTime;
long secondsLeft = Math.max(0, (long) this.roundTime); long totalMillis = (long) (this.roundTime * 1000);
long startTime = System.currentTimeMillis();
for (int i = Math.min(3, (int) secondsLeft); i >= 0; i--) { scheduler.scheduleTask(() -> {
int level = i; if (!this.isRunning) return stop;
scheduler.scheduleTask(() -> {
this.getPlayers().forEach(player -> player.setLevel(level)); long elapsed = System.currentTimeMillis() - startTime;
long remaining = totalMillis - elapsed;
if (remaining <= 0) {
this.getPlayers().forEach(player -> {
player.setExp(0f);
player.setLevel(0);
});
return stop; return stop;
MineTec marked this conversation as resolved
Review

andere Lösung für das effective-final wär schön

andere Lösung für das effective-final wär schön
Review

passt so?

passt so?
}, TaskSchedule.seconds(secondsLeft-i)); }
}
float progress = (float) remaining / totalMillis;
this.getPlayers().forEach(player -> {
player.setExp(progress);
player.setLevel((int) Math.ceil(remaining / 1000.0));
});
return TaskSchedule.millis(50); // 1 Tick (20 TPS)
}, TaskSchedule.millis(0));
} }
private void generate() { private void generate() {