Compare commits
2 Commits
f881427a67
...
c017d4c129
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c017d4c129 | ||
|
|
b17e88f96d |
38
README.md
38
README.md
@@ -10,10 +10,38 @@ Können Sie meinen Highscore schlagen?
|
||||
|
||||

|
||||
|
||||
## Im Falle einer IllegalArgumentException
|
||||
Eclipse ist unfähig, Java-Konventionen zu befolgen und fügt den 'resources'-Ordner nicht automatisch zum classpath hinzu.
|
||||
Um das zu beheben, gehen Sie in die Projekteinstellungen -> Java Build Path -> Source und fügen Sie den Ordner `src/main/resources` manuell hinzu.
|
||||
|
||||
## Rechtliche Hinweise
|
||||
»Tetris« ist eine eingetragene Marke von The Tetris Company, Inc.
|
||||
Die Verwendung des Namens »Tetris« und des Spielkonzepts erfolgen lediglich zu Bildungszwecken.
|
||||
Die Verwendung des Namens »Tetris« und des Spielkonzepts erfolgen lediglich zu Bildungszwecken.
|
||||
|
||||
# Testbeispiele
|
||||
## Bewegung
|
||||
Spiel starten
|
||||
1. Nach links verschieben mit `A` oder `←`
|
||||
2. Nach rechts verschieben mit `D` oder `→`
|
||||
3. Schneller nach unten mit `S` oder `↓`
|
||||
4. Direkt nach unten mit `Leertaste`
|
||||
5. Rotieren mit `W` oder `↑`
|
||||
|
||||
Bei jeder Bewegung sollte vor dem Umsetzen geprüft werden, ob die neue Position valide (Nicht überschneidend und nicht außerhalb des Spielraums) ist.
|
||||
|
||||
## Logik
|
||||
Sobald eine Reihe vervollständigt wird, sollte sie verschwinden.
|
||||
Wenn die Teile über den oberen Rand ragen, soll das Spiel beendet werden.
|
||||
Im Vorschaufenster sollte immer das nächste Tetrominio angezeigt werden.
|
||||

|
||||
|
||||
## Highscores
|
||||
Sobald das Spiel beendet wird und der Score den aktuell höchsten Score überschreitet, sollte eine Aufforderung zum Eingeben des Namens erscheinen.
|
||||
Nach dem Bestätigen erscheint der Name in der Highscore-Liste und wird über Spielsitzungen hinweg gespeichert.
|
||||

