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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +49,11 @@ public class Space {
|
||||
Color[][] tempGameMap = new Color[gameMap.length][gameMap[0].length];
|
||||
for (int y = 0; y < tempGameMap.length; y++) {
|
||||
System.arraycopy(gameMap[y], 0, tempGameMap[y], 0, tempGameMap[y].length);
|
||||
if (currentTetromino != null) {
|
||||
Color[] newBlobs = currentTetromino.getLine(y);
|
||||
for (int i = 0; i < newBlobs.length; i++) {
|
||||
if (newBlobs[i] == null) continue;
|
||||
tempGameMap[y][i] = newBlobs[i];
|
||||
}
|
||||
if (currentTetromino == null) continue;
|
||||
Color[] newBlobs = currentTetromino.getLine(y);
|
||||
for (int i = 0; i < newBlobs.length; i++) {
|
||||
if (newBlobs[i] == null) continue;
|
||||
tempGameMap[y][i] = newBlobs[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package eu.midnightdust.yaytris.ui;
|
||||
|
||||
import eu.midnightdust.yaytris.Tetris;
|
||||
import eu.midnightdust.yaytris.game.Space;
|
||||
import eu.midnightdust.yaytris.util.CatppuccinColor;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@@ -79,8 +78,6 @@ public class TetrisUI extends JFrame implements KeyListener {
|
||||
|
||||
public void startGame(ActionEvent actionEvent) {
|
||||
Tetris.startGame();
|
||||
//this.remove(menuPanel);
|
||||
//menuPanel = null;
|
||||
this.openScoreMenu(actionEvent);
|
||||
this.requestFocus();
|
||||
this.repaint();
|
||||
|
||||
Reference in New Issue
Block a user