diff --git a/Programmierung2/src/Git/Erstelle ein Repo.pdf b/Programmierung2/src/Git/Erstelle ein Repo.pdf new file mode 100644 index 0000000..9405141 Binary files /dev/null and b/Programmierung2/src/Git/Erstelle ein Repo.pdf differ diff --git a/Programmierung2/src/Git/Git Skripte.odt b/Programmierung2/src/Git/Git Skripte.odt deleted file mode 100644 index a38a232..0000000 Binary files a/Programmierung2/src/Git/Git Skripte.odt and /dev/null differ diff --git a/Programmierung2/src/Git/Repo History.pdf b/Programmierung2/src/Git/Repo History.pdf new file mode 100644 index 0000000..c1e9844 Binary files /dev/null and b/Programmierung2/src/Git/Repo History.pdf differ diff --git a/Programmierung2/src/Logging/Test.java b/Programmierung2/src/Logging/Test.java new file mode 100644 index 0000000..1b28d75 --- /dev/null +++ b/Programmierung2/src/Logging/Test.java @@ -0,0 +1,12 @@ +package Logging; + +import java.util.logging.Level; +import java.util.logging.Logger; +public class Test { + + public static void main(String[] args) { + + + } + +} diff --git a/Programmierung2/src/Übungen/Pac_Man/GameContainer.java b/Programmierung2/src/Übungen/Pac_Man/GameContainer.java index 2b060d5..6fae328 100644 --- a/Programmierung2/src/Übungen/Pac_Man/GameContainer.java +++ b/Programmierung2/src/Übungen/Pac_Man/GameContainer.java @@ -11,8 +11,8 @@ public class GameContainer extends JPanel implements Runnable { final static int WIDTH_WINDOW = 1000; final static int HEIGH_WINDOW = 700; Dimension fensterSize = new Dimension(WIDTH_WINDOW,HEIGH_WINDOW); - PacMan pacman; + Geist[] geists = new Geist[3]; ArrayList waende; @@ -29,7 +29,7 @@ public class GameContainer extends JPanel implements Runnable { GameContainer(){ this.waende = new ArrayList<>(); draw_waende(); - draw_PacMan(); + draw_pacman(); this.setFocusable(true); this.setPreferredSize(fensterSize); this.addKeyListener(new Steuern()); @@ -38,7 +38,7 @@ public class GameContainer extends JPanel implements Runnable { } - public void draw_PacMan() { + public void draw_pacman() { pacman = new PacMan(WIDTH_WINDOW/2,HEIGH_WINDOW/2); } @@ -67,8 +67,8 @@ public class GameContainer extends JPanel implements Runnable { for (SpielKarte w:waende ) w.draw(g); - // Zeige Pacman - pacman.draw(g); + pacman.draw(g); + } @@ -85,11 +85,18 @@ public class GameContainer extends JPanel implements Runnable { } - if (pacman.y <= 5 || pacman.x <= 5) { - pacman.set_x_bewegung(0); + if (pacman.y <= 5 ) { pacman.set_y_bewegung(0); } + if (pacman.x < 0) + pacman.x = WIDTH_WINDOW ; + + if (pacman.x < 0) + pacman.x = WIDTH_WINDOW ; + + + } @Override @@ -100,7 +107,7 @@ public class GameContainer extends JPanel implements Runnable { move(); checkKollision(); repaint(); - Thread.sleep(25); + Thread.sleep(20); } catch (InterruptedException e) { e.printStackTrace(); } diff --git a/Programmierung2/src/Übungen/Pac_Man/PacMan.java b/Programmierung2/src/Übungen/Pac_Man/PacMan.java index b5c998f..a150517 100644 --- a/Programmierung2/src/Übungen/Pac_Man/PacMan.java +++ b/Programmierung2/src/Übungen/Pac_Man/PacMan.java @@ -3,63 +3,114 @@ package Übungen.Pac_Man; import java.awt.*; import java.awt.event.KeyEvent; +import javax.swing.ImageIcon; + public class PacMan extends Rectangle { - private static int pacMan_width = 20; - private static int pacMan_height = 20; - private int ybewegung; - private int xbewegung; - private int speed = 8; + private static int pacMan_width = 30; + private static int pacMan_height = 30; + private int ybewegung; + private int xbewegung; + private int speed = 8; + + Image[] pacmanImagesRight; + Image[] pacmanImagesLeft; + Image[] pacmanImagesUp; + Image[] pacmanImagesDown; - PacMan(int x, int y) { + Image currentImage; + int animationIndex = 0; + long lastTime = System.nanoTime(); + + PacMan(int x, int y) { + super(x, y, pacMan_width, pacMan_height); + + pacmanImagesRight = new Image[]{ + new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Pac_Man\\Pacman\\pacmanright.png").getImage(), + new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Pac_Man\\Pacman\\pacmanopenright.png").getImage() + }; + pacmanImagesLeft = new Image[]{ + new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Pac_Man\\Pacman\\pacmanleft.png").getImage(), + new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Pac_Man\\Pacman\\pacmanopenleft.png").getImage() + }; + pacmanImagesUp = new Image[]{ + new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Pac_Man\\Pacman\\pacmanup.png").getImage(), + new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Pac_Man\\Pacman\\pacmanopenup.png").getImage() + }; + pacmanImagesDown = new Image[]{ + new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Pac_Man\\Pacman\\pacmandown.png").getImage(), + new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Pac_Man\\Pacman\\pacmanopendown.png").getImage() + }; - super(x, y, pacMan_width, pacMan_height); - } + // Standardmäßig das rechte Bild anzeigen + currentImage = pacmanImagesRight[0]; + } - public void draw(Graphics g) { - g.setColor(Color.GREEN); - g.fillRect(x, y, pacMan_width, pacMan_height); - } + public void draw(Graphics g) { + long currentTime = System.nanoTime(); + // Alle 200ms zwischen den zwei Animation-Bildern wechseln + if ((currentTime - lastTime) > 200_000_000) { + animationIndex = (animationIndex + 1) % 2; // 0 -> 1 -> 0 wechseln + lastTime = currentTime; + } + + // Je nach Bewegung das passende Bild setzen + if (xbewegung > 0) + currentImage = pacmanImagesRight[animationIndex]; + else if (xbewegung < 0) + currentImage = pacmanImagesLeft[animationIndex]; + else if (ybewegung > 0) + currentImage = pacmanImagesDown[animationIndex]; + else if (ybewegung < 0) + currentImage = pacmanImagesUp[animationIndex]; + + + g.drawImage(currentImage, x, y, pacMan_width, pacMan_height, null); + } - public void keyPressed(KeyEvent e) { - if (e.getKeyCode() == KeyEvent.VK_W) { - set_y_bewegung(-speed); - set_x_bewegung(0); - } + public void keyPressed(KeyEvent e) { + if (e.getKeyCode() == KeyEvent.VK_W) { + currentImage = pacmanImagesUp[animationIndex]; + set_y_bewegung(-speed); + set_x_bewegung(0); + } + if (e.getKeyCode() == KeyEvent.VK_S) { + currentImage = pacmanImagesDown[animationIndex]; + set_y_bewegung(speed); + set_x_bewegung(0); + } + if (e.getKeyCode() == KeyEvent.VK_D) { + currentImage = pacmanImagesRight[animationIndex]; + set_y_bewegung(0); + set_x_bewegung(speed); + } + if (e.getKeyCode() == KeyEvent.VK_A) { + currentImage = pacmanImagesLeft[animationIndex]; + set_y_bewegung(0); + set_x_bewegung(-speed); + } + } - if (e.getKeyCode() == KeyEvent.VK_S) { - set_y_bewegung(speed); - set_x_bewegung(0); - } + public void set_y_bewegung(int y) { + this.ybewegung = y; + } + + public void set_x_bewegung(int x) { + this.xbewegung = x; + } - if (e.getKeyCode() == KeyEvent.VK_D) { - set_y_bewegung(0); - set_x_bewegung(speed); - } + // Bewegung updaten + public void move() { + y += ybewegung; + x += xbewegung; + } - if (e.getKeyCode() == KeyEvent.VK_A) { - set_y_bewegung(0); - set_x_bewegung(-speed); - } - - } - - public void set_y_bewegung(int y) { - this.ybewegung = y; - } - - public void set_x_bewegung(int x) { - this.xbewegung = x; - } - - public void move() { - y += ybewegung; - x += xbewegung; - } - - public void check_kollision() { - - } + public void check_kollision(int windowWidth, int windowHeight) { + if (x < 0) x = 0; + if (y < 0) y = 0; + if (x + pacMan_width > windowWidth) x = windowWidth - pacMan_width; + if (y + pacMan_height > windowHeight) y = windowHeight - pacMan_height; + } } diff --git a/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanclosed.png b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanclosed.png new file mode 100644 index 0000000..6b89fc9 Binary files /dev/null and b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanclosed.png differ diff --git a/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmandown.png b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmandown.png new file mode 100644 index 0000000..3193f0f Binary files /dev/null and b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmandown.png differ diff --git a/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanleft.png b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanleft.png new file mode 100644 index 0000000..c849fcc Binary files /dev/null and b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanleft.png differ diff --git a/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanopendown.png b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanopendown.png new file mode 100644 index 0000000..62dfc89 Binary files /dev/null and b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanopendown.png differ diff --git a/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanopenleft.png b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanopenleft.png new file mode 100644 index 0000000..4f5d872 Binary files /dev/null and b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanopenleft.png differ diff --git a/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanopenright.png b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanopenright.png new file mode 100644 index 0000000..b944cab Binary files /dev/null and b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanopenright.png differ diff --git a/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanopenup.png b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanopenup.png new file mode 100644 index 0000000..5049dfc Binary files /dev/null and b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanopenup.png differ diff --git a/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanright.png b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanright.png new file mode 100644 index 0000000..a0924af Binary files /dev/null and b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanright.png differ diff --git a/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanup.png b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanup.png new file mode 100644 index 0000000..b93e564 Binary files /dev/null and b/Programmierung2/src/Übungen/Pac_Man/Pacman/pacmanup.png differ diff --git a/Programmierung2/src/Übungen/Pac_Man/test.java b/Programmierung2/src/Übungen/Pac_Man/test.java index 1ad5650..6162f6f 100644 --- a/Programmierung2/src/Übungen/Pac_Man/test.java +++ b/Programmierung2/src/Übungen/Pac_Man/test.java @@ -1,35 +1,61 @@ package Übungen.Pac_Man; import java.awt.EventQueue; +import java.util.ArrayList; +import javax.swing.ImageIcon; import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.border.EmptyBorder; import javax.swing.JLabel; -import javax.swing.JSlider; -import javax.swing.JTree; -public class test extends JFrame { +public class test extends JFrame implements Runnable { + + Thread test; + ArrayList pacman; + JLabel setman; + int currentImageIndex = 0; // Um den aktuellen Index des Bildes zu verfolgen - private static final long serialVersionUID = 1L; - private JPanel contentPane; + test() { + setman = new JLabel(); + pacman = new ArrayList<>(); + // Bilder zur Liste hinzufügen + pacman.add(new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Pac_Man\\Pacman\\pacmanright.png")); + pacman.add(new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Pac_Man\\Pacman\\pacmanopenright.png")); +// pacman.add(new ImageIcon("C:\\Users\\obaya\\git\\Programmierung2\\Programmierung2\\src\\Übungen\\Pac_Man\\Pacman\\pacmandown.png")); - public test() { - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - setBounds(100, 100, 1000, 700); - contentPane = new JPanel(); - contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + this.setTitle("Pacman Animation"); + this.setSize(700, 700); + this.setResizable(false); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + this.setLocationRelativeTo(null); + this.add(setman); - setContentPane(contentPane); - contentPane.setLayout(null); + // Thread starten + test = new Thread(this); + test.start(); - JLabel lblNewLabel = new JLabel("New label"); - lblNewLabel.setBounds(230, 257, 169, 22); - contentPane.add(lblNewLabel); - - JLabel lblNewLabel_1 = new JLabel("New label"); - lblNewLabel_1.setBounds(230, 95, 46, 144); - contentPane.add(lblNewLabel_1); + this.setVisible(true); + } + + public static void main(String[] args) { + new test(); + } + + public void zeigePacMan() { + setman.setIcon(pacman.get(currentImageIndex)); + // Erhöht den Index und stellt sicher, dass er nicht größer als die Liste wird + currentImageIndex = (currentImageIndex + 1) % pacman.size(); + } + + @Override + public void run() { + while (true) { + try { + zeigePacMan(); + Thread.sleep(300); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } } } diff --git a/Programmierung2/src/Übungen/Ponggame/GamePanle.java b/Programmierung2/src/Übungen/Ponggame/GamePanle.java index 2b9a9ac..4f3aa5b 100644 --- a/Programmierung2/src/Übungen/Ponggame/GamePanle.java +++ b/Programmierung2/src/Übungen/Ponggame/GamePanle.java @@ -70,7 +70,7 @@ public class GamePanle extends JPanel implements Runnable { g.setFont(new Font("Arial", Font.BOLD, 20)); g.setColor(Color.YELLOW); g.drawString("ComputerGegener", WIDTH_WINDOW/2 + 100, 35); - + } public void mov() {