Added BoardDisplay, startet connecting FrontEnd/BackAnd.
Added new graphics. Added startLocalGameLoadingScreen
This commit is contained in:
parent
f20896566c
commit
48bc601a0d
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,15 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
// Erstellt Spielfeld für Spieler1/Spieler2
|
||||
public class BoardDisplay extends JPanel {
|
||||
public BoardDisplay(int gridSize, Icon buttonIcon) {
|
||||
super(new GridLayout(gridSize, gridSize));
|
||||
|
||||
// Buttons zum Panel hinzufügen
|
||||
for (int i = 0; i < gridSize; i++) {
|
||||
for (int j = 0; j < gridSize; j++) {
|
||||
add(new JButton(buttonIcon));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@ public class GameBoard extends JPanel {
|
|||
JButton leftPlayerModul5 = new JButton("Modul 5");
|
||||
JButton leftPlayerModul6 = new JButton("Modul 6");
|
||||
JButton leftPlayerModul7 = new JButton("Reset");
|
||||
|
||||
// Gegnerische ModulButtons
|
||||
JButton rightPlayerModul1 = new JButton("Modul 1");
|
||||
JButton rightPlayerModul2 = new JButton("Modul 2");
|
||||
|
@ -68,10 +69,14 @@ public class GameBoard extends JPanel {
|
|||
rightButtonsPanel.add(rightPlayerModul7);
|
||||
|
||||
// Spielfelder erstellen (eigenes und gegnerisches)
|
||||
int gridSize = 13 + semesterCounter; // Größe des Spielfelds
|
||||
JPanel ownBoardPanel = new JPanel(new GridLayout(gridSize, gridSize));
|
||||
JPanel opponentBoardPanel = new JPanel(new GridLayout(gridSize, gridSize));
|
||||
int gridSize = GameController.semesterToBoardSize(semesterCounter); // Größe des Spielfelds
|
||||
// Spielfelder werden in BoardDisplay erstellt
|
||||
//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);
|
||||
|
||||
/* Alter code ohne BoardDisplay
|
||||
// Buttons für das eigene Spielfeld hinzufügen
|
||||
for (int i = 0; i < gridSize; i++) {
|
||||
for (int j = 0; j < gridSize; j++) {
|
||||
|
@ -85,6 +90,7 @@ public class GameBoard extends JPanel {
|
|||
opponentBoardPanel.add(new JButton(gameBoardEmtpy));
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Panel für beide Spielfelder (nebeneinander in der Mitte)
|
||||
JPanel centerPanel = new JPanel();
|
||||
|
@ -99,7 +105,7 @@ public class GameBoard extends JPanel {
|
|||
add(centerPanel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
GameBoard(MainFrame frame,int semesterCounter) {
|
||||
GameBoard(MainFrame frame, int semesterCounter,Player p1, Player p2) {
|
||||
buildPanel(frame, semesterCounter);
|
||||
/*
|
||||
rightPlayerRightButton.addActionListener(new ActionListener() {
|
||||
|
|
|
@ -35,6 +35,7 @@ public class MainFrame extends JFrame {
|
|||
// Verschiedene Panels erstellen und hinzufügen
|
||||
MainMenuView mainMenuView = new MainMenuView(this);
|
||||
startLocalGame localGame = new startLocalGame(this);
|
||||
//startLocalGameLoadingScreen LocalGameLoadingScreen = new startLocalGameLoadingScreen(this);
|
||||
startMultiplayerGame multiplayerGame = new startMultiplayerGame(this);
|
||||
coinToss coinToss = new coinToss(this);
|
||||
Verbinden verbinden = new Verbinden(this);
|
||||
|
@ -60,6 +61,7 @@ public class MainFrame extends JFrame {
|
|||
public void showPanel(String panelName) {
|
||||
cardLayout.show(mainPanel, panelName);
|
||||
}
|
||||
|
||||
// --- ShowPanel der startMultiplayerGame Klasse
|
||||
public void showPanelSMG(String panelName, int num) {
|
||||
this.localMult = num;
|
||||
|
@ -73,12 +75,14 @@ public class MainFrame extends JFrame {
|
|||
|
||||
cardLayout.show(mainPanel, panelName); // Show the panel
|
||||
}
|
||||
// --- ShowPanel der startLocalGame Klasse
|
||||
public void showPanelSLG(String panelName,int semesterCounter) {
|
||||
this.semesterCounter = semesterCounter;
|
||||
// --- ShowPanel der startLocalGameLoadingScreen Klasse (DURCH BACKEND AUFGERUFEN)
|
||||
public void showPanelSLG(String panelName,int semesterCounter, Player p1, Player p2) {
|
||||
this.semesterCounter = semesterCounter;
|
||||
|
||||
//if (!isPanelPresent(panelName)) { //TODO potentiell raus
|
||||
GameBoard gameBoard = new GameBoard(this, semesterCounter);
|
||||
//if (!isPanelPresent(panelName)) { //TODO potentiell raus
|
||||
// gameBoard muss player übergeben bekommen
|
||||
GameBoard gameBoard = new GameBoard(this, semesterCounter, p1, p2);
|
||||
//mainPanel.add(mainMenuView, "MainMenu");
|
||||
mainPanel.add(gameBoard, panelName);
|
||||
mainPanel.revalidate(); // Refresh
|
||||
mainPanel.repaint();
|
||||
|
@ -86,6 +90,20 @@ public class MainFrame extends JFrame {
|
|||
|
||||
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?
|
||||
private boolean isPanelPresent(String panelName) {
|
||||
for (Component component : mainPanel.getComponents()) {
|
||||
|
@ -96,6 +114,20 @@ public class MainFrame extends JFrame {
|
|||
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) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
MainFrame frame = new MainFrame();
|
||||
|
|
|
@ -3,6 +3,10 @@ import java.awt.event.ActionEvent;
|
|||
import java.awt.event.ActionListener;
|
||||
|
||||
public class startLocalGame extends JPanel {
|
||||
// Player
|
||||
//Player p1;
|
||||
//Player p2;
|
||||
|
||||
// Funktionshilfen
|
||||
int semesterCounter = 1; // Semester Counter Label
|
||||
String leftPlayerNickname = "Spieler 1";
|
||||
|
@ -11,7 +15,9 @@ public class startLocalGame extends JPanel {
|
|||
// Grafiken
|
||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.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
|
||||
JLabel frameTitle = new JLabel("Lokales Spiel");
|
||||
|
@ -19,7 +25,7 @@ public class startLocalGame extends JPanel {
|
|||
JLabel leftPlayerName = new JLabel("Name");
|
||||
JLabel rightPlayerName = new JLabel("KI-Level");
|
||||
JLabel leftPlayerIcon = new JLabel(humanPlayerIcon);
|
||||
JLabel rightPlayerIcon = new JLabel(aiPlayerIcon);
|
||||
JLabel rightPlayerIcon = new JLabel(aiPlayerEasyIcon);
|
||||
JLabel semesterCounterLabel = new JLabel(String.valueOf(semesterCounter));
|
||||
|
||||
JButton backButton = new JButton(backButtonIcon);
|
||||
|
@ -93,6 +99,7 @@ public class startLocalGame extends JPanel {
|
|||
rightPlayerTextField.setText(rightPlayerNickname);
|
||||
add(rightPlayerTextField);
|
||||
|
||||
|
||||
// ActionListener für Buttons
|
||||
semesterUpButton.addActionListener(e -> {
|
||||
if (semesterCounter < 6) {
|
||||
|
@ -142,12 +149,67 @@ public class startLocalGame extends JPanel {
|
|||
|
||||
backButton.addActionListener(e -> frame.showPanel("MainMenu"));
|
||||
|
||||
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 Diverse KiIcons erstellen für diffs
|
||||
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, SpecificAiPlayerEasy.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, SpecificAiPlayerEasy.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, SpecificAiPlayerEasy.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, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
// GameController.startLocalGame(SpecificAiPlayerEasy.class, rightPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
// TODO Zwischenscreen einfügen ("Spiel wird erstellt")
|
||||
/*
|
||||
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {// TODO Diverse KiIcons erstellen für diffs
|
||||
if (rightPlayerIcon.getIcon() == aiPlayerIcon) { // Platzhalter da nur eine KI gerade exisitert
|
||||
//...
|
||||
GameController.startLocalGame(HumanPlayer.class, leftPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
}
|
||||
} else if (leftPlayerIcon.getIcon() == aiPlayerIcon) {
|
||||
//...
|
||||
GameController.startLocalGame(SpecificAiPlayerEasy.class, rightPlayerNickname, SpecificAiPlayerEasy.class, GameController.semesterToBoardSize(semesterCounter));
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void toggleLeftPlayerIcon() {
|
||||
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||
leftPlayerIcon.setIcon(aiPlayerIcon);
|
||||
leftPlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||
} else {
|
||||
leftPlayerIcon.setIcon(humanPlayerIcon);
|
||||
}
|
||||
|
@ -155,7 +217,7 @@ public class startLocalGame extends JPanel {
|
|||
|
||||
private void toggleRightPlayerIcon() {
|
||||
if (rightPlayerIcon.getIcon() == humanPlayerIcon) {
|
||||
rightPlayerIcon.setIcon(aiPlayerIcon);
|
||||
rightPlayerIcon.setIcon(aiPlayerEasyIcon);
|
||||
} else {
|
||||
rightPlayerIcon.setIcon(humanPlayerIcon);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
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,4 +1,6 @@
|
|||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public class startMultiplayerGame extends JPanel {
|
||||
// Funktionshilfen
|
||||
|
@ -76,7 +78,16 @@ public class startMultiplayerGame extends JPanel {
|
|||
PlayerTextField.setText(PlayerNickname);
|
||||
add(PlayerTextField);
|
||||
|
||||
// ActionListener für Buttons
|
||||
/* 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
|
||||
// SEMESTERBUTTONS
|
||||
semesterUpButton.addActionListener(e -> {
|
||||
if (semesterCounter < 6) {
|
||||
|
|
Loading…
Reference in New Issue