Merge pull request 'lucasjoshua' (#12) from lucasjoshua into main
Reviewed-on: #12
This commit is contained in:
commit
6118d480d9
Binary file not shown.
After Width: | Height: | Size: 854 B |
Binary file not shown.
After Width: | Height: | Size: 875 B |
Binary file not shown.
After Width: | Height: | Size: 889 B |
|
@ -0,0 +1,54 @@
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
|
||||||
|
public class BoardDisplay extends JPanel {
|
||||||
|
public BoardDisplay(int gridSize, Icon buttonIcon) {
|
||||||
|
super(new GridLayout(gridSize + 1, gridSize + 1)); // +1 wegen extra Zeile/Splate
|
||||||
|
|
||||||
|
// Erstellung von Spielfeld
|
||||||
|
for (int i = 0; i <= gridSize; i++) {
|
||||||
|
for (int j = 0; j <= gridSize; j++) {
|
||||||
|
if (i == 0 && j == 0) {
|
||||||
|
add(new JLabel(" "));
|
||||||
|
} else if (i == 0) {
|
||||||
|
JLabel colLabel = new JLabel(String.valueOf(j));
|
||||||
|
colLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
colLabel.setFont(new Font("Arial", Font.BOLD, 14));
|
||||||
|
add(colLabel);
|
||||||
|
} else if (j == 0) {
|
||||||
|
JLabel rowLabel = new JLabel(String.valueOf((char) ('A' + i - 1)));
|
||||||
|
rowLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
|
rowLabel.setFont(new Font("Arial", Font.BOLD, 14));
|
||||||
|
add(rowLabel);
|
||||||
|
} else {
|
||||||
|
// Spielfeld (interaktive Zellen)
|
||||||
|
JButton field = new JButton("");
|
||||||
|
field.setBackground(Color.LIGHT_GRAY);
|
||||||
|
field.setOpaque(true);
|
||||||
|
field.setBorderPainted(true);
|
||||||
|
|
||||||
|
field.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
if(SwingUtilities.isRightMouseButton(e)) {
|
||||||
|
handleFieldClick(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mouseExited(MouseEvent e) {
|
||||||
|
// field.setBackground(Color.LIGHT_GRAY);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
add(field);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleFieldClick(JButton field) {
|
||||||
|
field.setBackground(Color.RED);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
|
import javafx.scene.control.ToggleGroup;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
@ -19,21 +21,22 @@ public class GameBoard extends JPanel {
|
||||||
|
|
||||||
JButton backButton = new JButton(backButtonIcon);
|
JButton backButton = new JButton(backButtonIcon);
|
||||||
// Eigene ModulButtons
|
// Eigene ModulButtons
|
||||||
JButton leftPlayerModul1 = new JButton("Modul 1"); //TODO: Dynamische Namen durch abgleich mit Semester
|
JToggleButton leftPlayerModul1 = new JToggleButton("Modul 1"); //TODO: Dynamische Namen durch abgleich mit Semester
|
||||||
JButton leftPlayerModul2 = new JButton("Modul 2");
|
JToggleButton leftPlayerModul2 = new JToggleButton("Modul 2");
|
||||||
JButton leftPlayerModul3 = new JButton("Modul 3");
|
JToggleButton leftPlayerModul3 = new JToggleButton("Modul 3");
|
||||||
JButton leftPlayerModul4 = new JButton("Modul 4");
|
JToggleButton leftPlayerModul4 = new JToggleButton("Modul 4");
|
||||||
JButton leftPlayerModul5 = new JButton("Modul 5");
|
JToggleButton leftPlayerModul5 = new JToggleButton("Modul 5");
|
||||||
JButton leftPlayerModul6 = new JButton("Modul 6");
|
JToggleButton leftPlayerModul6 = new JToggleButton("Modul 6");
|
||||||
JButton leftPlayerModul7 = new JButton("Reset");
|
JToggleButton leftPlayerModul7 = new JToggleButton("Reset");
|
||||||
|
|
||||||
// Gegnerische ModulButtons
|
// Gegnerische ModulButtons
|
||||||
JButton rightPlayerModul1 = new JButton("Modul 1");
|
JToggleButton rightPlayerModul1 = new JToggleButton("Modul 1");
|
||||||
JButton rightPlayerModul2 = new JButton("Modul 2");
|
JToggleButton rightPlayerModul2 = new JToggleButton("Modul 2");
|
||||||
JButton rightPlayerModul3 = new JButton("Modul 3");
|
JToggleButton rightPlayerModul3 = new JToggleButton("Modul 3");
|
||||||
JButton rightPlayerModul4 = new JButton("Modul 4");
|
JToggleButton rightPlayerModul4 = new JToggleButton("Modul 4");
|
||||||
JButton rightPlayerModul5 = new JButton("Modul 5");
|
JToggleButton rightPlayerModul5 = new JToggleButton("Modul 5");
|
||||||
JButton rightPlayerModul6 = new JButton("Modul 6");
|
JToggleButton rightPlayerModul6 = new JToggleButton("Modul 6");
|
||||||
JButton rightPlayerModul7 = new JButton("Bereit");
|
JToggleButton rightPlayerModul7 = new JToggleButton("Bereit");
|
||||||
|
|
||||||
public void buildPanel(MainFrame frame, int semesterCounter) {
|
public void buildPanel(MainFrame frame, int semesterCounter) {
|
||||||
// Hauptlayout - BorderLayout für die Anordnung der Komponenten
|
// Hauptlayout - BorderLayout für die Anordnung der Komponenten
|
||||||
|
@ -68,23 +71,31 @@ public class GameBoard extends JPanel {
|
||||||
rightButtonsPanel.add(rightPlayerModul7);
|
rightButtonsPanel.add(rightPlayerModul7);
|
||||||
|
|
||||||
// Spielfelder erstellen (eigenes und gegnerisches)
|
// Spielfelder erstellen (eigenes und gegnerisches)
|
||||||
int gridSize = 13 + semesterCounter; // Größe des Spielfelds
|
int gridSize = GameController.semesterToBoardSize(semesterCounter); // Größe des Spielfelds
|
||||||
JPanel ownBoardPanel = new JPanel(new GridLayout(gridSize, gridSize));
|
// Spielfelder werden in BoardDisplay erstellt
|
||||||
JPanel opponentBoardPanel = new JPanel(new GridLayout(gridSize, gridSize));
|
//JPanel ownBoardPanel = new JPanel(new GridLayout(gridSize, gridSize));
|
||||||
|
//JPanel opponentBoardPanel = new JPanel(new GridLayout(gridSize, gridSize));
|
||||||
|
JPanel ownBoardPanel = new BoardDisplay(gridSize, gameBoardEmtpy);
|
||||||
|
JPanel opponentBoardPanel = new BoardDisplay(gridSize, gameBoardEmtpy);
|
||||||
|
|
||||||
// Buttons für das eigene Spielfeld hinzufügen
|
//Buttons in eine Gruppe packen damit diese beim drücken eines anderen Buttons wieder entwählt werden
|
||||||
for (int i = 0; i < gridSize; i++) {
|
ButtonGroup leftButtonGroup= new ButtonGroup();
|
||||||
for (int j = 0; j < gridSize; j++) {
|
leftButtonGroup.add(rightPlayerModul1);
|
||||||
ownBoardPanel.add(new JButton(gameBoardEmtpy));
|
leftButtonGroup.add(rightPlayerModul2);
|
||||||
}
|
leftButtonGroup.add(rightPlayerModul3);
|
||||||
}
|
leftButtonGroup.add(rightPlayerModul4);
|
||||||
|
leftButtonGroup.add(rightPlayerModul5);
|
||||||
|
leftButtonGroup.add(rightPlayerModul6);
|
||||||
|
leftButtonGroup.add(rightPlayerModul7);
|
||||||
|
|
||||||
// Buttons für das gegnerische Spielfeld hinzufügen
|
ButtonGroup rightButtonGroup= new ButtonGroup();
|
||||||
for (int i = 0; i < gridSize; i++) {
|
rightButtonGroup.add(leftPlayerModul1);
|
||||||
for (int j = 0; j < gridSize; j++) {
|
rightButtonGroup.add(leftPlayerModul2);
|
||||||
opponentBoardPanel.add(new JButton(gameBoardEmtpy));
|
rightButtonGroup.add(leftPlayerModul3);
|
||||||
}
|
rightButtonGroup.add(leftPlayerModul4);
|
||||||
}
|
rightButtonGroup.add(leftPlayerModul5);
|
||||||
|
rightButtonGroup.add(leftPlayerModul6);
|
||||||
|
rightButtonGroup.add(leftPlayerModul7);
|
||||||
|
|
||||||
// Panel für beide Spielfelder (nebeneinander in der Mitte)
|
// Panel für beide Spielfelder (nebeneinander in der Mitte)
|
||||||
JPanel centerPanel = new JPanel();
|
JPanel centerPanel = new JPanel();
|
||||||
|
@ -99,7 +110,7 @@ public class GameBoard extends JPanel {
|
||||||
add(centerPanel, BorderLayout.CENTER);
|
add(centerPanel, BorderLayout.CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameBoard(MainFrame frame,int semesterCounter) {
|
GameBoard(MainFrame frame, int semesterCounter,Player p1, Player p2) {
|
||||||
buildPanel(frame, semesterCounter);
|
buildPanel(frame, semesterCounter);
|
||||||
/*
|
/*
|
||||||
rightPlayerRightButton.addActionListener(new ActionListener() {
|
rightPlayerRightButton.addActionListener(new ActionListener() {
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
/*
|
||||||
|
TODO: evtl an Lucas: die "JoinGame" muss noch informationen erhalten, welche Spieler erstellt wurden und welches Semester
|
||||||
|
Also die startMultiplayerGame muss JoinGame mit parametern für (HumanPlayer/AiEasy/AiNormal/AiHard, Semesteranzahl, Spielername) (3 Parameter) erhalten
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
public class JoinGame extends JPanel {
|
public class JoinGame extends JPanel {
|
||||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||||
|
@ -51,5 +60,19 @@ public class JoinGame extends JPanel {
|
||||||
|
|
||||||
backButton.addActionListener(e -> frame.showPanel("MultiplayerGame"));
|
backButton.addActionListener(e -> frame.showPanel("MultiplayerGame"));
|
||||||
losButton.addActionListener(e -> frame.showPanel("Verbinden"));
|
losButton.addActionListener(e -> frame.showPanel("Verbinden"));
|
||||||
|
/*
|
||||||
|
losButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
frame.showPanel("Verbinden");
|
||||||
|
//public static void startOnlineGame(Class<? extends LocalPlayer> localPlayerClass, String localPlayerName, InetSocketAddress
|
||||||
|
// address, int size) throws IOException {
|
||||||
|
if(playerType == 1) { //Beispiel (für playertape wäre z.B. 1 humanPlayer etc.)
|
||||||
|
GameController.startOnlineGame(HumanPlayer.class, playerName, adress); //
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -11,7 +11,8 @@ public class MainFrame extends JFrame {
|
||||||
// Von startMultiplayerGame an JoinGame
|
// Von startMultiplayerGame an JoinGame
|
||||||
int localMult;
|
int localMult;
|
||||||
|
|
||||||
// Von startLocalGame an GameBoard
|
// Von startLocalGame an startLocalGameLoadingScreen
|
||||||
|
// Von startLocalGameLoadingScreen an GameBoard
|
||||||
int semesterCounter;
|
int semesterCounter;
|
||||||
// ---------- //
|
// ---------- //
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ public class MainFrame extends JFrame {
|
||||||
// Verschiedene Panels erstellen und hinzufügen
|
// Verschiedene Panels erstellen und hinzufügen
|
||||||
MainMenuView mainMenuView = new MainMenuView(this);
|
MainMenuView mainMenuView = new MainMenuView(this);
|
||||||
startLocalGame localGame = new startLocalGame(this);
|
startLocalGame localGame = new startLocalGame(this);
|
||||||
|
//startLocalGameLoadingScreen LocalGameLoadingScreen = new startLocalGameLoadingScreen(this);
|
||||||
startMultiplayerGame multiplayerGame = new startMultiplayerGame(this);
|
startMultiplayerGame multiplayerGame = new startMultiplayerGame(this);
|
||||||
coinToss coinToss = new coinToss(this);
|
coinToss coinToss = new coinToss(this);
|
||||||
Verbinden verbinden = new Verbinden(this);
|
Verbinden verbinden = new Verbinden(this);
|
||||||
|
@ -60,6 +62,7 @@ public class MainFrame extends JFrame {
|
||||||
public void showPanel(String panelName) {
|
public void showPanel(String panelName) {
|
||||||
cardLayout.show(mainPanel, panelName);
|
cardLayout.show(mainPanel, panelName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- ShowPanel der startMultiplayerGame Klasse
|
// --- ShowPanel der startMultiplayerGame Klasse
|
||||||
public void showPanelSMG(String panelName, int num) {
|
public void showPanelSMG(String panelName, int num) {
|
||||||
this.localMult = num;
|
this.localMult = num;
|
||||||
|
@ -73,12 +76,14 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
cardLayout.show(mainPanel, panelName); // Show the panel
|
cardLayout.show(mainPanel, panelName); // Show the panel
|
||||||
}
|
}
|
||||||
// --- ShowPanel der startLocalGame Klasse
|
// --- ShowPanel der startLocalGameLoadingScreen Klasse (DURCH BACKEND AUFGERUFEN)
|
||||||
public void showPanelSLG(String panelName,int semesterCounter) {
|
public void showPanelSLG(String panelName,int semesterCounter, Player p1, Player p2) {
|
||||||
this.semesterCounter = semesterCounter;
|
this.semesterCounter = semesterCounter;
|
||||||
|
|
||||||
//if (!isPanelPresent(panelName)) { //TODO potentiell raus
|
//if (!isPanelPresent(panelName)) { //TODO potentiell raus
|
||||||
GameBoard gameBoard = new GameBoard(this, semesterCounter);
|
// gameBoard muss player übergeben bekommen
|
||||||
|
GameBoard gameBoard = new GameBoard(this, semesterCounter, p1, p2);
|
||||||
|
//mainPanel.add(mainMenuView, "MainMenu");
|
||||||
mainPanel.add(gameBoard, panelName);
|
mainPanel.add(gameBoard, panelName);
|
||||||
mainPanel.revalidate(); // Refresh
|
mainPanel.revalidate(); // Refresh
|
||||||
mainPanel.repaint();
|
mainPanel.repaint();
|
||||||
|
@ -86,6 +91,20 @@ public class MainFrame extends JFrame {
|
||||||
|
|
||||||
cardLayout.show(mainPanel, panelName); // Show the panel
|
cardLayout.show(mainPanel, panelName); // Show the panel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- ShowPanel der startLocalGame Klasse
|
||||||
|
public void showPanelSLGLS(String panelName,int semesterCounter) {
|
||||||
|
this.semesterCounter = semesterCounter;
|
||||||
|
// gameBoard muss player übergeben bekommen
|
||||||
|
startLocalGameLoadingScreen LocalGameLoadingScreen = new startLocalGameLoadingScreen(this, semesterCounter);
|
||||||
|
mainPanel.add(LocalGameLoadingScreen, panelName);
|
||||||
|
mainPanel.revalidate(); // Refresh
|
||||||
|
mainPanel.repaint();
|
||||||
|
//}
|
||||||
|
|
||||||
|
cardLayout.show(mainPanel, panelName); // Show the panel
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO ist dies unnötig?
|
/* TODO ist dies unnötig?
|
||||||
private boolean isPanelPresent(String panelName) {
|
private boolean isPanelPresent(String panelName) {
|
||||||
for (Component component : mainPanel.getComponents()) {
|
for (Component component : mainPanel.getComponents()) {
|
||||||
|
@ -96,6 +115,20 @@ public class MainFrame extends JFrame {
|
||||||
return false;
|
return false;
|
||||||
} */
|
} */
|
||||||
|
|
||||||
|
// Methoden für übergabe von playern an GameBoard
|
||||||
|
/*
|
||||||
|
public void setPlayerData() {
|
||||||
|
this.semesterCounter = semesterCounter;
|
||||||
|
|
||||||
|
//if (!isPanelPresent(panelName)) { //TODO potentiell raus
|
||||||
|
// gameBoard muss player übergeben bekommen
|
||||||
|
GameBoard gameBoard = new GameBoard(this, semesterCounter);
|
||||||
|
mainPanel.add(gameBoard, panelName);
|
||||||
|
mainPanel.revalidate(); // Refresh
|
||||||
|
mainPanel.repaint();
|
||||||
|
}*/
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
MainFrame frame = new MainFrame();
|
MainFrame frame = new MainFrame();
|
||||||
|
|
|
@ -2,16 +2,26 @@ import javax.swing.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// Evtl. ist Namen selber setzten noch unmöglich
|
||||||
|
//
|
||||||
|
|
||||||
public class startLocalGame extends JPanel {
|
public class startLocalGame extends JPanel {
|
||||||
|
// Player
|
||||||
|
Player p1;
|
||||||
|
Player p2;
|
||||||
|
|
||||||
// Funktionshilfen
|
// Funktionshilfen
|
||||||
int semesterCounter = 1; // Semester Counter Label
|
int semesterCounter = 1; // Semester Counter Label
|
||||||
String leftPlayerNickname = "Spieler 1";
|
String leftPlayerNickname = "Spieler 1";
|
||||||
String rightPlayerNickname = "Spieler 2";
|
String rightPlayerNickname = "Einfach";
|
||||||
|
|
||||||
// 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");
|
||||||
ImageIcon aiPlayerIcon = new ImageIcon("graphics/aiPlayer.png");
|
ImageIcon aiPlayerEasyIcon = new ImageIcon("graphics/botPlayerEasy.png");
|
||||||
|
ImageIcon aiPlayerNormalIcon = new ImageIcon("graphics/botPlayerNormal.png");
|
||||||
|
ImageIcon aiPlayerHardIcon = new ImageIcon("graphics/botPlayerHard.png");
|
||||||
|
|
||||||
// Labels und Buttons
|
// Labels und Buttons
|
||||||
JLabel frameTitle = new JLabel("Lokales Spiel");
|
JLabel frameTitle = new JLabel("Lokales Spiel");
|
||||||
|
@ -19,7 +29,7 @@ public class startLocalGame extends JPanel {
|
||||||
JLabel leftPlayerName = new JLabel("Name");
|
JLabel leftPlayerName = new JLabel("Name");
|
||||||
JLabel rightPlayerName = new JLabel("KI-Level");
|
JLabel rightPlayerName = new JLabel("KI-Level");
|
||||||
JLabel leftPlayerIcon = new JLabel(humanPlayerIcon);
|
JLabel leftPlayerIcon = new JLabel(humanPlayerIcon);
|
||||||
JLabel rightPlayerIcon = new JLabel(aiPlayerIcon);
|
JLabel rightPlayerIcon = new JLabel(aiPlayerEasyIcon);
|
||||||
JLabel semesterCounterLabel = new JLabel(String.valueOf(semesterCounter));
|
JLabel semesterCounterLabel = new JLabel(String.valueOf(semesterCounter));
|
||||||
|
|
||||||
JButton backButton = new JButton(backButtonIcon);
|
JButton backButton = new JButton(backButtonIcon);
|
||||||
|
@ -30,6 +40,7 @@ public class startLocalGame extends JPanel {
|
||||||
JButton rightPlayerLeftButton = new JButton("<-");
|
JButton rightPlayerLeftButton = new JButton("<-");
|
||||||
JButton rightPlayerRightButton = new JButton("->");
|
JButton rightPlayerRightButton = new JButton("->");
|
||||||
JButton startButton = new JButton("Start!");
|
JButton startButton = new JButton("Start!");
|
||||||
|
JButton testButton = new JButton("Test");
|
||||||
|
|
||||||
JTextField leftPlayerTextField = new JTextField(20);
|
JTextField leftPlayerTextField = new JTextField(20);
|
||||||
JTextField rightPlayerTextField = new JTextField(20);
|
JTextField rightPlayerTextField = new JTextField(20);
|
||||||
|
@ -61,6 +72,9 @@ public class startLocalGame extends JPanel {
|
||||||
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||||
add(semesterCounterLabel);
|
add(semesterCounterLabel);
|
||||||
|
|
||||||
|
testButton.setBounds(500,800,50,50);
|
||||||
|
add(testButton);
|
||||||
|
|
||||||
backButton.setBounds(1380, 20, 80, 80);
|
backButton.setBounds(1380, 20, 80, 80);
|
||||||
add(backButton);
|
add(backButton);
|
||||||
|
|
||||||
|
@ -93,6 +107,7 @@ public class startLocalGame extends JPanel {
|
||||||
rightPlayerTextField.setText(rightPlayerNickname);
|
rightPlayerTextField.setText(rightPlayerNickname);
|
||||||
add(rightPlayerTextField);
|
add(rightPlayerTextField);
|
||||||
|
|
||||||
|
|
||||||
// ActionListener für Buttons
|
// ActionListener für Buttons
|
||||||
semesterUpButton.addActionListener(e -> {
|
semesterUpButton.addActionListener(e -> {
|
||||||
if (semesterCounter < 6) {
|
if (semesterCounter < 6) {
|
||||||
|
@ -111,7 +126,7 @@ public class startLocalGame extends JPanel {
|
||||||
leftPlayerLeftButton.addActionListener(new ActionListener() {
|
leftPlayerLeftButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
toggleLeftPlayerIcon();
|
toggleLeftPlayerIconLeft();
|
||||||
updateTextFields();
|
updateTextFields();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -119,7 +134,7 @@ public class startLocalGame extends JPanel {
|
||||||
leftPlayerRightButton.addActionListener(new ActionListener() {
|
leftPlayerRightButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
toggleLeftPlayerIcon();
|
toggleLeftPlayerIconRight();
|
||||||
updateTextFields();
|
updateTextFields();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -127,7 +142,7 @@ public class startLocalGame extends JPanel {
|
||||||
rightPlayerLeftButton.addActionListener(new ActionListener() {
|
rightPlayerLeftButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
toggleRightPlayerIcon();
|
toggleRightPlayerIconLeft();
|
||||||
updateTextFields();
|
updateTextFields();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -135,29 +150,98 @@ public class startLocalGame extends JPanel {
|
||||||
rightPlayerRightButton.addActionListener(new ActionListener() {
|
rightPlayerRightButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
toggleRightPlayerIcon();
|
toggleRightPlayerIconRight();
|
||||||
updateTextFields();
|
updateTextFields();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
backButton.addActionListener(e -> frame.showPanel("MainMenu"));
|
backButton.addActionListener(e -> frame.showPanel("MainMenu"));
|
||||||
|
testButton.addActionListener(e -> frame.showPanelSLG("GameBoard",1,p1,p2));
|
||||||
startButton.addActionListener(e -> frame.showPanelSLG("GameBoard", semesterCounter)); // TODO ECHTE FUNKTION EINFÜGEN
|
//startButton.addActionListener(e -> frame.showPanelSLG("GameBoard", semesterCounter,p1, p2)); // TODO ECHTE FUNKTION EINFÜGEN
|
||||||
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleLeftPlayerIcon() {
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleLeftPlayerIconLeft() {
|
||||||
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
leftPlayerIcon.setIcon(aiPlayerIcon);
|
leftPlayerIcon.setIcon(aiPlayerHardIcon);
|
||||||
} else {
|
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||||
|
leftPlayerIcon.setIcon(humanPlayerIcon);
|
||||||
|
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
|
leftPlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||||
|
} else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
|
leftPlayerIcon.setIcon(aiPlayerNormalIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleLeftPlayerIconRight() {
|
||||||
|
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
|
leftPlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||||
|
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||||
|
leftPlayerIcon.setIcon(aiPlayerNormalIcon);
|
||||||
|
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
|
leftPlayerIcon.setIcon(aiPlayerHardIcon);
|
||||||
|
} else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
leftPlayerIcon.setIcon(humanPlayerIcon);
|
leftPlayerIcon.setIcon(humanPlayerIcon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleRightPlayerIcon() {
|
private void toggleRightPlayerIconLeft() {
|
||||||
if (rightPlayerIcon.getIcon() == humanPlayerIcon) {
|
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
rightPlayerIcon.setIcon(aiPlayerIcon);
|
rightPlayerIcon.setIcon(aiPlayerHardIcon);
|
||||||
} else {
|
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){
|
||||||
rightPlayerIcon.setIcon(humanPlayerIcon);
|
rightPlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||||
|
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
|
rightPlayerIcon.setIcon(aiPlayerNormalIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleRightPlayerIconRight() {
|
||||||
|
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
|
||||||
|
rightPlayerIcon.setIcon(aiPlayerNormalIcon);
|
||||||
|
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){
|
||||||
|
rightPlayerIcon.setIcon(aiPlayerHardIcon);
|
||||||
|
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
|
rightPlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,15 +250,21 @@ public class startLocalGame extends JPanel {
|
||||||
// Linker Spieler
|
// Linker Spieler
|
||||||
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
leftPlayerTextField.setText("Spieler 1");
|
leftPlayerTextField.setText("Spieler 1");
|
||||||
} else {
|
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||||
leftPlayerTextField.setText("Leicht");
|
leftPlayerTextField.setText("Einfach");
|
||||||
|
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
|
leftPlayerTextField.setText("Mittel");
|
||||||
|
} else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
|
leftPlayerTextField.setText("Schwer");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rechter Spieler
|
// Rechter Spieler
|
||||||
if (rightPlayerIcon.getIcon() == humanPlayerIcon) {
|
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||||
rightPlayerTextField.setText("Spieler 2");
|
rightPlayerTextField.setText("Einfach");
|
||||||
} else {
|
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
rightPlayerTextField.setText("Leicht");
|
rightPlayerTextField.setText("Mittel");
|
||||||
|
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
|
rightPlayerTextField.setText("Schwer");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
|
//Kann evtl. als genereller LoadingScreen verwendet werden und nicht "nur" für localGame
|
||||||
|
public class startLocalGameLoadingScreen extends JPanel{
|
||||||
|
startLocalGameLoadingScreen(MainFrame frame, int semesterCounter) {
|
||||||
|
// Layout setzen
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
|
// Label mit dem Text erstellen
|
||||||
|
JLabel loadingLabel = new JLabel("Spiel wird gestartet, bitte warten...");
|
||||||
|
loadingLabel.setHorizontalAlignment(SwingConstants.CENTER); // Horizontal zentrieren
|
||||||
|
loadingLabel.setVerticalAlignment(SwingConstants.CENTER); // Vertikal zentrieren
|
||||||
|
|
||||||
|
// Schriftgröße anpassen (optional)
|
||||||
|
loadingLabel.setFont(new Font("Arial", Font.PLAIN, 18));
|
||||||
|
|
||||||
|
// Label zum Panel hinzufügen
|
||||||
|
add(loadingLabel, BorderLayout.CENTER);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,9 @@
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// Evtl. ist Namen selber setzten noch unmöglich
|
||||||
|
//
|
||||||
|
|
||||||
public class startMultiplayerGame extends JPanel {
|
public class startMultiplayerGame extends JPanel {
|
||||||
// Funktionshilfen
|
// Funktionshilfen
|
||||||
int semesterCounter = 1; // Semester Counter Label
|
int semesterCounter = 1; // Semester Counter Label
|
||||||
|
@ -7,7 +11,9 @@ public class startMultiplayerGame extends JPanel {
|
||||||
// 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");
|
||||||
ImageIcon aiPlayerIcon = new ImageIcon("graphics/aiPlayer.png");
|
ImageIcon aiPlayerEasyIcon = new ImageIcon("graphics/botPlayerEasy.png");
|
||||||
|
ImageIcon aiPlayerNormalIcon = new ImageIcon("graphics/botPlayerNormal.png");
|
||||||
|
ImageIcon aiPlayerHardIcon = new ImageIcon("graphics/botPlayerHard.png");
|
||||||
|
|
||||||
// Labels
|
// Labels
|
||||||
JLabel frameTitle = new JLabel("Multiplayer Spiel");
|
JLabel frameTitle = new JLabel("Multiplayer Spiel");
|
||||||
|
@ -76,6 +82,15 @@ public class startMultiplayerGame extends JPanel {
|
||||||
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
|
||||||
// SEMESTERBUTTONS
|
// SEMESTERBUTTONS
|
||||||
semesterUpButton.addActionListener(e -> {
|
semesterUpButton.addActionListener(e -> {
|
||||||
|
@ -94,12 +109,12 @@ public class startMultiplayerGame extends JPanel {
|
||||||
|
|
||||||
// PLAYERTOGGLEBUTTONS
|
// PLAYERTOGGLEBUTTONS
|
||||||
PlayerLeftButton.addActionListener(e -> {
|
PlayerLeftButton.addActionListener(e -> {
|
||||||
toggleLeftPlayerIcon();
|
togglePlayerIconLeft();
|
||||||
updateTextFields();
|
updateTextFields();
|
||||||
});
|
});
|
||||||
|
|
||||||
PlayerRightButton.addActionListener(e -> {
|
PlayerRightButton.addActionListener(e -> {
|
||||||
toggleLeftPlayerIcon();
|
togglePlayerIconRight();
|
||||||
updateTextFields();
|
updateTextFields();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -111,19 +126,39 @@ public class startMultiplayerGame extends JPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TOGGLE METHODEN
|
// TOGGLE METHODEN
|
||||||
private void toggleLeftPlayerIcon() {
|
private void togglePlayerIconLeft() {
|
||||||
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
PlayerIcon.setIcon(aiPlayerIcon);
|
PlayerIcon.setIcon(aiPlayerHardIcon);
|
||||||
} else {
|
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||||
|
PlayerIcon.setIcon(humanPlayerIcon);
|
||||||
|
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
|
PlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||||
|
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
|
PlayerIcon.setIcon(aiPlayerNormalIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void togglePlayerIconRight() {
|
||||||
|
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
|
PlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||||
|
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||||
|
PlayerIcon.setIcon(aiPlayerNormalIcon);
|
||||||
|
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
|
PlayerIcon.setIcon(aiPlayerHardIcon);
|
||||||
|
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
PlayerIcon.setIcon(humanPlayerIcon);
|
PlayerIcon.setIcon(humanPlayerIcon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTextFields() {
|
private void updateTextFields() {
|
||||||
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
if (PlayerIcon.getIcon() == humanPlayerIcon) {
|
||||||
PlayerTextField.setText(PlayerNickname);
|
PlayerTextField.setText("Spieler 1");
|
||||||
} else {
|
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
|
||||||
PlayerTextField.setText("Leicht");
|
PlayerTextField.setText("Einfach");
|
||||||
|
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
|
||||||
|
PlayerTextField.setText("Mittel");
|
||||||
|
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
|
||||||
|
PlayerTextField.setText("Schwer");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue