ole #7

Merged
lgc merged 23 commits from ole into main 2024-11-26 14:01:01 +00:00
3 changed files with 66 additions and 67 deletions
Showing only changes of commit 6ef3b38dd5 - Show all commits

View File

@ -20,10 +20,12 @@ public class MainFrame extends JFrame {
MainMenuView mainMenuView = new MainMenuView(this);
startLocalGame localGame = new startLocalGame(this);
startMultiplayerGame multiplayerGame = new startMultiplayerGame(this);
coinToss coinToss = new coinToss(this);
mainPanel.add(mainMenuView, "MainMenu");
mainPanel.add(localGame, "LocalGame");
mainPanel.add(multiplayerGame, "MultiplayerGame");
mainPanel.add(coinToss, "coinToss");
// Hauptpanel in JFrame hinzufügen
add(mainPanel);

View File

@ -3,36 +3,26 @@ import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class coinToss {
// Frame
private JFrame frame = new JFrame("Zugreihenfolge");
private JPanel mainPanel = new JPanel(new CardLayout()); // Panel mit CardLayout für Szenenwechsel
public class coinToss extends JPanel {
// Funktionshilfen
private JLabel frameTitle = new JLabel("Zugreihenfolge", SwingConstants.CENTER);
private JLabel messageLabel = new JLabel("", SwingConstants.CENTER); // Label für die Nachricht
private JLabel text = new JLabel("", SwingConstants.CENTER); // Label für die Nachricht
private int reihenfolge = 1; // Beispielhaft: 1 = Spieler 1 fängt an, 0 = Spieler 2 fängt an
private Timer timer;
coinToss() {
// Erstelle Frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1500, 1000);
frame.setLocationRelativeTo(null);
// Panel für die Startszene erstellen
JPanel startPanel = new JPanel();
startPanel.setLayout(new BorderLayout());
// Konstruktor
coinToss(MainFrame frame) {
setLayout(null); // Setze das Layout des Panels auf CardLayout
// Nachricht basierend auf 'reihenfolge' einstellen
String startMessage = (reihenfolge == 1)
? "Du fängst an, mach dich bereit..."
: "Dein Gegner fängt an, mach dich bereit...";
messageLabel.setText(startMessage);
messageLabel.setFont(new Font("Arial", Font.BOLD, 24));
startPanel.add(frameTitle, BorderLayout.NORTH);
startPanel.add(messageLabel, BorderLayout.CENTER);
text.setText(startMessage);
text.setFont(new Font("Arial", Font.BOLD, 24));
add(text);
// Panel zur Haupt-Panel hinzufügen
mainPanel.add(startPanel, "start");
frameTitle.setFont(new Font("Arial", Font.BOLD, 32));
// Beispielhaftes "Spielfeld" (nächste Szene)
JPanel gamePanel = new JPanel();
@ -41,12 +31,8 @@ public class coinToss {
gameLabel.setFont(new Font("Arial", Font.BOLD, 36));
gamePanel.add(gameLabel, BorderLayout.CENTER);
// GamePanel zu Haupt-Panel hinzufügen
mainPanel.add(gamePanel, "game");
// Frame-Layout einstellen
frame.add(mainPanel);
frame.setVisible(true);
// Füge das Spiel-Panel zu diesem Panel hinzu
add(gamePanel, "game");
// Timer starten
startTimer();
@ -58,8 +44,8 @@ public class coinToss {
@Override
public void actionPerformed(ActionEvent e) {
// Wechsel zum Spiel-Panel
CardLayout cardLayout = (CardLayout) mainPanel.getLayout();
cardLayout.show(mainPanel, "game");
CardLayout cardLayout = (CardLayout) getLayout();
cardLayout.show(coinToss.this, "game");
timer.stop(); // Timer stoppen
}
});
@ -67,37 +53,3 @@ public class coinToss {
timer.start(); // Timer starten
}
}
/*
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
TODO:
public class coinToss {
// Funktionshilfen
// Frame
JFrame frame = new JFrame("Zugreihenfolge");
// Labels
JLabel frameTitle = new JLabel("Zugreihenfolge");
coinToss() {
// Erstelle Frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1500, 1000);
// Layout Manager (absolute ositionierung)
frame.setLayout(null);
}
}*/

View File

@ -1,5 +1,7 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class startLocalGame extends JPanel {
// Funktionshilfen
@ -107,15 +109,41 @@ public class startLocalGame extends JPanel {
}
});
leftPlayerLeftButton.addActionListener(e -> toggleLeftPlayerIcon());
leftPlayerRightButton.addActionListener(e -> toggleLeftPlayerIcon());
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();
}
});
rightPlayerLeftButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
toggleRightPlayerIcon();
updateTextFields();
}
});
rightPlayerRightButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
toggleRightPlayerIcon();
updateTextFields();
}
});
backButton.addActionListener(e -> frame.showPanel("MainMenu"));
startButton.addActionListener(e -> frame.showPanel("MainMenu")); // TODO ECHTE FUNKTION EINFÜGEN
startButton.addActionListener(e -> frame.showPanel("coinToss")); // TODO ECHTE FUNKTION EINFÜGEN
}
private void toggleLeftPlayerIcon() {
@ -133,4 +161,21 @@ public class startLocalGame extends JPanel {
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("Spieler 1");
} else {
leftPlayerTextField.setText("Leicht");
}
// Rechter Spieler
if (rightPlayerIcon.getIcon() == humanPlayerIcon) {
rightPlayerTextField.setText("Spieler 2");
} else {
rightPlayerTextField.setText("Leicht");
}
}
}