diff --git a/src/main/dev/lh/Snake.java b/src/main/dev/lh/Snake.java index f0fa54d..ee3293c 100644 --- a/src/main/dev/lh/Snake.java +++ b/src/main/dev/lh/Snake.java @@ -28,7 +28,7 @@ public class Snake implements Updateable { * @author Leon Hofmeister * @since Snake 1.0 */ - public static enum Direction { + public enum Direction { /** * Use if the snake should head left. */ @@ -50,10 +50,10 @@ public class Snake implements Updateable { DOWN; } - private static Endscreen endscreen; - private Direction direction = Direction.RIGHT; - private int length; - private List tiles = new ArrayList<>(); + private static Endscreen endscreen; + private Direction direction = Direction.RIGHT; + private int length; + private final List tiles = new ArrayList<>(); private static final int TILE_SIZE = 10; @@ -78,7 +78,7 @@ public class Snake implements Updateable { * @since Snake 1.0 */ public void addLength(int additional) { - Rectangle last = tiles.get(tiles.size() - 1); + final Rectangle last = tiles.get(tiles.size() - 1); for (int i = 0; i < additional; i++) tiles.add(last); length += additional; @@ -96,9 +96,9 @@ public class Snake implements Updateable { * @since Snake 1.1 */ private void gameOver() { + Main.getGame().close(); endscreen = new Endscreen(length); endscreen.setVisible(true); - Main.getGame().close(); } @Override diff --git a/src/main/dev/lh/ui/StartScreen.java b/src/main/dev/lh/ui/StartScreen.java index 0b908d7..5af86cb 100755 --- a/src/main/dev/lh/ui/StartScreen.java +++ b/src/main/dev/lh/ui/StartScreen.java @@ -4,9 +4,7 @@ import java.awt.EventQueue; import java.awt.Font; import java.awt.event.KeyEvent; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JPanel; +import javax.swing.*; import javax.swing.border.EmptyBorder; import dev.lh.Main; @@ -26,9 +24,7 @@ public class StartScreen extends JFrame { /** * Closes the application. */ - public static void close() { - System.exit(0); - } + public static void close() { System.exit(0); } /** * Launches Snake. @@ -36,25 +32,22 @@ public class StartScreen extends JFrame { * @param args the program arguments * @since Snake 1.0 */ - public static void main(String[] args) { - EventQueue.invokeLater(StartScreen::new); - } + public static void main(String[] args) { EventQueue.invokeLater(StartScreen::new); } /** * Create the frame. */ public StartScreen() { setTitle("Snake - Startscreen"); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setBounds(500, 200, 550, 550); - JPanel contentPane = new JPanel(); + final JPanel contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); - JButton buPlay = new JButton("Start Game"); + final JButton buPlay = new JButton("Start Game"); buPlay.setBounds(158, 197, 190, 131); - buPlay.setText("Play Again"); buPlay.setMnemonic(KeyEvent.VK_ENTER); buPlay.setFont(new Font("Times New Roman", Font.PLAIN, 16)); buPlay.addActionListener(a -> {