clean: improve code structure
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user