feat: add timer for automatically falling pieces

This commit is contained in:
Martin Prokoph
2025-06-27 23:33:43 +02:00
parent b1be4e0731
commit 2ca0fcfd86
2 changed files with 19 additions and 3 deletions

View File

@@ -5,6 +5,8 @@ import eu.midnightdust.yaytris.ui.TetrisUI;
import javax.swing.*;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
public class Tetris {
public static final Random random = new Random();
@@ -19,5 +21,15 @@ public class Tetris {
Settings.load();
space = new Space();
ui = new TetrisUI();
Timer timer = new Timer("Tetris falling pieces");
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
if (Tetris.space.getCurrentTetromino() != null) {
Tetris.space.getCurrentTetromino().fall(1);
Tetris.ui.getGamePanel().repaint();
}
}
}, 50, 1000);
}
}