docs: add javadocs for nearly everything

This commit is contained in:
Martin Prokoph
2025-09-02 23:48:49 +02:00
parent 504018b9f8
commit 67a12899c6
14 changed files with 334 additions and 31 deletions

View File

@@ -19,6 +19,13 @@ public class Tetris {
private static TimerTask gravityTask;
private static LocalTime startTime;
/**
* The application's entry point.
* Initializes the UI library to match the system style.
* Also loads saved settings, translations, and highscores from JSON.
*
* @param args command line arguments will be ignored
*/
public static void main(String[] args) {
try {
System.setProperty("java.awt.headless", "false");
@@ -32,10 +39,20 @@ public class Tetris {
ui = new TetrisUI();
}
/**
* Get the active game space
*
* @see Space
*/
public static Space getSpace() {
return space;
}
/**
* Resets the game space, preparing it for a new game.
*
* @see Space
*/
public static void resetSpace() {
SoundUtil.stopMusic("/music/theme.wav");
if (gravityTask != null) gravityTask.cancel();
@@ -43,6 +60,12 @@ public class Tetris {
space = new Space();
}
/**
* Starts a new game of Tetris :D
* This involves starting our gravity task, playing music and spawning the first {@link eu.midnightdust.yaytris.game.Tetromino}
*
* @see Space#spawnTetromino()
*/
public static void startGame() {
SoundUtil.playMusic("/music/theme.wav", true);
space.spawnTetromino();
@@ -51,6 +74,13 @@ public class Tetris {
timer.scheduleAtFixedRate(gravityTask, 1, Settings.difficulty.getTimerPeriod());
}
/**
* Stops the current game.
* Disables falling, fades out music and handles saving of high scores.
*
* @see ScoreMenu
* @see HighScores
*/
public static void stopGame() {
SoundUtil.stopMusic("/music/theme.wav");
if (gravityTask != null) gravityTask.cancel();
@@ -60,13 +90,30 @@ public class Tetris {
if (HighScores.scores.values().stream().noneMatch(hs -> hs > space.getScore())) ui.showHighscoreDialog(space.getScore());
}
/**
* Updates the displayed score
*
* @param score the new score
* @see ScoreMenu
*/
public static void updateScore(int score) {
if (ui.getMenuPanel() instanceof ScoreMenu) ((ScoreMenu) ui.getMenuPanel()).updateScore(score);
updateLevel(score);
}
/**
* Updates the elapsed time
*
* @see ScoreMenu
*/
public static void updateTime() {
if (ui.getMenuPanel() instanceof ScoreMenu) ((ScoreMenu) ui.getMenuPanel()).updateTime(startTime);
}
/**
* Updates the displayed level
*
* @param score the new score, from which the level will be calculated
* @see ScoreMenu
*/
public static void updateLevel(int score) {
int newLevel = Math.max(0, (int) (score / 1000f));
if (newLevel != space.level) {
@@ -80,6 +127,9 @@ public class Tetris {
}
}
/**
* Defines our custom timer task that handles falling pieces.
*/
public static class GravityTimerTask extends TimerTask {
@Override
public void run() {