Network and Frontend #10
Binary file not shown.
After Width: | Height: | Size: 84 B |
Binary file not shown.
After Width: | Height: | Size: 171 B |
|
@ -1,3 +1,114 @@
|
|||
public class GameBoard {
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class GameBoard extends JPanel {
|
||||
// Funktionshilfen
|
||||
//int semesterCounter = 1; //TODO: ersetzen durch param von vorpanel
|
||||
|
||||
// Grafiken
|
||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||
ImageIcon gameBoardEmtpy = new ImageIcon("graphics/gameboardempty.png");
|
||||
ImageIcon gameBoardX = new ImageIcon("graphics/gameboardx.png");
|
||||
|
||||
// Labels
|
||||
JLabel frameTitle = new JLabel("GameBoard");
|
||||
JLabel kontextText = new JLabel("Beispielhafter Kontext-Text");
|
||||
//kontextText.setFont(new Font("Roboto", Font.BOLD, 24)); //TODO setFont fixen
|
||||
|
||||
JButton backButton = new JButton(backButtonIcon);
|
||||
// Eigene ModulButtons
|
||||
JButton leftPlayerModul1 = new JButton("Modul 1"); //TODO: Dynamische Namen durch abgleich mit Semester
|
||||
JButton leftPlayerModul2 = new JButton("Modul 2");
|
||||
JButton leftPlayerModul3 = new JButton("Modul 3");
|
||||
JButton leftPlayerModul4 = new JButton("Modul 4");
|
||||
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");
|
||||
JButton rightPlayerModul3 = new JButton("Modul 3");
|
||||
JButton rightPlayerModul4 = new JButton("Modul 4");
|
||||
JButton rightPlayerModul5 = new JButton("Modul 5");
|
||||
JButton rightPlayerModul6 = new JButton("Modul 6");
|
||||
JButton rightPlayerModul7 = new JButton("Bereit");
|
||||
|
||||
public void buildPanel(MainFrame frame, int semesterCounter) {
|
||||
// Hauptlayout - BorderLayout für die Anordnung der Komponenten
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
// Panel für das Kontext-Text-Feld
|
||||
JPanel headerPanel = new JPanel();
|
||||
headerPanel.setLayout(new BorderLayout());
|
||||
headerPanel.add(kontextText, BorderLayout.WEST);
|
||||
headerPanel.add(backButton, BorderLayout.EAST);
|
||||
|
||||
// Panel für die Buttons des linken Spielers (ganz links)
|
||||
JPanel leftButtonsPanel = new JPanel();
|
||||
leftButtonsPanel.setLayout(new GridLayout(7, 1)); // 6 Buttons untereinander
|
||||
leftButtonsPanel.add(leftPlayerModul1);
|
||||
leftButtonsPanel.add(leftPlayerModul2);
|
||||
leftButtonsPanel.add(leftPlayerModul3);
|
||||
leftButtonsPanel.add(leftPlayerModul4);
|
||||
leftButtonsPanel.add(leftPlayerModul5);
|
||||
leftButtonsPanel.add(leftPlayerModul6);
|
||||
leftButtonsPanel.add(leftPlayerModul7);
|
||||
|
||||
// Panel für die Buttons des rechten Spielers (ganz rechts)
|
||||
JPanel rightButtonsPanel = new JPanel();
|
||||
rightButtonsPanel.setLayout(new GridLayout(7, 1)); // 6 Buttons untereinander
|
||||
rightButtonsPanel.add(rightPlayerModul1);
|
||||
rightButtonsPanel.add(rightPlayerModul2);
|
||||
rightButtonsPanel.add(rightPlayerModul3);
|
||||
rightButtonsPanel.add(rightPlayerModul4);
|
||||
rightButtonsPanel.add(rightPlayerModul5);
|
||||
rightButtonsPanel.add(rightPlayerModul6);
|
||||
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));
|
||||
|
||||
// Buttons für das eigene Spielfeld hinzufügen
|
||||
for (int i = 0; i < gridSize; i++) {
|
||||
for (int j = 0; j < gridSize; j++) {
|
||||
ownBoardPanel.add(new JButton(gameBoardEmtpy));
|
||||
}
|
||||
}
|
||||
|
||||
// Buttons für das gegnerische Spielfeld hinzufügen
|
||||
for (int i = 0; i < gridSize; i++) {
|
||||
for (int j = 0; j < gridSize; j++) {
|
||||
opponentBoardPanel.add(new JButton(gameBoardEmtpy));
|
||||
}
|
||||
}
|
||||
|
||||
// Panel für beide Spielfelder (nebeneinander in der Mitte)
|
||||
JPanel centerPanel = new JPanel();
|
||||
centerPanel.setLayout(new GridLayout(1, 2, 20, 0)); // 2 Spielfelder nebeneinander, mit Abstand von 20 Pixeln
|
||||
centerPanel.add(ownBoardPanel);
|
||||
centerPanel.add(opponentBoardPanel);
|
||||
|
||||
// Panels dem Hauptlayout hinzufügen
|
||||
add(leftButtonsPanel, BorderLayout.WEST);
|
||||
add(rightButtonsPanel, BorderLayout.EAST);
|
||||
add(headerPanel, BorderLayout.NORTH);
|
||||
add(centerPanel, BorderLayout.CENTER);
|
||||
}
|
||||
|
||||
GameBoard(MainFrame frame,int semesterCounter) {
|
||||
buildPanel(frame, semesterCounter);
|
||||
/*
|
||||
rightPlayerRightButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
toggleRightPlayerIcon();
|
||||
updateTextFields();
|
||||
}
|
||||
}); */
|
||||
backButton.addActionListener(e -> frame.showPanel("MainMenu"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.*;
|
||||
|
||||
public class JoinGame extends JPanel {
|
||||
JLabel spielBeitretenLabel= new JLabel("Spiel beitreten");
|
||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||
|
||||
JLabel spielBeitretenLabel;
|
||||
JLabel ipLabel = new JLabel("IP-Adresse");
|
||||
JLabel portLabel = new JLabel("Port");
|
||||
|
||||
|
@ -12,17 +12,25 @@ public class JoinGame extends JPanel {
|
|||
JTextField portTextField = new JTextField(20);
|
||||
|
||||
JButton losButton = new JButton("Los!");
|
||||
JButton backButton = new JButton(backButtonIcon);
|
||||
|
||||
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
||||
|
||||
public JoinGame(MainFrame frame) {
|
||||
public JoinGame(MainFrame frame,int g) {
|
||||
setLayout(null);
|
||||
buildPanel(frame);
|
||||
buildPanel(frame,g);
|
||||
}
|
||||
|
||||
private void buildPanel(MainFrame frame) {
|
||||
private void buildPanel(MainFrame frame,int g) {
|
||||
if(g==1){
|
||||
spielBeitretenLabel= new JLabel("Spiel beitreten");
|
||||
}else{
|
||||
spielBeitretenLabel= new JLabel("Spiel erstellen");
|
||||
}
|
||||
|
||||
spielBeitretenLabel.setBounds(20,20,700, 100);
|
||||
losButton.setBounds(320, 225, 100, 50);
|
||||
backButton.setBounds(1380, 20, 80, 80);
|
||||
|
||||
ipLabel.setBounds(50, 125, 200, 30);
|
||||
portLabel.setBounds(50, 200, 200, 30);
|
||||
|
@ -39,6 +47,9 @@ public class JoinGame extends JPanel {
|
|||
add(losButton);
|
||||
add(ipTextField);
|
||||
add(portTextField);
|
||||
}
|
||||
add(backButton);
|
||||
|
||||
backButton.addActionListener(e -> frame.showPanel("MultiplayerGame"));
|
||||
losButton.addActionListener(e -> frame.showPanel("Verbinden"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,16 @@ public class MainFrame extends JFrame {
|
|||
private CardLayout cardLayout;
|
||||
private JPanel mainPanel;
|
||||
|
||||
// ---------- //
|
||||
// Diverse Hilfsvariablen (für Parameterübergabe etc.)
|
||||
// Von startMultiplayerGame an JoinGame
|
||||
int localMult;
|
||||
|
||||
// Von startLocalGame an GameBoard
|
||||
int semesterCounter;
|
||||
// ---------- //
|
||||
|
||||
|
||||
public MainFrame() {
|
||||
setTitle("Studium Versenken");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
@ -27,13 +37,18 @@ public class MainFrame extends JFrame {
|
|||
startLocalGame localGame = new startLocalGame(this);
|
||||
startMultiplayerGame multiplayerGame = new startMultiplayerGame(this);
|
||||
coinToss coinToss = new coinToss(this);
|
||||
JoinGame joinGame = new JoinGame(this);
|
||||
Verbinden verbinden = new Verbinden(this);
|
||||
//JoinGame joinGame = new JoinGame(this,localMult);
|
||||
//GameBoard gameBoard = new GameBoard(this, localMult);
|
||||
|
||||
mainPanel.add(mainMenuView, "MainMenu");
|
||||
mainPanel.add(localGame, "LocalGame");
|
||||
mainPanel.add(multiplayerGame, "MultiplayerGame");
|
||||
mainPanel.add(coinToss, "coinToss");
|
||||
mainPanel.add(joinGame, "JoinGame");
|
||||
mainPanel.add(verbinden, "Verbinden");
|
||||
//mainPanel.add(joinGame, "JoinGame");
|
||||
//mainPanel.add(gameBoard, "GameBoard");
|
||||
|
||||
// Hauptpanel in JFrame hinzufügen
|
||||
add(mainPanel);
|
||||
|
||||
|
@ -45,6 +60,41 @@ 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;
|
||||
|
||||
//if (!isPanelPresent(panelName)) { //TODO potentiell raus
|
||||
JoinGame joinGame = new JoinGame(this, localMult);
|
||||
mainPanel.add(joinGame, panelName);
|
||||
mainPanel.revalidate(); // Refresh
|
||||
mainPanel.repaint();
|
||||
//}
|
||||
|
||||
cardLayout.show(mainPanel, panelName); // Show the panel
|
||||
}
|
||||
// --- ShowPanel der startLocalGame Klasse
|
||||
public void showPanelSLG(String panelName,int semesterCounter) {
|
||||
this.semesterCounter = semesterCounter;
|
||||
|
||||
//if (!isPanelPresent(panelName)) { //TODO potentiell raus
|
||||
GameBoard gameBoard = new GameBoard(this, semesterCounter);
|
||||
mainPanel.add(gameBoard, 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()) {
|
||||
if (panelName.equals(mainPanel.getClientProperty("name"))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} */
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.*;
|
||||
|
||||
|
@ -36,9 +37,29 @@ public class MainMenuView extends JPanel {
|
|||
add(soundButton);
|
||||
|
||||
// Event Listener für Buttons
|
||||
lokalButton.addActionListener(e -> frame.showPanel("LocalGame"));
|
||||
multiButton.addActionListener(e -> frame.showPanel("MultiplayerGame"));
|
||||
soundButton.addActionListener(e -> toggleMute());
|
||||
lokalButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("Lokales Spiel ausgewählt.");
|
||||
frame.showPanel("LocalGame"); // Panel wechseln
|
||||
}
|
||||
});
|
||||
|
||||
multiButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("Multiplayer-Spiel ausgewählt.");
|
||||
frame.showPanel("MultiplayerGame"); // Panel wechseln
|
||||
}
|
||||
});
|
||||
|
||||
soundButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.out.println("Soundbutton geklickt.");
|
||||
toggleMute();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void toggleMute() {
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Verbinden extends JPanel{
|
||||
|
||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||
|
||||
JLabel verbindenLabel = new JLabel("Verbinde . . .",SwingConstants.CENTER);
|
||||
|
||||
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
|
||||
|
||||
public Verbinden(MainFrame frame) {
|
||||
setLayout(null);
|
||||
buildPanel(frame);
|
||||
}
|
||||
|
||||
private void buildPanel(MainFrame frame) {
|
||||
setLayout(new BorderLayout());
|
||||
verbindenLabel.setFont(robotoFont.deriveFont(50f));
|
||||
add(verbindenLabel, BorderLayout.CENTER);
|
||||
}
|
||||
}
|
||||
|
|
@ -142,7 +142,7 @@ public class startLocalGame extends JPanel {
|
|||
|
||||
backButton.addActionListener(e -> frame.showPanel("MainMenu"));
|
||||
|
||||
startButton.addActionListener(e -> frame.showPanel("coinToss")); // TODO ECHTE FUNKTION EINFÜGEN
|
||||
startButton.addActionListener(e -> frame.showPanelSLG("GameBoard", semesterCounter)); // TODO ECHTE FUNKTION EINFÜGEN
|
||||
}
|
||||
|
||||
private void toggleLeftPlayerIcon() {
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import javax.swing.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class startMultiplayerGame extends JPanel {
|
||||
// Funktionshilfen
|
||||
int semesterCounter = 1; // Semester Counter Label
|
||||
String PlayerNickname = "Spieler 1";
|
||||
|
||||
// Grafiken
|
||||
ImageIcon backButtonIcon = new ImageIcon("graphics/backButton.png");
|
||||
ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png");
|
||||
|
@ -108,7 +106,8 @@ public class startMultiplayerGame extends JPanel {
|
|||
// ActionListener für den "Back" Button, um zum vorherigen Panel zurückzukehren
|
||||
|
||||
backButton.addActionListener(e -> frame.showPanel("MainMenu"));
|
||||
joinGameButton.addActionListener(e -> frame.showPanel("JoinGame"));
|
||||
joinGameButton.addActionListener(e -> frame.showPanelSMG("JoinGame",1));
|
||||
createGameButton.addActionListener(e -> frame.showPanelSMG("JoinGame",0));
|
||||
}
|
||||
|
||||
// TOGGLE METHODEN
|
||||
|
|
Loading…
Reference in New Issue