feat: add timer for automatically falling pieces
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user