clean: improve code structure

This commit is contained in:
Martin Prokoph
2025-08-01 16:51:14 +02:00
parent 7ef6e246ff
commit 4d175761a5
3 changed files with 17 additions and 19 deletions

View File

@@ -45,16 +45,7 @@ public class Tetris {
SoundUtil.playMusic("/music/theme.wav", true);
space.spawnTetromino();
startTime = LocalTime.now();
gravityTask = new TimerTask() {
@Override
public void run() {
if (space.getCurrentTetromino() != null) {
updateTime();
space.getCurrentTetromino().fall();
ui.getGamePanel().repaint();
}
}
};
gravityTask = new GravityTimerTask();
timer.scheduleAtFixedRate(gravityTask, 1, Settings.difficulty.getTimerPeriod());
}
@@ -72,4 +63,15 @@ public class Tetris {
public static void updateTime() {
if (ui.getMenuPanel() instanceof ScoreMenu) ((ScoreMenu) ui.getMenuPanel()).updateTime(startTime);
}
public static class GravityTimerTask extends TimerTask {
@Override
public void run() {
if (space.getCurrentTetromino() != null) {
updateTime();
space.getCurrentTetromino().fall();
ui.getGamePanel().repaint();
}
}
}
}