Compare commits
No commits in common. "6f9f5c506362010b9c257bde3d0ad593c531e6a9" and "8a9e7fb4b28394597cc3e6c816b65c47bc2ca50e" have entirely different histories.
6f9f5c5063
...
8a9e7fb4b2
|
@ -5,49 +5,26 @@ import java.awt.event.ActionListener;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
/**
|
|
||||||
* Das JoinGame Panel dient zum setzten des Ports/IP-Adresse.
|
|
||||||
* Anschließend kann das Verbinden Panel gezeigt werden.
|
|
||||||
*/
|
|
||||||
public class JoinGame extends JPanel {
|
public class JoinGame extends JPanel {
|
||||||
// Grafiken
|
|
||||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||||
|
|
||||||
// Labels
|
|
||||||
JLabel spielBeitretenLabel;
|
JLabel spielBeitretenLabel;
|
||||||
JLabel ipLabel = new JLabel("IP-Adresse");
|
JLabel ipLabel = new JLabel("IP-Adresse");
|
||||||
JLabel portLabel = new JLabel("Port");
|
JLabel portLabel = new JLabel("Port");
|
||||||
|
|
||||||
// Textfelder
|
|
||||||
JTextField ipTextField = new JTextField(20);
|
JTextField ipTextField = new JTextField(20);
|
||||||
JTextField portTextField = new JTextField(20);
|
JTextField portTextField = new JTextField(20);
|
||||||
|
|
||||||
// Buttons
|
|
||||||
JButton losButton = new JButton("Los!");
|
JButton losButton = new JButton("Los!");
|
||||||
JButton backButton = new JButton(backButtonIcon);
|
JButton backButton = new JButton(backButtonIcon);
|
||||||
|
|
||||||
// Font
|
|
||||||
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
||||||
|
|
||||||
/**
|
|
||||||
* Erstellt mittels Funktionsaufrufen das Panel.
|
|
||||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
|
||||||
* @param g int-Anzeige, ob es sich um "spiel erstellen" oder "spiel beitreten" handelt.
|
|
||||||
* @param playerType int-Anzeige, ob es sich um einen HumanPlayer,AIEasy... handelt.
|
|
||||||
* @param playerName Name des Spielers
|
|
||||||
*/
|
|
||||||
public JoinGame(MainFrame frame,int g,int playerType,String playerName) {
|
public JoinGame(MainFrame frame,int g,int playerType,String playerName) {
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
buildPanel(frame,g,playerType,playerName);
|
buildPanel(frame,g,playerType,playerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Erstellt das Panel.
|
|
||||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
|
||||||
* @param g int-Anzeige, ob es sich um "spiel erstellen" oder "spiel beitreten" handelt.
|
|
||||||
* @param playerType int-Anzeige, ob es sich um einen HumanPlayer,AIEasy... handelt.
|
|
||||||
* @param playerName Name des Spielers
|
|
||||||
*/
|
|
||||||
private void buildPanel(MainFrame frame,int g,int playerType,String playerName) {
|
private void buildPanel(MainFrame frame,int g,int playerType,String playerName) {
|
||||||
if(g==1){
|
if(g==1){
|
||||||
spielBeitretenLabel= new JLabel("Spiel beitreten");
|
spielBeitretenLabel= new JLabel("Spiel beitreten");
|
||||||
|
@ -65,9 +42,9 @@ public class JoinGame extends JPanel {
|
||||||
ipLabel.setBounds(50, 125, 200, 30);
|
ipLabel.setBounds(50, 125, 200, 30);
|
||||||
ipTextField.setBounds(50, 150, 250, 50);
|
ipTextField.setBounds(50, 150, 250, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
portTextField.setBounds(50, 225, 250, 50);
|
portTextField.setBounds(50, 225, 250, 50);
|
||||||
|
|
||||||
|
|
||||||
spielBeitretenLabel.setFont(robotoFont.deriveFont(50f));
|
spielBeitretenLabel.setFont(robotoFont.deriveFont(50f));
|
||||||
|
|
||||||
add(spielBeitretenLabel);
|
add(spielBeitretenLabel);
|
||||||
|
@ -77,16 +54,11 @@ public class JoinGame extends JPanel {
|
||||||
add(ipTextField);
|
add(ipTextField);
|
||||||
add(portTextField);
|
add(portTextField);
|
||||||
add(backButton);
|
add(backButton);
|
||||||
// ActionListener für Buttons
|
|
||||||
// Um in das MultiplayerGame zurückzuwechseln.
|
|
||||||
backButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
frame.showPanel("MultiplayerGame");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Um das Verbinden Panel anzuzeigen und Daten an Backend weiterzureichen.
|
backButton.addActionListener(e -> frame.showPanel("MultiplayerGame"));
|
||||||
|
//losButton.addActionListener(e -> frame.showPanel("Verbinden"));
|
||||||
|
|
||||||
|
|
||||||
losButton.addActionListener(new ActionListener() {
|
losButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
|
@ -2,13 +2,12 @@ import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
/**
|
// TODO
|
||||||
* Das startLocalGame Panel dient dem Erstellen eines lokalen Spiels.
|
// Evtl. ist Namen selber setzten noch unmöglich
|
||||||
* Hier kann der Benutzer Spieler inklusive Namen und das Semester, in dem sich der Benutzer befindet, einstellen.
|
//
|
||||||
*/
|
|
||||||
public class startLocalGame extends JPanel {
|
public class startLocalGame extends JPanel {
|
||||||
// Player
|
// Player
|
||||||
// TODO: entfernen
|
|
||||||
Player p1;
|
Player p1;
|
||||||
Player p2;
|
Player p2;
|
||||||
|
|
||||||
|
@ -24,7 +23,7 @@ public class startLocalGame extends JPanel {
|
||||||
ImageIcon aiPlayerNormalIcon = new ImageIcon("graphics/botPlayerNormal.png");
|
ImageIcon aiPlayerNormalIcon = new ImageIcon("graphics/botPlayerNormal.png");
|
||||||
ImageIcon aiPlayerHardIcon = new ImageIcon("graphics/botPlayerHard.png");
|
ImageIcon aiPlayerHardIcon = new ImageIcon("graphics/botPlayerHard.png");
|
||||||
|
|
||||||
// Labels
|
// Labels und Buttons
|
||||||
JLabel frameTitle = new JLabel("Lokales Spiel");
|
JLabel frameTitle = new JLabel("Lokales Spiel");
|
||||||
JLabel semesterLabel = new JLabel("Semester");
|
JLabel semesterLabel = new JLabel("Semester");
|
||||||
JLabel leftPlayerName = new JLabel("Name");
|
JLabel leftPlayerName = new JLabel("Name");
|
||||||
|
@ -33,7 +32,6 @@ public class startLocalGame extends JPanel {
|
||||||
JLabel rightPlayerIcon = new JLabel(aiPlayerEasyIcon);
|
JLabel rightPlayerIcon = new JLabel(aiPlayerEasyIcon);
|
||||||
JLabel semesterCounterLabel = new JLabel(String.valueOf(semesterCounter));
|
JLabel semesterCounterLabel = new JLabel(String.valueOf(semesterCounter));
|
||||||
|
|
||||||
// Buttons
|
|
||||||
JButton backButton = new JButton(backButtonIcon);
|
JButton backButton = new JButton(backButtonIcon);
|
||||||
JButton leftPlayerLeftButton = new JButton("<-");
|
JButton leftPlayerLeftButton = new JButton("<-");
|
||||||
JButton leftPlayerRightButton = new JButton("->");
|
JButton leftPlayerRightButton = new JButton("->");
|
||||||
|
@ -44,20 +42,12 @@ public class startLocalGame extends JPanel {
|
||||||
JButton startButton = new JButton("Start!");
|
JButton startButton = new JButton("Start!");
|
||||||
JButton testButton = new JButton("Test");
|
JButton testButton = new JButton("Test");
|
||||||
|
|
||||||
// Textfelder
|
|
||||||
JTextField leftPlayerTextField = new JTextField(20);
|
JTextField leftPlayerTextField = new JTextField(20);
|
||||||
JTextField rightPlayerTextField = new JTextField(20);
|
JTextField rightPlayerTextField = new JTextField(20);
|
||||||
|
|
||||||
/**
|
// Methode zur Erstellung des Panels
|
||||||
* Konstruktor der startLocalGame.
|
|
||||||
* Fügt Buttons, Textfelder und Label hinzu.
|
|
||||||
* Fügt ebenfalls ActionListeners hinzu, damit Buttons etc. ihre gewünschte Funktion haben
|
|
||||||
*
|
|
||||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
|
||||||
*/
|
|
||||||
startLocalGame(MainFrame frame) {
|
startLocalGame(MainFrame frame) {
|
||||||
// Layout des Panels
|
setLayout(null); // Stelle das Layout des Panels ein
|
||||||
setLayout(null);
|
|
||||||
|
|
||||||
// Setze Komponentenpositionen
|
// Setze Komponentenpositionen
|
||||||
frameTitle.setBounds(20, 20, 200, 30);
|
frameTitle.setBounds(20, 20, 200, 30);
|
||||||
|
@ -117,8 +107,8 @@ public class startLocalGame extends JPanel {
|
||||||
rightPlayerTextField.setText(rightPlayerNickname);
|
rightPlayerTextField.setText(rightPlayerNickname);
|
||||||
add(rightPlayerTextField);
|
add(rightPlayerTextField);
|
||||||
|
|
||||||
|
|
||||||
// ActionListener für Buttons
|
// ActionListener für Buttons
|
||||||
// Um das Semester zu erhöhen.
|
|
||||||
semesterUpButton.addActionListener(e -> {
|
semesterUpButton.addActionListener(e -> {
|
||||||
if (semesterCounter < 6) {
|
if (semesterCounter < 6) {
|
||||||
semesterCounter++;
|
semesterCounter++;
|
||||||
|
@ -126,7 +116,6 @@ public class startLocalGame extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Um das Semester zu senken.
|
|
||||||
semesterDownButton.addActionListener(e -> {
|
semesterDownButton.addActionListener(e -> {
|
||||||
if (semesterCounter > 1) {
|
if (semesterCounter > 1) {
|
||||||
semesterCounter--;
|
semesterCounter--;
|
||||||
|
@ -134,7 +123,6 @@ public class startLocalGame extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Um linken Player nach links zu "rotieren".
|
|
||||||
leftPlayerLeftButton.addActionListener(new ActionListener() {
|
leftPlayerLeftButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
@ -143,7 +131,6 @@ public class startLocalGame extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Um linken Player nach rechts zu "rotieren".
|
|
||||||
leftPlayerRightButton.addActionListener(new ActionListener() {
|
leftPlayerRightButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
@ -152,7 +139,6 @@ public class startLocalGame extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Um rechten Player nach links zu "rotieren".
|
|
||||||
rightPlayerLeftButton.addActionListener(new ActionListener() {
|
rightPlayerLeftButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
@ -161,7 +147,6 @@ public class startLocalGame extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Um den rechten Player nach rechts zu "rotieren".
|
|
||||||
rightPlayerRightButton.addActionListener(new ActionListener() {
|
rightPlayerRightButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
@ -170,38 +155,9 @@ public class startLocalGame extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Um Namen des linken Spielers zu speichern.
|
backButton.addActionListener(e -> frame.showPanel("MainMenu"));
|
||||||
leftPlayerTextField.addActionListener(e -> {
|
testButton.addActionListener(e -> frame.showPanelSLG("GameBoard",1,p1,p2));
|
||||||
leftPlayerNickname = leftPlayerTextField.getText();
|
//startButton.addActionListener(e -> frame.showPanelSLG("GameBoard", semesterCounter,p1, p2)); // TODO ECHTE FUNKTION EINFÜGEN
|
||||||
System.out.println("Linker Spielername geändert zu: " + leftPlayerNickname); // Debugging-Ausgabe
|
|
||||||
});
|
|
||||||
|
|
||||||
// Um Namen des linken Spielers zu speichern, auch wenn nicht Enter gedrückt wird.
|
|
||||||
leftPlayerTextField.addFocusListener(new java.awt.event.FocusAdapter() {
|
|
||||||
@Override
|
|
||||||
public void focusLost(java.awt.event.FocusEvent evt) {
|
|
||||||
leftPlayerNickname = leftPlayerTextField.getText();
|
|
||||||
System.out.println("Linker Spielername geändert zu: " + leftPlayerNickname); // Debugging-Ausgabe
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Um zum MainMenu zu wechseln.
|
|
||||||
backButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
frame.showPanel("MainMenu");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Um zum Gameboard zu wechseln.
|
|
||||||
testButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
frame.showPanelSLG("GameBoard",1,p1,p2);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Um zum startLocalGameLoadingScreen zu wechseln und Daten an Backend weiterzureichen.
|
|
||||||
startButton.addActionListener(new ActionListener() {
|
startButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
@ -244,8 +200,7 @@ public class startLocalGame extends JPanel {
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
// Hilfsfunktionen
|
|
||||||
// Setzt das jeweils "nächste" Icon, wenn der leftPlayerLeftButton gedrückt wird.
|
|
||||||
private void toggleLeftPlayerIconLeft() {
|
private void toggleLeftPlayerIconLeft() {
|
||||||
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
leftPlayerIcon.setIcon(aiPlayerHardIcon);
|
leftPlayerIcon.setIcon(aiPlayerHardIcon);
|
||||||
|
@ -258,7 +213,6 @@ public class startLocalGame extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setzt das jeweils "nächste" Icon, wenn der leftPlayerRightButton gedrückt wird.
|
|
||||||
private void toggleLeftPlayerIconRight() {
|
private void toggleLeftPlayerIconRight() {
|
||||||
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
leftPlayerIcon.setIcon(aiPlayerEasyIcon);
|
leftPlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||||
|
@ -271,7 +225,6 @@ public class startLocalGame extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setzt das jeweils "nächste" Icon, wenn der RightPlayerLeftButton gedrückt wird.
|
|
||||||
private void toggleRightPlayerIconLeft() {
|
private void toggleRightPlayerIconLeft() {
|
||||||
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
rightPlayerIcon.setIcon(aiPlayerHardIcon);
|
rightPlayerIcon.setIcon(aiPlayerHardIcon);
|
||||||
|
@ -282,7 +235,6 @@ public class startLocalGame extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setzt das jeweils "nächste" Icon, wenn der RightPlayerRightButton gedrückt wird.
|
|
||||||
private void toggleRightPlayerIconRight() {
|
private void toggleRightPlayerIconRight() {
|
||||||
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
rightPlayerIcon.setIcon(aiPlayerNormalIcon);
|
rightPlayerIcon.setIcon(aiPlayerNormalIcon);
|
||||||
|
@ -293,11 +245,11 @@ public class startLocalGame extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aktualisiert die Textfelder basierend auf den Icons
|
// Methode zum Aktualisieren der Textfelder basierend auf den ausgewählten Icons
|
||||||
private void updateTextFields() {
|
private void updateTextFields() {
|
||||||
// Für Linken Spieler
|
// Linker Spieler
|
||||||
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
leftPlayerTextField.setText(leftPlayerNickname);
|
leftPlayerTextField.setText("Spieler 1");
|
||||||
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
|
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||||
leftPlayerTextField.setText("Einfach");
|
leftPlayerTextField.setText("Einfach");
|
||||||
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
|
@ -306,7 +258,7 @@ public class startLocalGame extends JPanel {
|
||||||
leftPlayerTextField.setText("Schwer");
|
leftPlayerTextField.setText("Schwer");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Für Rechten Spieler
|
// Rechter Spieler
|
||||||
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon){
|
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||||
rightPlayerTextField.setText("Einfach");
|
rightPlayerTextField.setText("Einfach");
|
||||||
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
|
|
|
@ -1,19 +1,9 @@
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
//Kann evtl. als genereller LoadingScreen verwendet werden und nicht "nur" für localGame
|
||||||
/**
|
|
||||||
* Das startLocalGameLoadingScreen Panel dient als "Überblende", während im Backend das Spiel erstellt wird.
|
|
||||||
* Hier wird lediglich Text angezeigt
|
|
||||||
*/
|
|
||||||
public class startLocalGameLoadingScreen extends JPanel{
|
public class startLocalGameLoadingScreen extends JPanel{
|
||||||
/**
|
|
||||||
* Konstruktor der startLocalGameLoadingScreen.
|
|
||||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
|
||||||
* @param semesterCounter Ein Zähler, der das gewählte Semester speichert (hier unbenutzt)
|
|
||||||
*/
|
|
||||||
startLocalGameLoadingScreen(MainFrame frame, int semesterCounter) {
|
startLocalGameLoadingScreen(MainFrame frame, int semesterCounter) {
|
||||||
|
// Layout setzen
|
||||||
// Layout des Panels
|
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
// Label mit dem Text erstellen
|
// Label mit dem Text erstellen
|
||||||
|
@ -21,8 +11,8 @@ public class startLocalGameLoadingScreen extends JPanel{
|
||||||
loadingLabel.setHorizontalAlignment(SwingConstants.CENTER); // Horizontal zentrieren
|
loadingLabel.setHorizontalAlignment(SwingConstants.CENTER); // Horizontal zentrieren
|
||||||
loadingLabel.setVerticalAlignment(SwingConstants.CENTER); // Vertikal zentrieren
|
loadingLabel.setVerticalAlignment(SwingConstants.CENTER); // Vertikal zentrieren
|
||||||
|
|
||||||
// Schriftgröße anpassen
|
// Schriftgröße anpassen (optional)
|
||||||
loadingLabel.setFont(new Font("Roboto", Font.BOLD, 45));
|
loadingLabel.setFont(new Font("Arial", Font.PLAIN, 18));
|
||||||
|
|
||||||
// Label zum Panel hinzufügen
|
// Label zum Panel hinzufügen
|
||||||
add(loadingLabel, BorderLayout.CENTER);
|
add(loadingLabel, BorderLayout.CENTER);
|
||||||
|
|
|
@ -2,16 +2,14 @@ import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
/**
|
// TODO
|
||||||
* Das startMultiplayerGame Panel dient dem Erstellen eines Online Spiels.
|
// Evtl. ist Namen selber setzten noch unmöglich
|
||||||
* Hier kann der Benutzer Spieler inklusive Namen und das Semester, in dem sich der Benutzer befindet, einstellen.
|
//
|
||||||
*/
|
|
||||||
public class startMultiplayerGame extends JPanel {
|
public class startMultiplayerGame extends JPanel {
|
||||||
|
|
||||||
// Funktionshilfen
|
// Funktionshilfen
|
||||||
int semesterCounter = 1;
|
int semesterCounter = 1; // Semester Counter Label
|
||||||
String PlayerNickname = "Spieler 1";
|
String PlayerNickname = "Spieler 1";
|
||||||
|
|
||||||
// Grafiken
|
// Grafiken
|
||||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||||
ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png");
|
ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png");
|
||||||
|
@ -38,18 +36,11 @@ public class startMultiplayerGame extends JPanel {
|
||||||
// Textfelder
|
// Textfelder
|
||||||
JTextField PlayerTextField = new JTextField(20);
|
JTextField PlayerTextField = new JTextField(20);
|
||||||
|
|
||||||
/**
|
// Konstruktor
|
||||||
* Konstruktor der startLocalGame.
|
|
||||||
* Fügt Buttons, Textfelder und Label hinzu.
|
|
||||||
* Fügt ebenfalls ActionListeners hinzu, damit Buttons etc. ihre gewünschte Funktion haben
|
|
||||||
* @param frame Der Mainframe der Anwendung über den alle Panels angezeigt werden.
|
|
||||||
*/
|
|
||||||
startMultiplayerGame(MainFrame frame) {
|
startMultiplayerGame(MainFrame frame) {
|
||||||
|
setLayout(null); // Setze das Layout für das Panel auf null
|
||||||
|
|
||||||
// Layout des Panels
|
// Setze Komponentenpositionen und füge sie dem Panel hinzu
|
||||||
setLayout(null);
|
|
||||||
|
|
||||||
// Setze Komponentenpositionen
|
|
||||||
frameTitle.setBounds(20, 20, 200, 30);
|
frameTitle.setBounds(20, 20, 200, 30);
|
||||||
add(frameTitle);
|
add(frameTitle);
|
||||||
|
|
||||||
|
@ -66,6 +57,7 @@ public class startMultiplayerGame extends JPanel {
|
||||||
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
add(semesterCounterLabel);
|
add(semesterCounterLabel);
|
||||||
|
|
||||||
|
// Füge Buttons hinzu und setze ihre Positionen
|
||||||
backButton.setBounds(1380, 20, 80, 80);
|
backButton.setBounds(1380, 20, 80, 80);
|
||||||
add(backButton);
|
add(backButton);
|
||||||
|
|
||||||
|
@ -87,12 +79,22 @@ public class startMultiplayerGame extends JPanel {
|
||||||
createGameButton.setBounds(1100, 550, 200, 50);
|
createGameButton.setBounds(1100, 550, 200, 50);
|
||||||
add(createGameButton);
|
add(createGameButton);
|
||||||
|
|
||||||
|
// Füge das Textfeld hinzu
|
||||||
PlayerTextField.setBounds(50, 650, 250, 50);
|
PlayerTextField.setBounds(50, 650, 250, 50);
|
||||||
PlayerTextField.setText(PlayerNickname);
|
PlayerTextField.setText(PlayerNickname);
|
||||||
add(PlayerTextField);
|
add(PlayerTextField);
|
||||||
|
|
||||||
|
/* TODO: Muss in Lucas klasse rein.
|
||||||
|
public static void startOnlineGame(Class<? extends LocalPlayer> localPlayerClass, String localPlayerName, InetSocketAddress
|
||||||
|
address, int size) throws IOException {
|
||||||
|
*/
|
||||||
|
|
||||||
|
//GameController.startOnlineGame(...);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ActionListener für Buttons
|
// ActionListener für Buttons
|
||||||
// Um das Semester zu erhöhen.
|
// SEMESTERBUTTONS
|
||||||
semesterUpButton.addActionListener(e -> {
|
semesterUpButton.addActionListener(e -> {
|
||||||
if (semesterCounter < 6) {
|
if (semesterCounter < 6) {
|
||||||
semesterCounter++;
|
semesterCounter++;
|
||||||
|
@ -100,7 +102,6 @@ public class startMultiplayerGame extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Um das Semester zu senken.
|
|
||||||
semesterDownButton.addActionListener(e -> {
|
semesterDownButton.addActionListener(e -> {
|
||||||
if (semesterCounter > 1) {
|
if (semesterCounter > 1) {
|
||||||
semesterCounter--;
|
semesterCounter--;
|
||||||
|
@ -108,46 +109,28 @@ public class startMultiplayerGame extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Um Player nach links zu "rotieren".
|
// PLAYERTOGGLEBUTTONS
|
||||||
PlayerLeftButton.addActionListener(e -> {
|
PlayerLeftButton.addActionListener(e -> {
|
||||||
togglePlayerIconLeft();
|
togglePlayerIconLeft();
|
||||||
updateTextFields();
|
updateTextFields();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Um Player nach rechts zu "rotieren".
|
|
||||||
PlayerRightButton.addActionListener(e -> {
|
PlayerRightButton.addActionListener(e -> {
|
||||||
togglePlayerIconRight();
|
togglePlayerIconRight();
|
||||||
updateTextFields();
|
updateTextFields();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Um Namen des linken Spielers zu speichern.
|
// ActionListener für den "Back" Button, um zum vorherigen Panel zurückzukehren
|
||||||
PlayerTextField.addActionListener(e -> {
|
|
||||||
PlayerNickname = PlayerTextField.getText();
|
|
||||||
System.out.println("Linker Spielername geändert zu: " + PlayerNickname); // Debugging-Ausgabe
|
|
||||||
});
|
|
||||||
|
|
||||||
// Um Namen des linken Spielers zu speichern, auch wenn nicht Enter gedrückt wird.
|
backButton.addActionListener(e -> frame.showPanel("MainMenu"));
|
||||||
PlayerTextField.addFocusListener(new java.awt.event.FocusAdapter() {
|
//joinGameButton.addActionListener(e -> frame.showPanelSMG("JoinGame",1));
|
||||||
@Override
|
//createGameButton.addActionListener(e -> frame.showPanelSMG("JoinGame",0));
|
||||||
public void focusLost(java.awt.event.FocusEvent evt) {
|
|
||||||
PlayerNickname = PlayerTextField.getText();
|
|
||||||
System.out.println("Linker Spielername geändert zu: " + PlayerNickname); // Debugging-Ausgabe
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Um zum MainMenu zu wechseln.
|
|
||||||
backButton.addActionListener(new ActionListener() {
|
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
frame.showPanel("MainMenu");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Um zu JoinGame mit richtigen Parametern zu wechseln.
|
|
||||||
joinGameButton.addActionListener(new ActionListener() {
|
joinGameButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
//Parameter -> panelName, Spiel erstellen oder beitreten (int), Spielertyp(int 0-3), Spielername
|
||||||
|
if (PlayerIcon.getIcon() == humanPlayerIcon) { // TODO Wird name wirklich weitergegeben?
|
||||||
frame.showPanelSMG("JoinGame",1,0, PlayerNickname);
|
frame.showPanelSMG("JoinGame",1,0, PlayerNickname);
|
||||||
} else if ( PlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
} else if ( PlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
frame.showPanelSMG("JoinGame",1,1, PlayerNickname);
|
frame.showPanelSMG("JoinGame",1,1, PlayerNickname);
|
||||||
|
@ -159,7 +142,6 @@ public class startMultiplayerGame extends JPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Um zu JoinGame mit richtigen Parametern zu wechseln.
|
|
||||||
createGameButton.addActionListener(new ActionListener() {
|
createGameButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
@ -175,10 +157,51 @@ public class startMultiplayerGame extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
/*
|
||||||
|
startButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
frame.showPanelSLGLS("startLocalGameLoadingScreen", semesterCounter); //TODO
|
||||||
|
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {// TODO Wird name wirklich weitergegeben?
|
||||||
|
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
|
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
|
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
|
}
|
||||||
|
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
|
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
|
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
|
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
|
}
|
||||||
|
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
|
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
|
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
|
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
|
}
|
||||||
|
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
|
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
|
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerMedium.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
|
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
|
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerHard.class, GameController.semesterToBoardSize(semesterCounter));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hilfsfunktionen
|
}
|
||||||
// Setzt das jeweils "nächste" Icon, wenn der PlayerLeftButton gedrückt wird.
|
});
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
// TOGGLE METHODEN
|
||||||
private void togglePlayerIconLeft() {
|
private void togglePlayerIconLeft() {
|
||||||
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
PlayerIcon.setIcon(aiPlayerHardIcon);
|
PlayerIcon.setIcon(aiPlayerHardIcon);
|
||||||
|
@ -191,7 +214,6 @@ public class startMultiplayerGame extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setzt das jeweils "nächste" Icon, wenn der PlayerRightButton gedrückt wird.
|
|
||||||
private void togglePlayerIconRight() {
|
private void togglePlayerIconRight() {
|
||||||
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
PlayerIcon.setIcon(aiPlayerEasyIcon);
|
PlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||||
|
@ -204,10 +226,9 @@ public class startMultiplayerGame extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aktualisiert die Textfelder basierend auf den Icons
|
|
||||||
private void updateTextFields() {
|
private void updateTextFields() {
|
||||||
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
PlayerTextField.setText(PlayerNickname);
|
PlayerTextField.setText("Spieler 1");
|
||||||
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
|
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||||
PlayerTextField.setText("Einfach");
|
PlayerTextField.setText("Einfach");
|
||||||
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
|
|
Loading…
Reference in New Issue