diff --git a/.idea/libraries/jlayer_1_0_3.xml b/.idea/libraries/jlayer_1_0_3.xml index 2457be1..b09f4ed 100644 --- a/.idea/libraries/jlayer_1_0_3.xml +++ b/.idea/libraries/jlayer_1_0_3.xml @@ -2,6 +2,7 @@ + diff --git a/Grafik/mainmenubackground.png b/Grafik/mainmenubackground.png new file mode 100644 index 0000000..07435cb Binary files /dev/null and b/Grafik/mainmenubackground.png differ diff --git a/Grafik/sound button muted.png b/Grafik/sound button muted.png new file mode 100644 index 0000000..28f0f62 Binary files /dev/null and b/Grafik/sound button muted.png differ diff --git a/Grafik/sound button.png b/Grafik/sound button.png new file mode 100644 index 0000000..3182ef1 Binary files /dev/null and b/Grafik/sound button.png differ diff --git a/graphics/aiPlayer.png b/graphics/aiPlayer.png new file mode 100644 index 0000000..5057fdf Binary files /dev/null and b/graphics/aiPlayer.png differ diff --git a/graphics/backButton.png b/graphics/backButton.png new file mode 100644 index 0000000..92c9647 Binary files /dev/null and b/graphics/backButton.png differ diff --git a/graphics/humanplayer.png b/graphics/humanplayer.png new file mode 100644 index 0000000..3bb39cd Binary files /dev/null and b/graphics/humanplayer.png differ diff --git a/src/HalloSchiffeVersenken.java b/src/HalloSchiffeVersenken.java index 92e952d..eaa1be8 100644 --- a/src/HalloSchiffeVersenken.java +++ b/src/HalloSchiffeVersenken.java @@ -1,10 +1,14 @@ public class HalloSchiffeVersenken { public static void main(String[] args) throws InterruptedException { - + /*Luccas Methoden + MainMenuModel model = new MainMenuModel(); + MainMenuView view = new MainMenuView(); + MainMenuController controller = new MainMenuController(model, view); +*/ System.out.println("HelloSchiffeVersenekn"); - +/* System.out.println("sound"); SoundHandler.playSound("hit"); @@ -13,7 +17,7 @@ public class HalloSchiffeVersenken { SoundHandler.setSoundOn(false); System.out.println("sound off"); SoundHandler.playSound("hit"); - - +*/ + startLocalGame huso = new startLocalGame(); } } diff --git a/src/MainMenuController.java b/src/MainMenuController.java new file mode 100644 index 0000000..4abc54b --- /dev/null +++ b/src/MainMenuController.java @@ -0,0 +1,31 @@ +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.*; + +public class MainMenuController implements ActionListener { + private MainMenuView view; + private MainMenuModel model; + + public MainMenuController(MainMenuModel model, MainMenuView view) { + this.view = view; + this.model = model; + this.view.getLocalButton().addActionListener(this); + this.view.getMultiButton().addActionListener(this); + this.view.getSoundButton().addActionListener(this); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == view.getMultiButton()) { + view.closeWindOw(); + MultiMenuModel model = new MultiMenuModel(); + MultiMenuView view = new MultiMenuView(); + MultiMenuController controller2 = new MultiMenuController(model, view); + } else if (e.getSource() == view.getMultiButton()) { + model.setGameMode("Multiplayer"); + JOptionPane.showMessageDialog(view.getFrame(), "Multiplayer game selected."); + }else if (e.getSource() == view.getSoundButton()) { + view.toggleMute(); + } + } +} \ No newline at end of file diff --git a/src/MainMenuModel.java b/src/MainMenuModel.java new file mode 100644 index 0000000..de9a8d4 --- /dev/null +++ b/src/MainMenuModel.java @@ -0,0 +1,11 @@ +public class MainMenuModel { + private String gameMode; + + public void setGameMode(String mode) { + this.gameMode = mode; + } + + public String getGameMode() { + return gameMode; + } +} \ No newline at end of file diff --git a/src/MainMenuView.java b/src/MainMenuView.java new file mode 100644 index 0000000..a79fafc --- /dev/null +++ b/src/MainMenuView.java @@ -0,0 +1,73 @@ +import java.awt.*; +import javax.swing.JFrame; +import javax.swing.*; + +public class MainMenuView { + ImageIcon SoundIcon = new ImageIcon("Grafik/sound button.png"); + private JFrame frame = new JFrame(); + private JLabel titelLabel = new JLabel("Studium versenken"); + private JButton lokalButton = new JButton("Lokal"); + private JButton multiButton= new JButton("Multiplayer"); + private JButton soundButton = new JButton(SoundIcon); + Font robotoFont = new Font("Roboto", Font.BOLD, 45); + public MainMenuView() { + buildFrame(); + buildComponents(); + + } + + + public void buildComponents(){ + lokalButton.setBounds(200,200,500,500); + multiButton.setBounds(800,200,500,500); + titelLabel.setBounds(550,10,700,100); + soundButton.setBounds(20,20,128,128); + titelLabel.setFont(robotoFont); + lokalButton.setFont(robotoFont.deriveFont(50f)); + multiButton.setFont(robotoFont.deriveFont(50f)); + } + + public void buildFrame() { + frame.setLayout(null); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(1500,1000); + frame.setVisible(true); + frame.getContentPane().setBackground( Color.decode("#98F5FF")); + JLabel backgroundLabel = new JLabel(new ImageIcon("Grafik/mainmenubackground.png")); + frame.setContentPane(backgroundLabel); + frame.add(titelLabel); + frame.add(lokalButton); + frame.add(multiButton); + frame.add(soundButton); + frame.setLocationRelativeTo(null); + } + + public void toggleMute(){ + ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png"); + if(soundButton.getIcon()==SoundIcon) { + soundButton.setIcon(MuteIcon); + }else{ + soundButton.setIcon(SoundIcon); + } + } + + public void closeWindOw(){ + frame.dispose(); + } + public JFrame getFrame() { + return frame; + } + + public JButton getLocalButton() { + return lokalButton; + } + + public JButton getMultiButton() { + return multiButton; + } + + public JButton getSoundButton() { + return soundButton; + } + +} diff --git a/src/MultiMenuController.java b/src/MultiMenuController.java new file mode 100644 index 0000000..ea97136 --- /dev/null +++ b/src/MultiMenuController.java @@ -0,0 +1,21 @@ +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.*; + +public class MultiMenuController implements ActionListener { + private MultiMenuView view; + private MultiMenuModel model; + + public MultiMenuController(MultiMenuModel model, MultiMenuView view) { + this.view = view; + this.model = model; + this.view.getSoundButton().addActionListener(this); + } + + @Override + public void actionPerformed(ActionEvent e) { + if (e.getSource() == view.getSoundButton()) { + view.toggleMute(); + } + } +} \ No newline at end of file diff --git a/src/MultiMenuModel.java b/src/MultiMenuModel.java new file mode 100644 index 0000000..4a8466b --- /dev/null +++ b/src/MultiMenuModel.java @@ -0,0 +1,11 @@ +public class MultiMenuModel { + private String gameMode; + + public void setGameMode(String mode) { + this.gameMode = mode; + } + + public String getGameMode() { + return gameMode; + } +} \ No newline at end of file diff --git a/src/MultiMenuView.java b/src/MultiMenuView.java new file mode 100644 index 0000000..6b1b6b0 --- /dev/null +++ b/src/MultiMenuView.java @@ -0,0 +1,53 @@ +import java.awt.*; +import javax.swing.JFrame; +import javax.swing.*; + +public class MultiMenuView { + ImageIcon SoundIcon = new ImageIcon("Grafik/sound button.png"); + private JFrame frame = new JFrame(); + private JButton soundButton = new JButton(SoundIcon); + Font robotoFont = new Font("Roboto", Font.BOLD, 45); + public MultiMenuView() { + buildFrame(); + buildComponents(); + + } + + + public void buildComponents(){ + soundButton.setBounds(20,20,128,128); + } + + public void buildFrame() { + frame.setLayout(null); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(1500,1000); + frame.setVisible(true); + frame.getContentPane().setBackground( Color.decode("#98F5FF")); + JLabel backgroundLabel = new JLabel(new ImageIcon("Grafik/mainmenubackground.png")); + frame.setContentPane(backgroundLabel); + frame.add(soundButton); + frame.setLocationRelativeTo(null); + } + + public void toggleMute(){ + ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png"); + if(soundButton.getIcon()==SoundIcon) { + soundButton.setIcon(MuteIcon); + }else{ + soundButton.setIcon(SoundIcon); + } + } + + public void closeWindOw(){ + frame.dispose(); + } + public JFrame getFrame() { + return frame; + } + + public JButton getSoundButton() { + return soundButton; + } + +} diff --git a/src/startLocalGame.java b/src/startLocalGame.java new file mode 100644 index 0000000..66212b4 --- /dev/null +++ b/src/startLocalGame.java @@ -0,0 +1,173 @@ +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public class startLocalGame { + // Funktionshilfen + int semesterCounter = 1; // Semester Counter Label + + // Grafiken + ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png"); + ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png"); + ImageIcon aiPlayerIcon = new ImageIcon("graphics/aiPlayer.png"); + + // Frame + JFrame frame = new JFrame("Lokales Spiel"); + + // Labels + JLabel frameTitle = new JLabel("Lokales Spiel"); + JLabel semesterlable = new JLabel("Semester"); + JLabel leftPlayerName = new JLabel("Name"); + JLabel rightPlayerName = new JLabel("KI-Level"); + JLabel leftPlayerIcon = new JLabel(humanPlayerIcon); + JLabel rightPlayerIcon = new JLabel(aiPlayerIcon); + JLabel semesterCounterLabel = new JLabel(String.valueOf(semesterCounter)); + + // Buttons + JButton backButton = new JButton(backButtonIcon); + JButton leftPlayerLeftButton = new JButton("<-"); + JButton leftPlayerRightButton = new JButton("->"); + JButton semesterUpButton = new JButton("^"); + JButton semesterDownButton = new JButton("v"); + JButton rightPlayerLeftButton = new JButton("<-"); + JButton rightPlayerRightButton = new JButton("->"); + JButton startButton = new JButton("Start!"); + + // Textfelder + JTextField leftPlayerTextField = new JTextField(20); + JTextField rightPlayerTextField = new JTextField(20); + startLocalGame() { + // Erstelle Frame + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(1500, 1000); + + // Layout Manager (absolute ositionierung) + frame.setLayout(null); + + // Erstelle Label + frameTitle.setBounds(20, 20, 200, 30); + frame.add(frameTitle); + + semesterlable.setBounds(700, 300, 200, 30); + frame.add(semesterlable); + + leftPlayerName.setBounds(50, 625, 200, 30); + frame.add(leftPlayerName); + + rightPlayerName.setBounds(1200, 625, 200, 30); + frame.add(rightPlayerName); + + leftPlayerIcon.setBounds(75, 400, 200, 128); + frame.add(leftPlayerIcon); + + rightPlayerIcon.setBounds(1225, 400, 200, 128); + frame.add(rightPlayerIcon); + + semesterCounterLabel.setBounds(725, 475, 50, 50); // zwischen den Up/Down-Buttons + semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER); + frame.add(semesterCounterLabel); + + // Erstellt Buttons + backButton.setBounds(1380, 20, 80, 80); + frame.add(backButton); + + leftPlayerLeftButton.setBounds(50, 450, 50, 50); + frame.add(leftPlayerLeftButton); + + leftPlayerRightButton.setBounds(250, 450, 50, 50); + frame.add(leftPlayerRightButton); + + semesterUpButton.setBounds(725, 400, 50, 50); + frame.add(semesterUpButton); + + semesterDownButton.setBounds(725, 550, 50, 50); + frame.add(semesterDownButton); + + rightPlayerLeftButton.setBounds(1200, 450, 50, 50); + frame.add(rightPlayerLeftButton); + + rightPlayerRightButton.setBounds(1400, 450, 50, 50); + frame.add(rightPlayerRightButton); + + startButton.setBounds(700, 750, 100, 50); + frame.add(startButton); + + // Erstellt Textfelder + leftPlayerTextField.setBounds(50, 650, 250, 50); + frame.add(leftPlayerTextField); + + rightPlayerTextField.setBounds(1200, 650, 250, 50); + frame.add(rightPlayerTextField); + + // ActionListener für die Buttons + semesterUpButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (semesterCounter < 6) { + semesterCounter++; + semesterCounterLabel.setText(String.valueOf(semesterCounter)); + } + } + }); + + semesterDownButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (semesterCounter > 1) { // Verhindert, dass der Wert unter 1 fällt + semesterCounter--; + semesterCounterLabel.setText(String.valueOf(semesterCounter)); + } + } + }); + + leftPlayerLeftButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png"); + if(leftPlayerIcon.getIcon()==humanPlayerIcon) { + leftPlayerIcon.setIcon(aiPlayerIcon); + }else{ + leftPlayerIcon.setIcon(humanPlayerIcon); + } + } + }); + + leftPlayerRightButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png"); + if(leftPlayerIcon.getIcon()==humanPlayerIcon) { + leftPlayerIcon.setIcon(aiPlayerIcon); + }else{ + leftPlayerIcon.setIcon(humanPlayerIcon); + } + } + }); + + rightPlayerLeftButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png"); + if(rightPlayerIcon.getIcon()==humanPlayerIcon) { + rightPlayerIcon.setIcon(aiPlayerIcon); + }else{ + rightPlayerIcon.setIcon(humanPlayerIcon); + } + } + }); + + rightPlayerRightButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png"); + if(rightPlayerIcon.getIcon()==humanPlayerIcon) { + rightPlayerIcon.setIcon(aiPlayerIcon); + }else{ + rightPlayerIcon.setIcon(humanPlayerIcon); + } + } + }); + + frame.setVisible(true); + } +}