|
||||
|
||||
## Benutzeroberfläche
|
||||
Die Darstellung der Benutzeroberfläche kann in den Einstellungen angepasst werden.
|
||||
Dabei lässt sich die Sprache und die GUI-Skalierung auswählen.
|
||||
Ansonsten sind auch noch Einstellungen zur Lautstärke und Schwierigkeit vorhanden.
|
||||
|
||||
## Sounds und Musik
|
||||
Sofern die Lautstärke angemessen eingestellt und ein Lautsprecher angeschlossen ist, sollten beim Absetzen der Tetrominos, sowie beim Vervollständigen einer/mehrerer Reihen Töne zu hören sein.
|
||||
Auch Musik sollte abgespielt werden, sobald das Spiel gestartet wird.
|
||||
Töne und Musik wurden im Zrythm-DAW erzeugt.
|
||||
BIN
assets/highscore_dialog.png
Normal file
BIN
assets/highscore_dialog.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 102 KiB |
BIN
assets/line_completion.png
Normal file
BIN
assets/line_completion.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
22
src/main/java/eu/midnightdust/yaytris/Main.java
Normal file
22
src/main/java/eu/midnightdust/yaytris/Main.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package eu.midnightdust.yaytris;
|
||||
|
||||
import javax.swing.UIManager;
|
||||
|
||||
public class Main {
|
||||
|
||||
/**
|
||||
* 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");
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (Exception | Error e) { System.out.printf("%s: %s\n", "Error setting system look and feel", e); }
|
||||
Tetris.init();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
package eu.midnightdust.yaytris;
|
||||
|
||||
import eu.midnightdust.yaytris.game.Space;
|
||||
import eu.midnightdust.yaytris.game.Tetromino;
|
||||
import eu.midnightdust.yaytris.ui.ScoreMenu;
|
||||
import eu.midnightdust.yaytris.ui.TetrisUI;
|
||||
import eu.midnightdust.yaytris.util.GravityTimerTask;
|
||||
import eu.midnightdust.yaytris.util.sound.SoundUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.time.LocalTime;
|
||||
import java.util.Random;
|
||||
import java.util.Timer;
|
||||
@@ -20,30 +20,19 @@ 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");
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
} catch (Exception | Error e) { System.out.printf("%s: %s\n", "Error setting system look and feel", e); }
|
||||
public static void init() {
|
||||
Settings.load();
|
||||
Translation.load(Settings.language.locale);
|
||||
HighScores.load();
|
||||
timer = new Timer("Tetris falling pieces");
|
||||
space = new Space();
|
||||
ui = new TetrisUI();
|
||||
Tetris.timer = new Timer("Tetris falling pieces");
|
||||
Tetris.space = new Space();
|
||||
Tetris.ui = new TetrisUI();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the active game space
|
||||
*
|
||||
* @see Space
|
||||
* @see Space
|
||||
*/
|
||||
public static Space getSpace() {
|
||||
return space;
|
||||
@@ -52,7 +41,7 @@ public class Tetris {
|
||||
/**
|
||||
* Get the ui instance
|
||||
*
|
||||
* @see TetrisUI
|
||||
* @see TetrisUI
|
||||
*/
|
||||
public static TetrisUI getUi() {
|
||||
return ui;
|
||||
@@ -61,7 +50,7 @@ public class Tetris {
|
||||
/**
|
||||
* Resets the game space, preparing it for a new game.
|
||||
*
|
||||
* @see Space
|
||||
* @see Space
|
||||
*/
|
||||
public static void resetSpace() {
|
||||
SoundUtil.stopMusic("/music/theme.wav");
|
||||
@@ -72,9 +61,9 @@ public class Tetris {
|
||||
|
||||
/**
|
||||
* 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}
|
||||
* This involves starting our gravity task, playing music and spawning the first {@link Tetromino}
|
||||
*
|
||||
* @see Space#spawnTetromino()
|
||||
* @see Space#spawnTetromino()
|
||||
*/
|
||||
public static void startGame() {
|
||||
SoundUtil.playMusic("/music/theme.wav", true);
|
||||
@@ -88,8 +77,8 @@ public class Tetris {
|
||||
* Stops the current game.
|
||||
* Disables falling, fades out music and handles saving of high scores.
|
||||
*
|
||||
* @see ScoreMenu
|
||||
* @see HighScores
|
||||
* @see ScoreMenu
|
||||
* @see HighScores
|
||||
*/
|
||||
public static void stopGame() {
|
||||
SoundUtil.stopMusic("/music/theme.wav");
|
||||
@@ -97,32 +86,35 @@ public class Tetris {
|
||||
timer.purge();
|
||||
if (ui.getMenuPanel() instanceof ScoreMenu) ((ScoreMenu) ui.getMenuPanel()).gameOver();
|
||||
ui.transferFocus();
|
||||
if (HighScores.diffToMap(Settings.difficulty).values().stream().noneMatch(hs -> hs > space.getScore())) ui.showHighscoreDialog(space.getScore());
|
||||
if (HighScores.diffToMap(Settings.difficulty).values().stream().noneMatch(hs -> hs > space.getScore()))
|
||||
ui.showHighscoreDialog(space.getScore());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the displayed score
|
||||
*
|
||||
* @param score the new score
|
||||
* @see ScoreMenu
|
||||
* @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
|
||||
* @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
|
||||
* @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 / 1400f));
|
||||
@@ -136,5 +128,4 @@ public class Tetris {
|
||||
if (ui.getMenuPanel() instanceof ScoreMenu) ((ScoreMenu) ui.getMenuPanel()).updateLevel(newLevel);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class TetrisUI extends JFrame implements KeyListener {
|
||||
private void rescale() {
|
||||
this.setSize((int) (400 * guiScale), (int) (320 * guiScale));
|
||||
titleLabel.setBounds(scale(225), scale(7), scale(110), scale(30));
|
||||
titleLabel.setIcon(new ImageIcon(new ImageIcon(titleImage).getImage().getScaledInstance(scale(110), scale(30), Image.SCALE_DEFAULT)));
|
||||
titleLabel.setIcon(new ImageIcon(titleImage.getScaledInstance(scale(110), scale(30), Image.SCALE_DEFAULT)));
|
||||
gamePanel.setBounds(scale(10), scale(10), scale(150), scale(282));
|
||||
this.setLocationRelativeTo(null);
|
||||
}
|
||||
@@ -165,7 +165,7 @@ public class TetrisUI extends JFrame implements KeyListener {
|
||||
*/
|
||||
public void showHighscoreDialog(int score) {
|
||||
String playerName = JOptionPane.showInputDialog(null, t("dialog.highscore.action"), t("dialog.highscore.title"), JOptionPane.PLAIN_MESSAGE);
|
||||
HighScores.addScore(playerName, score);
|
||||
if (playerName != null) HighScores.addScore(playerName, score);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user