ole #7
|
@ -2,11 +2,12 @@ public class HalloSchiffeVersenken {
|
|||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
//LUCAS CODE
|
||||
coinToss ct = new coinToss();
|
||||
//coinToss ct = new coinToss();
|
||||
//MainMenuModel model = new MainMenuModel();
|
||||
//MainMenuView view = new MainMenuView();
|
||||
//MainMenuView view = new MainMenuView(new MainFrame());
|
||||
//MainMenuController controller = new MainMenuController(model, view);
|
||||
|
||||
MainFrame mf = new MainFrame();
|
||||
mf.setVisible(true);
|
||||
|
||||
//System.out.println("HelloSchiffeVersenekn");
|
||||
|
||||
|
|
|
@ -9,26 +9,26 @@ public class MainFrame extends JFrame {
|
|||
public MainFrame() {
|
||||
setTitle("Spiel UI mit CardLayout");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setSize(800, 600);
|
||||
setSize(1500, 1000);
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
// Erstelle das CardLayout und das Hauptpanel
|
||||
// CardLayout und Hauptpanel erstellen
|
||||
cardLayout = new CardLayout();
|
||||
mainPanel = new JPanel(cardLayout);
|
||||
|
||||
// Erstelle die verschiedenen Panels
|
||||
MainMenuPanel mainMenuPanel = new MainMenuPanel(this);
|
||||
LocalGamePanel localGamePanel = new LocalGamePanel(this);
|
||||
MultiplayerGamePanel multiplayerGamePanel = new MultiplayerGamePanel(this);
|
||||
// Verschiedene Panels erstellen und hinzufügen
|
||||
MainMenuView mainMenuView = new MainMenuView(this);
|
||||
startLocalGame localGame = new startLocalGame(this);
|
||||
startMultiplayerGame multiplayerGame = new startMultiplayerGame(this);
|
||||
|
||||
// Füge die Panels dem CardLayout hinzu
|
||||
mainPanel.add(mainMenuPanel, "MainMenu");
|
||||
mainPanel.add(localGamePanel, "LocalGame");
|
||||
mainPanel.add(multiplayerGamePanel, "MultiplayerGame");
|
||||
mainPanel.add(mainMenuView, "MainMenu");
|
||||
mainPanel.add(localGame, "LocalGame");
|
||||
mainPanel.add(multiplayerGame, "MultiplayerGame");
|
||||
|
||||
// Setze das Hauptpanel in das JFrame
|
||||
// Hauptpanel in JFrame hinzufügen
|
||||
add(mainPanel);
|
||||
|
||||
// Zeige das Hauptmenü an
|
||||
// Hauptmenü anzeigen
|
||||
cardLayout.show(mainPanel, "MainMenu");
|
||||
}
|
||||
|
||||
|
@ -43,4 +43,4 @@ public class MainFrame extends JFrame {
|
|||
frame.setVisible(true);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,27 +9,27 @@ public class MainMenuController implements ActionListener {
|
|||
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);
|
||||
//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()) {
|
||||
model.setGameMode("Multiplayer");
|
||||
MultiMenuModel multiModel = new MultiMenuModel();
|
||||
MultiMenuView multiView = new MultiMenuView();
|
||||
MultiMenuController multiMenuController = new MultiMenuController(multiModel, multiView);
|
||||
view.addPanel(multiView.getMultiPanel(), "MultiMenu");
|
||||
view.showPanel("MultiMenu");
|
||||
}else if (e.getSource() == view.getSoundButton()) {
|
||||
view.toggleMute();
|
||||
}else if(e.getSource() == view.getLocalButton()) {
|
||||
//if (e.getSource() == view.getMultiButton()) {
|
||||
// model.setGameMode("Multiplayer");
|
||||
// MultiMenuModel multiModel = new MultiMenuModel();
|
||||
// MultiMenuView multiView = new MultiMenuView();
|
||||
// MultiMenuController multiMenuController = new MultiMenuController(multiModel, multiView);
|
||||
// view.addPanel(multiView.getMultiPanel(), "MultiMenu");
|
||||
// view.showPanel("MultiMenu");
|
||||
// }else if (e.getSource() == view.getSoundButton()) {
|
||||
// view.toggleMute();
|
||||
// }else if(e.getSource() == view.getLocalButton()) {
|
||||
model.setGameMode("LocalGame");
|
||||
startLocalGame localGame = new startLocalGame();
|
||||
view.addPanel(localGame.getLocalPanel(), "LocalMenu");
|
||||
view.showPanel("LocalMenu");
|
||||
// view.addPanel(localGame.getLocalPanel(), "LocalMenu");
|
||||
// view.showPanel("LocalMenu");
|
||||
}
|
||||
}
|
||||
}
|
||||
//}
|
|
@ -1,97 +1,51 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.*;
|
||||
|
||||
public class MainMenuView {
|
||||
private JPanel mainPanel = new JPanel(new CardLayout()); // CardLayout for switching
|
||||
private JPanel menuPanel = new JPanel(null);
|
||||
ImageIcon SoundIcon = new ImageIcon("graphics/sound button.png");
|
||||
private JFrame frame = new JFrame();
|
||||
public class MainMenuView extends JPanel {
|
||||
|
||||
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);
|
||||
private JButton multiButton = new JButton("Multiplayer");
|
||||
private JButton soundButton;
|
||||
|
||||
public MainMenuView() {
|
||||
buildFrame();
|
||||
buildPanel();
|
||||
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
||||
private ImageIcon soundIcon = new ImageIcon("graphics/sound button.png");
|
||||
private ImageIcon muteIcon = new ImageIcon("graphics/sound button muted.png");
|
||||
|
||||
public MainMenuView(MainFrame frame) {
|
||||
setLayout(null);
|
||||
buildPanel(frame);
|
||||
}
|
||||
|
||||
public void buildPanel(){
|
||||
mainPanel.add(menuPanel, "MainMenu");
|
||||
private void buildPanel(MainFrame frame) {
|
||||
lokalButton.setBounds(200, 200, 500, 500);
|
||||
multiButton.setBounds(800, 200, 500, 500);
|
||||
titelLabel.setBounds(550, 10, 700, 100);
|
||||
soundButton = new JButton(soundIcon);
|
||||
soundButton.setBounds(20, 20, 128, 128);
|
||||
|
||||
lokalButton.setOpaque(true);
|
||||
multiButton.setOpaque(true);
|
||||
titelLabel.setOpaque(true);
|
||||
soundButton.setOpaque(true);
|
||||
|
||||
titelLabel.setFont(robotoFont);
|
||||
lokalButton.setFont(robotoFont.deriveFont(50f));
|
||||
multiButton.setFont(robotoFont.deriveFont(50f));
|
||||
|
||||
menuPanel.add(titelLabel);
|
||||
menuPanel.add(lokalButton);
|
||||
menuPanel.add(multiButton);
|
||||
menuPanel.add(soundButton);
|
||||
add(titelLabel);
|
||||
add(lokalButton);
|
||||
add(multiButton);
|
||||
add(soundButton);
|
||||
|
||||
//mainPanel.add(menuPanel, "MainMenu");
|
||||
// Event Listener für Buttons
|
||||
lokalButton.addActionListener(e -> frame.showPanel("LocalGame"));
|
||||
multiButton.addActionListener(e -> frame.showPanel("MultiplayerGame"));
|
||||
soundButton.addActionListener(e -> toggleMute());
|
||||
}
|
||||
|
||||
public void showPanel(String panelName) {
|
||||
CardLayout cl = (CardLayout)mainPanel.getLayout();
|
||||
cl.show(mainPanel, panelName);
|
||||
}
|
||||
|
||||
public void addPanel(JPanel panel, String name) {
|
||||
mainPanel.add(panel, name); // Neue Panels hinzufuegen
|
||||
}
|
||||
|
||||
public void buildFrame() {
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setSize(1500, 1000);
|
||||
frame.setLayout(null);
|
||||
|
||||
JLabel backgroundLabel = new JLabel(new ImageIcon("graphics/mainmenubackground.png"));
|
||||
backgroundLabel.setBounds(0, 0, 1500, 1000);
|
||||
mainPanel.setBounds(0, 0, 1500, 1000);
|
||||
// mainPanel.setOpaque(true);
|
||||
|
||||
frame.setContentPane(new JPanel(null));
|
||||
frame.getContentPane().add(backgroundLabel);
|
||||
frame.getContentPane().add(mainPanel);
|
||||
|
||||
frame.setVisible(true);
|
||||
frame.setLocationRelativeTo(null);
|
||||
}
|
||||
|
||||
public void toggleMute(){
|
||||
ImageIcon MuteIcon = new ImageIcon("graphics/sound button muted.png");
|
||||
if(soundButton.getIcon()==SoundIcon) {
|
||||
soundButton.setIcon(MuteIcon);
|
||||
}else{
|
||||
soundButton.setIcon(SoundIcon);
|
||||
private void toggleMute() {
|
||||
if (soundButton.getIcon() == soundIcon) {
|
||||
soundButton.setIcon(muteIcon);
|
||||
} else {
|
||||
soundButton.setIcon(soundIcon);
|
||||
}
|
||||
}
|
||||
|
||||
public JFrame getFrame() {
|
||||
return frame;
|
||||
}
|
||||
|
||||
public JButton getLocalButton() {
|
||||
return lokalButton;
|
||||
}
|
||||
|
||||
public JButton getMultiButton() {
|
||||
return multiButton;
|
||||
}
|
||||
|
||||
public JButton getSoundButton() {
|
||||
return soundButton;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -14,24 +14,15 @@ public class startLocalGame {
|
|||
ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png");
|
||||
ImageIcon aiPlayerIcon = new ImageIcon("graphics/aiPlayer.png");
|
||||
|
||||
// Frame
|
||||
JFrame frame = new JFrame("Lokales Spiel");
|
||||
JPanel mainPanel = new JPanel(new CardLayout());
|
||||
|
||||
// Panels
|
||||
JPanel localGamePanel = new JPanel(); // Panel für das lokale Spiel
|
||||
startMultiplayerGame multiplayerGame = new startMultiplayerGame(); // Instanziere Multiplayer-Klasse
|
||||
|
||||
// Labels
|
||||
// Labels und Buttons
|
||||
JLabel frameTitle = new JLabel("Lokales Spiel");
|
||||
JLabel semesterlable = new JLabel("Semester");
|
||||
JLabel semesterLabel = 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("->");
|
||||
|
@ -41,157 +32,97 @@ public class startLocalGame {
|
|||
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);
|
||||
frame.setLayout(new BorderLayout()); // Haupt-Layout
|
||||
frame.add(mainPanel, BorderLayout.CENTER);
|
||||
|
||||
// Layout Manager (absolute positionierung)
|
||||
frame.setLayout(null);
|
||||
|
||||
// Lokales Spiel Panel erstellen
|
||||
// Methode zur Erstellung des Panels
|
||||
public JPanel createLocalGamePanel(CardLayout cardLayout, JPanel mainPanel) {
|
||||
JPanel localGamePanel = new JPanel();
|
||||
localGamePanel.setLayout(null);
|
||||
|
||||
// Erstelle Label
|
||||
// Setze Komponentenpositionen
|
||||
frameTitle.setBounds(20, 20, 200, 30);
|
||||
frame.add(frameTitle);
|
||||
localGamePanel.add(frameTitle);
|
||||
|
||||
semesterlable.setBounds(700, 300, 200, 30);
|
||||
frame.add(semesterlable);
|
||||
semesterLabel.setBounds(700, 300, 200, 30);
|
||||
localGamePanel.add(semesterLabel);
|
||||
|
||||
leftPlayerName.setBounds(50, 625, 200, 30);
|
||||
frame.add(leftPlayerName);
|
||||
localGamePanel.add(leftPlayerName);
|
||||
|
||||
rightPlayerName.setBounds(1200, 625, 200, 30);
|
||||
frame.add(rightPlayerName);
|
||||
localGamePanel.add(rightPlayerName);
|
||||
|
||||
leftPlayerIcon.setBounds(75, 400, 200, 128);
|
||||
frame.add(leftPlayerIcon);
|
||||
localGamePanel.add(leftPlayerIcon);
|
||||
|
||||
rightPlayerIcon.setBounds(1225, 400, 200, 128);
|
||||
frame.add(rightPlayerIcon);
|
||||
localGamePanel.add(rightPlayerIcon);
|
||||
|
||||
semesterCounterLabel.setBounds(725, 475, 50, 50); // zwischen den Up/Down-Buttons
|
||||
semesterCounterLabel.setBounds(725, 475, 50, 50);
|
||||
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
frame.add(semesterCounterLabel);
|
||||
localGamePanel.add(semesterCounterLabel);
|
||||
|
||||
// Erstellt Buttons
|
||||
backButton.setBounds(1380, 20, 80, 80);
|
||||
frame.add(backButton);
|
||||
localGamePanel.add(backButton);
|
||||
|
||||
leftPlayerLeftButton.setBounds(50, 450, 50, 50);
|
||||
frame.add(leftPlayerLeftButton);
|
||||
localGamePanel.add(leftPlayerLeftButton);
|
||||
|
||||
leftPlayerRightButton.setBounds(250, 450, 50, 50);
|
||||
frame.add(leftPlayerRightButton);
|
||||
localGamePanel.add(leftPlayerRightButton);
|
||||
|
||||
semesterUpButton.setBounds(725, 400, 50, 50);
|
||||
frame.add(semesterUpButton);
|
||||
localGamePanel.add(semesterUpButton);
|
||||
|
||||
semesterDownButton.setBounds(725, 550, 50, 50);
|
||||
frame.add(semesterDownButton);
|
||||
localGamePanel.add(semesterDownButton);
|
||||
|
||||
rightPlayerLeftButton.setBounds(1200, 450, 50, 50);
|
||||
frame.add(rightPlayerLeftButton);
|
||||
localGamePanel.add(rightPlayerLeftButton);
|
||||
|
||||
rightPlayerRightButton.setBounds(1400, 450, 50, 50);
|
||||
frame.add(rightPlayerRightButton);
|
||||
localGamePanel.add(rightPlayerRightButton);
|
||||
|
||||
startButton.setBounds(700, 750, 100, 50);
|
||||
frame.add(startButton);
|
||||
localGamePanel.add(startButton);
|
||||
|
||||
// Erstellt Textfelder
|
||||
leftPlayerTextField.setBounds(50, 650, 250, 50);
|
||||
frame.add(leftPlayerTextField);
|
||||
leftPlayerTextField.setText(leftPlayerNickname);
|
||||
localGamePanel.add(leftPlayerTextField);
|
||||
|
||||
rightPlayerTextField.setBounds(1200, 650, 250, 50);
|
||||
frame.add(rightPlayerTextField);
|
||||
|
||||
//ZUSATZ
|
||||
leftPlayerTextField.setText(leftPlayerNickname);
|
||||
rightPlayerTextField.setText(rightPlayerNickname);
|
||||
localGamePanel.add(rightPlayerTextField);
|
||||
|
||||
// Panels zum CardLayout hinzufügen
|
||||
mainPanel.add(localGamePanel, "localGame");
|
||||
|
||||
// Multiplayer-Panel erstellen und hinzufügen
|
||||
JPanel multiplayerGamePanel = multiplayerGame.createMultiplayerPanel((CardLayout) mainPanel.getLayout(), mainPanel);
|
||||
mainPanel.add(multiplayerGamePanel, "multiplayerGame");
|
||||
|
||||
// ActionListener für den Start-Button
|
||||
startButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// Wechsel zum Multiplayer-Panel
|
||||
CardLayout cardLayout = (CardLayout) mainPanel.getLayout();
|
||||
cardLayout.show(mainPanel, "multiplayerGame");
|
||||
// ActionListener für Buttons
|
||||
semesterUpButton.addActionListener(e -> {
|
||||
if (semesterCounter < 6) {
|
||||
semesterCounter++;
|
||||
semesterCounterLabel.setText(String.valueOf(semesterCounter));
|
||||
}
|
||||
});
|
||||
|
||||
// SEMESTERBUTTONS
|
||||
semesterUpButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (semesterCounter < 6) {
|
||||
semesterCounter++;
|
||||
semesterCounterLabel.setText(String.valueOf(semesterCounter));
|
||||
}
|
||||
semesterDownButton.addActionListener(e -> {
|
||||
if (semesterCounter > 1) {
|
||||
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(e -> toggleLeftPlayerIcon());
|
||||
leftPlayerRightButton.addActionListener(e -> toggleLeftPlayerIcon());
|
||||
|
||||
// PLAYERTOGGLEBUTTONS
|
||||
leftPlayerLeftButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
toggleLeftPlayerIcon();
|
||||
updateTextFields();
|
||||
}
|
||||
});
|
||||
rightPlayerLeftButton.addActionListener(e -> toggleRightPlayerIcon());
|
||||
rightPlayerRightButton.addActionListener(e -> toggleRightPlayerIcon());
|
||||
|
||||
leftPlayerRightButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
toggleLeftPlayerIcon();
|
||||
updateTextFields();
|
||||
}
|
||||
});
|
||||
backButton.addActionListener(e -> cardLayout.show(mainPanel, "MainMenu"));
|
||||
|
||||
rightPlayerLeftButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
toggleRightPlayerIcon();
|
||||
updateTextFields();
|
||||
}
|
||||
});
|
||||
startButton.addActionListener(e -> cardLayout.show(mainPanel, "multiplayerGame"));
|
||||
|
||||
rightPlayerRightButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
toggleRightPlayerIcon();
|
||||
updateTextFields();
|
||||
}
|
||||
});
|
||||
|
||||
frame.setVisible(true);
|
||||
return localGamePanel;
|
||||
}
|
||||
|
||||
// TOGGLE METHODEN
|
||||
private void toggleLeftPlayerIcon() {
|
||||
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||
leftPlayerIcon.setIcon(aiPlayerIcon);
|
||||
|
@ -207,24 +138,4 @@ public class startLocalGame {
|
|||
rightPlayerIcon.setIcon(humanPlayerIcon);
|
||||
}
|
||||
}
|
||||
|
||||
// Methode zum Aktualisieren der Textfelder basierend auf den ausgewählten Icons
|
||||
private void updateTextFields() {
|
||||
// Linker Spieler
|
||||
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||
leftPlayerTextField.setText(leftPlayerNickname);
|
||||
} else {
|
||||
leftPlayerTextField.setText("Leicht");
|
||||
}
|
||||
|
||||
// Rechter Spieler
|
||||
if (rightPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||
rightPlayerTextField.setText(rightPlayerNickname);
|
||||
} else {
|
||||
rightPlayerTextField.setText("Leicht");
|
||||
}
|
||||
}
|
||||
public JPanel getLocalPanel() {
|
||||
return localGamePanel;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue