diff --git a/.classpath b/.classpath old mode 100644 new mode 100755 index 8cbcff2..a4f6d47 --- a/.classpath +++ b/.classpath @@ -2,6 +2,7 @@ + @@ -12,10 +13,6 @@ - - - - diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.project b/.project old mode 100644 new mode 100755 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs old mode 100644 new mode 100755 diff --git a/.settings/org.eclipse.jdt.ui.prefs b/.settings/org.eclipse.jdt.ui.prefs old mode 100644 new mode 100755 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/Snake/.classpath b/Snake/.classpath deleted file mode 100644 index 6c1ba30..0000000 --- a/Snake/.classpath +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/Snake/.gitignore b/Snake/.gitignore deleted file mode 100644 index ae3c172..0000000 --- a/Snake/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/Snake/.project b/Snake/.project deleted file mode 100644 index 919eb8f..0000000 --- a/Snake/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - Snake - - - - - - org.eclipse.jdt.core.javabuilder - - - - - - org.eclipse.jdt.core.javanature - - diff --git a/Snake/.settings/org.eclipse.jdt.core.prefs b/Snake/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index bb35fa0..0000000 --- a/Snake/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,11 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/Snake/jgoodies-forms-1.8.0.jar b/Snake/jgoodies-forms-1.8.0.jar deleted file mode 100644 index d5cdefb..0000000 Binary files a/Snake/jgoodies-forms-1.8.0.jar and /dev/null differ diff --git a/Snake/miglayout15-swing.jar b/Snake/miglayout15-swing.jar deleted file mode 100644 index 835545d..0000000 Binary files a/Snake/miglayout15-swing.jar and /dev/null differ diff --git a/Snake/src/dev/lh/snake/Food.java b/Snake/src/dev/lh/snake/Food.java deleted file mode 100644 index c380bf4..0000000 --- a/Snake/src/dev/lh/snake/Food.java +++ /dev/null @@ -1,21 +0,0 @@ -package dev.lh.snake; - -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Point; - -public class Food { - - private Point position; - - public Food(int x, int y) { - position = new Point(x,y); - } - - public void render(Graphics g) { - g.setColor(Color.yellow); - g.fillRect(position.x, position.y, 16, 16); - } - - -} diff --git a/Snake/src/dev/lh/snake/GameWindow.java b/Snake/src/dev/lh/snake/GameWindow.java deleted file mode 100644 index 0fb25fa..0000000 --- a/Snake/src/dev/lh/snake/GameWindow.java +++ /dev/null @@ -1,98 +0,0 @@ -package dev.lh.snake; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics; -import java.awt.Toolkit; -import java.awt.event.KeyAdapter; -import java.awt.event.KeyEvent; - -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.Timer; - -import dev.lh.snake.Snake; - -public class GameWindow extends JFrame { - - /** - * - */ - private static final long serialVersionUID = 1L; - Toolkit tk = Toolkit.getDefaultToolkit(); - int xSize = ((int) tk.getScreenSize().getWidth()); - int ySize = ((int) tk.getScreenSize().getHeight()); - - public GameWindow(int width, int height, String title) { - super(title); - setLocationRelativeTo(null); - Dimension size = new Dimension(width, height); - setPreferredSize(size); - setMinimumSize(size); - setMaximumSize(size); - setResizable(false); - setDefaultCloseOperation(EXIT_ON_CLOSE); - - Snake s = new Snake(3); - - add(new JPanel() { - - /** - * - */ - private static final long serialVersionUID = 1L; - - @Override - protected void paintComponent(Graphics g) { - super.paintComponent(g); - g.setColor(Color.black); - g.fillRect(0, 0, width, height); - s.render(g); - } - }); - - addKeyListener(new KeyAdapter() { - - @Override - public void keyPressed(KeyEvent e) { - super.keyPressed(e); - switch (e.getKeyCode()) { - case KeyEvent.VK_W: - s.setRichtung(Direction.Up); - break; - case KeyEvent.VK_A: - s.setRichtung(Direction.Left); - break; - case KeyEvent.VK_S: - s.setRichtung(Direction.Down); - break; - case KeyEvent.VK_D: - s.setRichtung(Direction.Right); - break; - case KeyEvent.VK_UP: - s.setRichtung(Direction.Up); - break; - case KeyEvent.VK_LEFT: - s.setRichtung(Direction.Left); - break; - case KeyEvent.VK_DOWN: - s.setRichtung(Direction.Down); - break; - case KeyEvent.VK_RIGHT: - s.setRichtung(Direction.Right); - break; - - }// switch - }// keypressed - });// keylistener - - Timer timer = new Timer (200, (evt)->{ - s.tick(); - repaint(); - }); - timer.start(); - - setVisible(true); - - } -}// Konstruktor \ No newline at end of file diff --git a/Snake/src/dev/lh/snake/Handler.java b/Snake/src/dev/lh/snake/Handler.java deleted file mode 100644 index db7b371..0000000 --- a/Snake/src/dev/lh/snake/Handler.java +++ /dev/null @@ -1,15 +0,0 @@ -package dev.lh.snake; - -import java.util.ArrayList; -import java.util.List; - -public class Handler { - - List targets; - - public Handler() { - targets = new ArrayList<>(); - targets.add(new Snake(3)); - } - -} diff --git a/Snake/src/dev/lh/snake/Main.java b/Snake/src/dev/lh/snake/Main.java deleted file mode 100644 index 7a6b3cd..0000000 --- a/Snake/src/dev/lh/snake/Main.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.lh.snake; - -import dev.lh.snake.GameWindow; - -public class Main { - - public static void main(String[] args) { - - GameWindow game = new GameWindow(640, 480, "Snake"); - game.setVisible(true); - } - -} diff --git a/Snake/src/dev/lh/snake/Snake.java b/Snake/src/dev/lh/snake/Snake.java deleted file mode 100644 index 6c00f4e..0000000 --- a/Snake/src/dev/lh/snake/Snake.java +++ /dev/null @@ -1,76 +0,0 @@ -package dev.lh.snake; - -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Point; - -public class Snake implements Updateable { - - static enum Direction{ - Left, Right, Up, Down; - } - private Direction Richtung; - private int length; - private Point[] tiles; - - public Snake(int length) { - this.length = length; - tiles =new Point[length]; - Richtung = Direction.Left; - - for(int i = 0; iSnake
- * File: Food.java
- * Created: 11 Mar 2020
- * - * @author Leon Hofmeister - * @since Snake 1.0 - */ -public class Food { - - private Point position; - - /** - * Constructs a new food object. - * - * @param x the x coordinate of the new food - * @param y the y coordinate of the new food - * @since Snake 1.0 - */ - public Food(int x, int y) { position = new Point(x, y); } - - /** - * Constructs a new food object. - * - * @param position the position of the food - * @since Snake 1.1 - */ - public Food(Point position) { this.position = position; } - - /** - * @param g the {@link Graphics} object used to draw the food - * @since Snake 1.0 - */ - public void render(Graphics g) { - g.setColor(Color.yellow); - g.fillRect(position.x, position.y, 16, 16); - } - -} diff --git a/src/main/dev/lh/FoodFactory.java b/src/main/dev/lh/FoodFactory.java old mode 100644 new mode 100755 diff --git a/src/main/dev/lh/Handler.java b/src/main/dev/lh/Handler.java deleted file mode 100644 index 6aebf6b..0000000 --- a/src/main/dev/lh/Handler.java +++ /dev/null @@ -1,30 +0,0 @@ -package dev.lh; - -import java.util.ArrayList; -import java.util.List; - -/** - * The handler handles incoming events in Snake.
- *
- * Project: Snake
- * File: Handler.java
- * Created: 11 Mar 2020
- * - * @author Leon Hofmeister - * @since Snake 1.0 - */ -public class Handler { - - List targets; - - /** - * Constructs a new {@link Handler}. - * - * @since Snake 1.0 - */ - public Handler() { - targets = new ArrayList<>(); - targets.add(new Snake(3)); - } - -} diff --git a/src/main/dev/lh/Main.java b/src/main/dev/lh/Main.java old mode 100644 new mode 100755 diff --git a/src/main/dev/lh/Snake.java b/src/main/dev/lh/Snake.java old mode 100644 new mode 100755 index 88134dc..6d26e23 --- a/src/main/dev/lh/Snake.java +++ b/src/main/dev/lh/Snake.java @@ -52,10 +52,11 @@ public class Snake implements Updateable { Down; } + private static FoodFactory foodFactory = FoodFactory.getInstance(); + private static Endscreen endscreen; private Direction Richtung; private int length; private List tiles = new ArrayList<>(); - private static FoodFactory foodFactory = FoodFactory.getInstance(); private final int snakeSize = 10; /** @@ -67,17 +68,15 @@ public class Snake implements Updateable { public Snake(int length) { this.length = length; Richtung = Direction.Right; - + // adding the initial tiles of the snake for (int i = 0; i < length; i++) - tiles.add(new Point(320 - 50 * i, 240)); - - }// End Constructor + tiles.add(new Point(320 - snakeSize * i, 240)); + } @Override public void nextFrame() { int velX = 0, velY = 0; switch (Richtung) { - case Up: velY = -snakeSize; break; @@ -90,7 +89,7 @@ public class Snake implements Updateable { case Right: velX = snakeSize; break; - }// switch + } Point next = (Point) tiles.get(0).clone(), cur; tiles.get(0).x += velX; tiles.get(0).y += velY; @@ -101,8 +100,9 @@ public class Snake implements Updateable { next = cur; } - // case if the snake is outside of the screen or touches itself - if (!Main.getGame().getBounds().contains(tiles.get(0)) || checkSelfCollision()) gameOver(); + // case if snake is outside of the screen or touches itself + if (checkSelfCollision()) gameOver(); + // if (!Main.getGame().getBounds().contains(tiles.get(0))) gameOver(); // case if snake eats food if (foodFactory.checkCollision(new Rectangle(tiles.get(0).x, tiles.get(0).y, snakeSize, snakeSize))) { @@ -117,7 +117,7 @@ public class Snake implements Updateable { * @since Snake 1.1 */ private void gameOver() { - Endscreen endscreen = new Endscreen(length); + endscreen = new Endscreen(length); endscreen.setVisible(true); Main.getGame().close(); } diff --git a/src/main/dev/lh/Spawner.java b/src/main/dev/lh/Spawner.java deleted file mode 100644 index d559b54..0000000 --- a/src/main/dev/lh/Spawner.java +++ /dev/null @@ -1,25 +0,0 @@ -package dev.lh; - -import java.awt.Graphics; - -/** - * Project: Snake
- * File: Spawner.java
- * Created: 11 Mar 2020
- * - * @author Leon Hofmeister - * @since Snake 1.0 - */ -public class Spawner implements Updateable { - - @Override - public void nextFrame() { - - } - - @Override - public void render(Graphics g) { - - } - -} diff --git a/src/main/dev/lh/Updateable.java b/src/main/dev/lh/Updateable.java old mode 100644 new mode 100755 diff --git a/src/main/dev/lh/ui/Endscreen.java b/src/main/dev/lh/ui/Endscreen.java old mode 100644 new mode 100755 index 92da2d3..0eec1d7 --- a/src/main/dev/lh/ui/Endscreen.java +++ b/src/main/dev/lh/ui/Endscreen.java @@ -1,13 +1,9 @@ package dev.lh.ui; -import java.awt.BorderLayout; -import java.awt.Font; +import java.awt.*; import java.awt.event.KeyEvent; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; +import javax.swing.*; import javax.swing.border.EmptyBorder; import dev.lh.Main; @@ -24,8 +20,9 @@ public class Endscreen extends JDialog { private static final long serialVersionUID = -4457484397259161063L; - private final JPanel contentPanel = new JPanel(); - private static int score = 0; + private final JPanel contentPanel = new JPanel(); + private int score = 0; + private static final int goodOrBadResult = 200; /** * Create the dialog. @@ -33,7 +30,7 @@ public class Endscreen extends JDialog { * @param score the highscore to set */ public Endscreen(int score) { - Endscreen.score = score; + this.score = score; try { // readInHighscoresPoints(); // readInHighscoresPlayers(); @@ -55,7 +52,6 @@ public class Endscreen extends JDialog { } catch (Exception e) { e.printStackTrace(); } - contentPanel.setLayout(null); // JScrollPane scrollPane = new JScrollPane(); // scrollPane.setBounds(10, 412, 349, 238); // contentPanel.add(scrollPane); @@ -78,16 +74,13 @@ public class Endscreen extends JDialog { JButton btnNewButton = new JButton("Play again"); btnNewButton.setMnemonic(KeyEvent.VK_ENTER); - - btnNewButton.addActionListener(e -> { Main.startGame(); setVisible(false); dispose(); }); - // BLOß NICHT RAUSWERFEN + 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.setIconTextGap(5); - // btnNewButton.setIcon(new - // ImageIcon(ClassLoader.getSystemResource("/com/sun/javafx/webkit/prism/resources/mediaPlayDisabled.png"))); // Endscreen.class.getResource("/com/sun/javafx/webkit/prism/resources/mediaPlayDisabled.png"))); btnNewButton.setFont(new Font("Times New Roman", Font.PLAIN, 15)); - btnNewButton.setBounds(85, 512, 243, 100); - contentPanel.add(btnNewButton); + contentPanel.add(btnNewButton, BorderLayout.SOUTH); // JButton btnClose = new JButton("Close game"); // @@ -139,14 +132,17 @@ public class Endscreen extends JDialog { JLabel lblDeinPunktestand = new JLabel("Dein Punktestand: " + String.valueOf(score)); lblDeinPunktestand.setFont(new Font("Times New Roman", Font.PLAIN, 25)); - lblDeinPunktestand.setBounds(10, 45, 291, 50); - contentPanel.add(lblDeinPunktestand); + 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)); @@ -161,10 +157,9 @@ public class Endscreen extends JDialog { // chckbxNewCheckBox.setBounds(300, 200, 250, 210); // lblDasIstEin.setText("Das kannst du aber noch verbessern!"); // lblDasIstEin.setBounds(10, 100, 240, 50); - // contentPanel.add(lblDasIstEin); // } - // contentPanel.add(chckbxNewCheckBox); - // contentPanel.add(lblDasIstEin); + // contentPanel.add(chckbxNewCheckBox, BorderLayout.CENTER); + // contentPanel.add(lblDasIstEin, BorderLayout.EAST); setVisible(true); } @@ -172,13 +167,13 @@ public class Endscreen extends JDialog { * @return the highscore of the current game * @since Snake 1.0 */ - public static int getScore() { return score; } + public int getScore() { return score; } /** * @param score the new highscore * @since Snake 1.0 */ - public static void setScore(int score) { Endscreen.score = score; } + public void setScore(int score) { this.score = score; } /* * public static void readInHighscoresPoints() { try { // FileReader reads text * files in the default encoding. FileReader fileReader = new diff --git a/src/main/dev/lh/ui/GameWindow.java b/src/main/dev/lh/ui/GameWindow.java old mode 100644 new mode 100755 index 087aa47..1afd534 --- a/src/main/dev/lh/ui/GameWindow.java +++ b/src/main/dev/lh/ui/GameWindow.java @@ -44,7 +44,7 @@ public class GameWindow extends JFrame { setMinimumSize(size); setPreferredSize(size); setMaximumSize(size); - setExtendedState(JFrame.MAXIMIZED_BOTH); + setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH); setResizable(false); setDefaultCloseOperation(EXIT_ON_CLOSE); diff --git a/src/main/dev/lh/ui/StartScreen.java b/src/main/dev/lh/ui/StartScreen.java old mode 100644 new mode 100755 diff --git a/src/main/resources/1211548-200.png b/src/main/resources/1211548-200.png old mode 100644 new mode 100755 diff --git a/src/main/resources/Try_Again.jpg b/src/main/resources/Try_Again.jpg old mode 100644 new mode 100755