From 3723c333e1946deded6f5244143f26818cc18294 Mon Sep 17 00:00:00 2001 From: delvh Date: Tue, 31 Mar 2020 18:24:12 +0200 Subject: [PATCH] Cleaned up whole project further (contains no more unused code snippets) --- src/main/dev/lh/FoodFactory.java | 9 +- src/main/dev/lh/Main.java | 1 - src/main/dev/lh/Updateable.java | 1 - src/main/dev/lh/ui/Endscreen.java | 173 +--------------------------- src/main/dev/lh/ui/GameWindow.java | 10 +- src/main/dev/lh/ui/StartScreen.java | 34 +----- 6 files changed, 10 insertions(+), 218 deletions(-) diff --git a/src/main/dev/lh/FoodFactory.java b/src/main/dev/lh/FoodFactory.java index 486511a..fc6252a 100755 --- a/src/main/dev/lh/FoodFactory.java +++ b/src/main/dev/lh/FoodFactory.java @@ -1,10 +1,6 @@ package dev.lh; -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Point; -import java.awt.Rectangle; +import java.awt.*; import dev.lh.ui.GameWindow; @@ -227,8 +223,7 @@ public class FoodFactory { case blue: snakeAdditionalLength = 1; break; - }// switch + } return snakeAdditionalLength; } - } diff --git a/src/main/dev/lh/Main.java b/src/main/dev/lh/Main.java index c446376..bb26ca9 100755 --- a/src/main/dev/lh/Main.java +++ b/src/main/dev/lh/Main.java @@ -38,5 +38,4 @@ public class Main { * @since Snake 1.0 */ public static GameWindow getGame() { return game; } - } diff --git a/src/main/dev/lh/Updateable.java b/src/main/dev/lh/Updateable.java index 8452686..f2f91c6 100755 --- a/src/main/dev/lh/Updateable.java +++ b/src/main/dev/lh/Updateable.java @@ -29,5 +29,4 @@ public interface Updateable { * @since Snake 1.0 */ void render(Graphics g); - } diff --git a/src/main/dev/lh/ui/Endscreen.java b/src/main/dev/lh/ui/Endscreen.java index 0eec1d7..3432a98 100755 --- a/src/main/dev/lh/ui/Endscreen.java +++ b/src/main/dev/lh/ui/Endscreen.java @@ -52,114 +52,26 @@ public class Endscreen extends JDialog { } catch (Exception e) { e.printStackTrace(); } - // JScrollPane scrollPane = new JScrollPane(); - // scrollPane.setBounds(10, 412, 349, 238); - // contentPanel.add(scrollPane); - // String[][] combis = new String[highscorePoints.length][2]; - // for (int i = 0; i < highscorePoints.length; i++) { - // combis[i][0] = highscorePlayers[i]; - // combis[i][1] = String.valueOf(highscorePoints[i]); - // } - // table = new JTable(combis, tableTitle); - // table.setRowSelectionAllowed(false); - // table.setFillsViewportHeight(true); - // table.setFont(new Font("Times New Roman", Font.PLAIN, 15)); - // scrollPane.setViewportView(table); - - // JLabel lblNewLabel = new JLabel("Highscores"); - // lblNewLabel.setFont(new Font("Times New Roman", Font.BOLD | Font.ITALIC, - // 18)); - // lblNewLabel.setBounds(65, 292, 98, 41); - // contentPanel.add(lblNewLabel); JButton btnNewButton = new JButton("Play again"); btnNewButton.setMnemonic(KeyEvent.VK_ENTER); btnNewButton.addActionListener(e -> { Main.startGame(); dispose(); }); contentPanel.setLayout(new BorderLayout(0, 0)); - btnNewButton.setIcon(new ImageIcon(ClassLoader.getSystemResource("/com/sun/javafx/webkit/prism/resources/mediaPlayDisabled.png"))); + // btnNewButton.setIcon(new + // ImageIcon(ClassLoader.getSystemResource("/com/sun/javafx/webkit/prism/resources/mediaPlayDisabled.png"))); btnNewButton.setIconTextGap(5); - // Endscreen.class.getResource("/com/sun/javafx/webkit/prism/resources/mediaPlayDisabled.png"))); btnNewButton.setFont(new Font("Times New Roman", Font.PLAIN, 15)); contentPanel.add(btnNewButton, BorderLayout.SOUTH); - // JButton btnClose = new JButton("Close game"); - // - // btnClose.addActionListener(new ActionListener() {// Beginn Listener new game - // public void actionPerformed(ActionEvent e) { - // System.exit(0); - // } - // }); - // - // btnClose.setFont(new Font("Times New Roman", Font.PLAIN, 15)); - // btnClose.setBounds(400, 500, 200, 100); - // contentPanel.add(btnClose); - // - // tfName = new JTextField(); - // tfName.setFont(new Font("Times New Roman", Font.PLAIN, 15)); - // tfName.setBounds(102, 344, 257, 40); - // contentPanel.add(tfName); - // tfName.setColumns(10); - // - // JTextArea txtrBitteErstNamen = new JTextArea(); - // txtrBitteErstNamen.setVisible(false); - // txtrBitteErstNamen.setBackground(UIManager.getColor("ScrollBar.foreground")); - // txtrBitteErstNamen.setText("Bitte erst Namen \r\neingeben und\r\ndann - // Speichern!!!!"); - // txtrBitteErstNamen.setBounds(468, 412, 155, 92); - // contentPanel.add(txtrBitteErstNamen); - // txtrBitteErstNamen.setVisible(false); - // - // JButton btnSaveHighscore = new JButton("Save Highscore"); - // btnSaveHighscore.setMnemonic(KeyEvent.VK_ENTER); - // btnSaveHighscore.setIconTextGap(5); - // btnSaveHighscore.setIcon( - // new - // ImageIcon(Endscreen.class.getResource("/javax/swing/plaf/metal/icons/ocean/floppy.gif"))); - // btnSaveHighscore.setFont(new Font("Times New Roman", Font.PLAIN, 15)); - // - // btnSaveHighscore.addActionListener(new ActionListener() {// Beginn Listener - // Save Highscore - // public void actionPerformed(ActionEvent e) { - // relocate(score1); - // writeFiles(); - // table.updateUI(); - // } - // - // }); - // - // btnSaveHighscore.setBounds(468, 344, 155, 50); - // contentPanel.add(btnSaveHighscore); - JLabel lblDeinPunktestand = new JLabel("Dein Punktestand: " + String.valueOf(score)); lblDeinPunktestand.setFont(new Font("Times New Roman", Font.PLAIN, 25)); contentPanel.add(lblDeinPunktestand, BorderLayout.NORTH); - // JLabel lblYourName = new JLabel("Your Name:"); - // lblYourName.setFont(new Font("Times New Roman", Font.PLAIN, 15)); - // lblYourName.setBounds(10, 355, 82, 29); - // contentPanel.add(lblYourName); - Image resultImage = Toolkit.getDefaultToolkit() .getImage(this.getClass() .getResource((score < goodOrBadResult) ? "/Snake/src/main/resources/Try_Again.jpg" : "/Snake/src/main/resources/1211548-200.png")); resultImage.flush(); - // JCheckBox chckbxNewCheckBox = new JCheckBox(""); - // JLabel lblDasIstEin = new JLabel("Das ist ein hervorragender Wert!"); - // lblDasIstEin.setFont(new Font("Times New Roman", Font.PLAIN, 15)); - // if (score >= goodOrBadResult) { - // chckbxNewCheckBox.setIcon(new - // ImageIcon(ClassLoader.getSystemResource("/dev/lh/snake/1211548-200.png"))); - // chckbxNewCheckBox.setBounds(300, 200, 200, 200); - // lblDasIstEin.setBounds(10, 100, 212, 50); - // } else { - // chckbxNewCheckBox.setIcon(new - // ImageIcon(ClassLoader.getSystemResource("/dev/lh/snake/Try_Again.jpg"))); - // chckbxNewCheckBox.setBounds(300, 200, 250, 210); - // lblDasIstEin.setText("Das kannst du aber noch verbessern!"); - // lblDasIstEin.setBounds(10, 100, 240, 50); - // } - // contentPanel.add(chckbxNewCheckBox, BorderLayout.CENTER); - // contentPanel.add(lblDasIstEin, BorderLayout.EAST); + setVisible(true); } @@ -174,81 +86,4 @@ public class Endscreen extends JDialog { * @since Snake 1.0 */ public void setScore(int score) { this.score = score; } - /* - * public static void readInHighscoresPoints() { try { // FileReader reads text - * files in the default encoding. FileReader fileReader = new - * FileReader(fileNamePoints); - * // Always wrap FileReader in BufferedReader. BufferedReader bufferedReader = - * new BufferedReader(fileReader); - * currentIndex = Integer.parseInt(bufferedReader.readLine()); for (int i = 0; i - * < currentIndex; i++) { highscorePoints[i]= - * Integer.parseInt(bufferedReader.readLine()); } // Always close files. - * bufferedReader.close(); fileReader.close(); } catch (FileNotFoundException - * ex) { System.out.println("Error 404:File '" + fileNamePoints + - * "' not found"); - * } catch (IOException ex) { System.out.println("Error reading file '" + - * fileNamePoints + "'"); ex.printStackTrace(); } } private void - * readInHighscoresPlayers(){ try { // FileReader reads text files in the - * default encoding. FileReader fileReader = new FileReader(fileNamePlayers); - * // Always wrap FileReader in BufferedReader. BufferedReader bufferedReader = - * new BufferedReader(fileReader); - * for (int i = 0; i < currentIndex; i++) { highscorePlayers[i]= - * bufferedReader.readLine(); } // Always close files. bufferedReader.close(); - * fileReader.close(); } catch (FileNotFoundException ex) { - * System.out.println("Error 404:File '" + fileNamePlayers + "' not found"); - * } catch (IOException ex) { System.out.println("Error reading file '" + - * fileNamePlayers + "'"); ex.printStackTrace(); } } /* private void - * writeFiles() { File dateiPoints = new File("." + File.separator + - * fileNamePoints); FileWriter fwpoints = null; BufferedWriter bwpoints = null; - * try { fwpoints = new FileWriter(dateiPoints); bwpoints = new - * BufferedWriter(fwpoints); bwpoints.write(highscorePoints.length); for (int - * i=0;i= - * 30){ for (int i=30;i { s.nextFrame(); if (System.currentTimeMillis() >= foodFactory.getTimeOfNextFood()) newFood(); repaint(); }); + evt -> { s.nextFrame(); if (System.currentTimeMillis() >= foodFactory.getTimeOfNextFood()) newFood(); repaint(); }); timer.start(); setVisible(true); @@ -112,4 +108,4 @@ public class GameWindow extends JFrame { * @since Snake 1.1 */ public void close() { dispose(); } -} \ No newline at end of file +} diff --git a/src/main/dev/lh/ui/StartScreen.java b/src/main/dev/lh/ui/StartScreen.java index b62dd68..2b9f374 100755 --- a/src/main/dev/lh/ui/StartScreen.java +++ b/src/main/dev/lh/ui/StartScreen.java @@ -4,10 +4,7 @@ import java.awt.EventQueue; import java.awt.Font; import java.awt.event.KeyEvent; -import javax.swing.ImageIcon; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JPanel; +import javax.swing.*; import javax.swing.border.EmptyBorder; import dev.lh.Main; @@ -47,35 +44,6 @@ public class StartScreen extends JFrame { }); } - // public static void readInHighscores() { - // try { - // combination.clear(); - // // FileReader reads text files in the default encoding. - // FileReader fileReader = new FileReader(fileName); - // - // // Always wrap FileReader in BufferedReader. - // BufferedReader bufferedReader = new BufferedReader(fileReader); - // - // currentIndex = Integer.parseInt(bufferedReader.readLine()); - // for (int i = 0; i < currentIndex; i++) { - // String[] spielerScore = new String[2]; - // spielerScore[0] = bufferedReader.readLine(); - // spielerScore[1] = bufferedReader.readLine(); - // combination.add(spielerScore); - // } - // // Always close files. - // bufferedReader.close(); - // fileReader.close(); - // } catch (FileNotFoundException ex) { - // System.out.println("Error 404:File '" + fileName + "' not found"); - // - // } catch (IOException ex) { - // System.out.println("Error reading file '" + fileName + "'"); - // ex.printStackTrace(); - // - // } - // } - /** * Create the frame. */