ole #7

Merged
lgc merged 23 commits from ole into main 2024-11-26 14:01:01 +00:00
26 changed files with 955 additions and 199 deletions

124
.idea/uiDesigner.xml Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

View File

Before

Width:  |  Height:  |  Size: 2.2 MiB

After

Width:  |  Height:  |  Size: 2.2 MiB

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 959 B

After

Width:  |  Height:  |  Size: 959 B

27
src/AiPlayer.java Normal file
View File

@ -0,0 +1,27 @@
import java.util.Random;
import java.awt.Point;
public abstract class AiPlayer extends Player {
public AiPlayer(int size) {
super(size);
}
public Point RandomPoint() {
Random random = new Random(); // Pseudo Random für zufallszahlen
int posx = random.nextInt(super.board.size); // Generiert 0 - 13
int posy = random.nextInt(super.board.size); //
return new Point(posx,posy);
}
public void AiSetShips() {
for(int i = 0; i < super.board.ships.size(); i++) { // Interiert durch alle Shiffe
while(!super.board.ships.get(i).setPosition(RandomPoint()))
} // Versucht das Aktuelle Shiff zu setzten und wiederholt solange bis es funktioniert
return;
}
public void AiShoot() {
super.board.hit(RandomPoint());
return;
}
}

View File

@ -1,2 +1,75 @@
import java.awt.*;
import java.util.List;
public class Board { public class Board {
private List<HitResponse> hits;
private List<Ship> ships;
private final int size;
public Board(int size) {
this.size = size;
this.createShip(size - 13);
}
public HitResponse hit (Point point){
HitResponse response = new HitResponse(HitResponseType.MISS,point);
for (int i = 0; i < this.ships.size(); i++) {
HitResponseType type = this.ships.get(i).shootOnShip(point);
if ( type == HitResponseType.SUNK) {
for (int ii = 0; i < this.ships.size(); ii++) {
if (!this.ships.get(ii).isSunk()) {
response.setType(type);
this.addHits(response);
return response;
}
}
response.setType(HitResponseType.VICTORY);
this.addHits(response);
return response;
} else if (type == HitResponseType.HIT) {
response.setType(type);
this.addHits(response);
return response;
}
}
this.addHits(response);
return response;
}
private void createShip(int semester){
List<ShipData> shipData = Ship.semeterList.get(semester -1);
for (int i = 0; i < shipData.size(); i++) {
this.ships.add(new Ship(shipData.get(i).size(), shipData.get(i).name()));
}
}
public List<Ship> getShips() {
return ships;
}
public boolean addHits(HitResponse hitResponse) {
if (this.getHitResponsOnPoint(hitResponse.getPoint()) == null){
this.hits.add(hitResponse);
return true;
}
return false;
}
public HitResponse getHitResponsOnPoint(Point point) {
for (int i = 0; i < this.hits.size(); i++){
if (this.hits.get(i).getPoint().equals(point)){
return this.hits.get(i);
}
}
return null;
}
public int getSize() {
return size;
}
} }

3
src/GameBoard.java Normal file
View File

@ -0,0 +1,3 @@
public class GameBoard {
}

16
src/GameController.java Normal file
View File

@ -0,0 +1,16 @@
public class GameController {
public void startOnlineGame() {
// fuck you Luca and Ole von Florian und nicht von Florian
}
public void startLocalGame(Class<? extends LocalPlayer> localPlayerClass, Class<? extends AiPlayer> enemyClass, int size) throws InstantiationException, IllegalAccessException {
LocalPlayer localPlayer = localPlayerClass.newInstance();
AiPlayer aiPlayer = enemyClass.newInstance();
localPlayer.setEnemy(aiPlayer);
aiPlayer.setEnemy(localPlayer);
}
}

View File

@ -1,14 +1,12 @@
public class HalloSchiffeVersenken { public class HalloSchiffeVersenken {
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
/*Luccas Methoden MainFrame mf = new MainFrame();
MainMenuModel model = new MainMenuModel(); mf.setVisible(true);
MainMenuView view = new MainMenuView();
MainMenuController controller = new MainMenuController(model, view);
*/
System.out.println("HelloSchiffeVersenekn"); System.out.println("HelloSchiffeVersenekn");
/*
System.out.println("sound"); System.out.println("sound");
SoundHandler.playSound("hit"); SoundHandler.playSound("hit");
@ -17,7 +15,7 @@ public class HalloSchiffeVersenken {
SoundHandler.setSoundOn(false); SoundHandler.setSoundOn(false);
System.out.println("sound off"); System.out.println("sound off");
SoundHandler.playSound("hit"); SoundHandler.playSound("hit");
*/
startLocalGame huso = new startLocalGame();
} }
} }

View File

@ -3,4 +3,21 @@ import java.awt.*;
public class HitResponse { public class HitResponse {
private HitResponseType type; private HitResponseType type;
private Point point; private Point point;
public HitResponse(HitResponseType type, Point point) {
this.type = type;
this.point = point;
}
public HitResponseType getHitResponse() {
return this.type;
}
public Point getPoint() {
return this.point;
}
public void setType(HitResponseType type) {
this.type = type;
}
} }

7
src/HumanPlayer.java Normal file
View File

@ -0,0 +1,7 @@
public class HumanPlayer extends LocalPlayer {
public HumanPlayer(int size) {
super(size);
}
}

44
src/JoinGame.java Normal file
View File

@ -0,0 +1,44 @@
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");
JLabel ipLabel = new JLabel("IP-Adresse");
JLabel portLabel = new JLabel("Port");
JTextField ipTextField = new JTextField(20);
JTextField portTextField = new JTextField(20);
JButton losButton = new JButton("Los!");
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
public JoinGame(MainFrame frame) {
setLayout(null);
buildPanel(frame);
}
private void buildPanel(MainFrame frame) {
spielBeitretenLabel.setBounds(20,20,700, 100);
losButton.setBounds(320, 225, 100, 50);
ipLabel.setBounds(50, 125, 200, 30);
portLabel.setBounds(50, 200, 200, 30);
ipTextField.setBounds(50, 150, 250, 50);
portTextField.setBounds(50, 225, 250, 50);
spielBeitretenLabel.setFont(robotoFont.deriveFont(50f));
add(spielBeitretenLabel);
add(ipLabel);
add(portLabel);
add(losButton);
add(ipTextField);
add(portTextField);
}
}

8
src/LocalPlayer.java Normal file
View File

@ -0,0 +1,8 @@
public class LocalPlayer extends Player {
LocalPlayer(int size) {
super(size);
}
}

55
src/MainFrame.java Normal file
View File

@ -0,0 +1,55 @@
import javax.swing.*;
import java.awt.*;
public class MainFrame extends JFrame {
private CardLayout cardLayout;
private JPanel mainPanel;
public MainFrame() {
setTitle("Studium Versenken");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(1500, 1000);
setLocationRelativeTo(null);
//JLabel backgroundLabel = new JLabel(new ImageIcon("graphics/mainmenubackground.png"));
// backgroundLabel.setBounds(0, 0, 1500, 1000);
// getContentPane().add(backgroundLabel);
// backgroundLabel.setOpaque(true);
// CardLayout und Hauptpanel erstellen
cardLayout = new CardLayout();
mainPanel = new JPanel(cardLayout);
// Verschiedene Panels erstellen und hinzufügen
MainMenuView mainMenuView = new MainMenuView(this);
startLocalGame localGame = new startLocalGame(this);
startMultiplayerGame multiplayerGame = new startMultiplayerGame(this);
coinToss coinToss = new coinToss(this);
JoinGame joinGame = new JoinGame(this);
mainPanel.add(mainMenuView, "MainMenu");
mainPanel.add(localGame, "LocalGame");
mainPanel.add(multiplayerGame, "MultiplayerGame");
mainPanel.add(coinToss, "coinToss");
mainPanel.add(joinGame, "JoinGame");
// Hauptpanel in JFrame hinzufügen
add(mainPanel);
// Hauptmenü anzeigen
cardLayout.show(mainPanel, "MainMenu");
}
// Methode, um die Ansicht zu wechseln
public void showPanel(String panelName) {
cardLayout.show(mainPanel, panelName);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
MainFrame frame = new MainFrame();
frame.setVisible(true);
});
}
}

View File

@ -9,23 +9,27 @@ public class MainMenuController implements ActionListener {
public MainMenuController(MainMenuModel model, MainMenuView view) { public MainMenuController(MainMenuModel model, MainMenuView view) {
this.view = view; this.view = view;
this.model = model; this.model = model;
this.view.getLocalButton().addActionListener(this); //this.view.getLocalButton().addActionListener(this);
this.view.getMultiButton().addActionListener(this); //this.view.getMultiButton().addActionListener(this);
this.view.getSoundButton().addActionListener(this); // this.view.getSoundButton().addActionListener(this);
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (e.getSource() == view.getMultiButton()) { //if (e.getSource() == view.getMultiButton()) {
view.closeWindOw(); // model.setGameMode("Multiplayer");
MultiMenuModel model = new MultiMenuModel(); // MultiMenuModel multiModel = new MultiMenuModel();
MultiMenuView view = new MultiMenuView(); // MultiMenuView multiView = new MultiMenuView();
MultiMenuController controller2 = new MultiMenuController(model, view); // MultiMenuController multiMenuController = new MultiMenuController(multiModel, multiView);
} else if (e.getSource() == view.getMultiButton()) { // view.addPanel(multiView.getMultiPanel(), "MultiMenu");
model.setGameMode("Multiplayer"); // view.showPanel("MultiMenu");
JOptionPane.showMessageDialog(view.getFrame(), "Multiplayer game selected."); // }else if (e.getSource() == view.getSoundButton()) {
}else if (e.getSource() == view.getSoundButton()) { // view.toggleMute();
view.toggleMute(); // }else if(e.getSource() == view.getLocalButton()) {
model.setGameMode("LocalGame");
//startLocalGame localGame = new startLocalGame();
// view.addPanel(localGame.getLocalPanel(), "LocalMenu");
// view.showPanel("LocalMenu");
} }
} }
} //}

View File

@ -1,73 +1,51 @@
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.*; import javax.swing.*;
public class MainMenuView { public class MainMenuView extends JPanel {
ImageIcon SoundIcon = new ImageIcon("Grafik/sound button.png");
private JFrame frame = new JFrame();
private JLabel titelLabel = new JLabel("Studium versenken"); private JLabel titelLabel = new JLabel("Studium versenken");
private JButton lokalButton = new JButton("Lokal"); private JButton lokalButton = new JButton("Lokal");
private JButton multiButton= new JButton("Multiplayer"); private JButton multiButton = new JButton("Multiplayer");
private JButton soundButton = new JButton(SoundIcon); private JButton soundButton;
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
public MainMenuView() {
buildFrame();
buildComponents();
Font robotoFont = new Font("Roboto", Font.BOLD, 45);
private ImageIcon soundIcon = new ImageIcon("graphics/sound button.png");
private ImageIcon muteIcon = new ImageIcon("graphics/sound button muted.png");
public MainMenuView(MainFrame frame) {
setLayout(null);
buildPanel(frame);
} }
private void buildPanel(MainFrame frame) {
lokalButton.setBounds(200, 200, 500, 500);
multiButton.setBounds(800, 200, 500, 500);
titelLabel.setBounds(550, 10, 700, 100);
soundButton = new JButton(soundIcon);
soundButton.setBounds(20, 20, 128, 128);
public void buildComponents(){
lokalButton.setBounds(200,200,500,500);
multiButton.setBounds(800,200,500,500);
titelLabel.setBounds(550,10,700,100);
soundButton.setBounds(20,20,128,128);
titelLabel.setFont(robotoFont); titelLabel.setFont(robotoFont);
lokalButton.setFont(robotoFont.deriveFont(50f)); lokalButton.setFont(robotoFont.deriveFont(50f));
multiButton.setFont(robotoFont.deriveFont(50f)); multiButton.setFont(robotoFont.deriveFont(50f));
add(titelLabel);
add(lokalButton);
add(multiButton);
add(soundButton);
// Event Listener für Buttons
lokalButton.addActionListener(e -> frame.showPanel("LocalGame"));
multiButton.addActionListener(e -> frame.showPanel("MultiplayerGame"));
soundButton.addActionListener(e -> toggleMute());
} }
public void buildFrame() { private void toggleMute() {
frame.setLayout(null); if (soundButton.getIcon() == soundIcon) {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); soundButton.setIcon(muteIcon);
frame.setSize(1500,1000); } else {
frame.setVisible(true); soundButton.setIcon(soundIcon);
frame.getContentPane().setBackground( Color.decode("#98F5FF"));
JLabel backgroundLabel = new JLabel(new ImageIcon("Grafik/mainmenubackground.png"));
frame.setContentPane(backgroundLabel);
frame.add(titelLabel);
frame.add(lokalButton);
frame.add(multiButton);
frame.add(soundButton);
frame.setLocationRelativeTo(null);
}
public void toggleMute(){
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png");
if(soundButton.getIcon()==SoundIcon) {
soundButton.setIcon(MuteIcon);
}else{
soundButton.setIcon(SoundIcon);
} }
} }
}
public void closeWindOw(){
frame.dispose();
}
public JFrame getFrame() {
return frame;
}
public JButton getLocalButton() {
return lokalButton;
}
public JButton getMultiButton() {
return multiButton;
}
public JButton getSoundButton() {
return soundButton;
}
}

View File

@ -9,13 +9,14 @@ public class MultiMenuController implements ActionListener {
public MultiMenuController(MultiMenuModel model, MultiMenuView view) { public MultiMenuController(MultiMenuModel model, MultiMenuView view) {
this.view = view; this.view = view;
this.model = model; this.model = model;
this.view.getSoundButton().addActionListener(this);
} }
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
if (e.getSource() == view.getSoundButton()) { if (e.getSource() == view.getPlayerLeftButton()){
view.toggleMute(); view.togglePlayerIcon();
}else if(e.getSource() == view.getPlayerRightButton()){
view.togglePlayerIcon();
} }
} }
} }

View File

@ -3,51 +3,81 @@ import javax.swing.JFrame;
import javax.swing.*; import javax.swing.*;
public class MultiMenuView { public class MultiMenuView {
ImageIcon SoundIcon = new ImageIcon("Grafik/sound button.png"); int semesterCounter = 1;
private JFrame frame = new JFrame(); private JPanel multiPanel = new JPanel(null);
private JButton soundButton = new JButton(SoundIcon);
Font robotoFont = new Font("Roboto", Font.BOLD, 45); private ImageIcon humanPlayerIcon = new ImageIcon("graphics/humanPlayer.png");
private ImageIcon aiPlayerIcon = new ImageIcon("graphics/aiPlayer.png");
JButton PlayerLeftButton = new JButton("<-");
JButton PlayerRightButton = new JButton("->");
JButton semesterUpButton = new JButton("^");
JButton semesterDownButton = new JButton("v");
JLabel semesterLabel = new JLabel("Semester");
private JLabel titelLabel = new JLabel("Multiplayer");
private JLabel PlayerIcon = new JLabel(humanPlayerIcon);
private JLabel PlayerName = new JLabel("Name");
private JTextField PlayerTextField = new JTextField(20);
JLabel semesterCounterLabel = new JLabel(String.valueOf(semesterCounter));
private Font robotoFont = new Font("Roboto", Font.BOLD, 45);
public MultiMenuView() { public MultiMenuView() {
buildFrame(); buildPanel();
buildComponents();
} }
public void buildComponents(){ public void buildPanel(){
soundButton.setBounds(20,20,128,128); titelLabel.setBounds(20,20,700,100);
PlayerIcon.setBounds(75, 400, 200, 128);
PlayerName.setBounds(50, 625, 200, 30);
PlayerTextField.setBounds(50, 650, 250, 50);
semesterCounterLabel.setBounds(725, 475, 50, 50); // zwischen den Up/Down-Buttons
PlayerLeftButton.setBounds(50, 450, 50, 50);
PlayerRightButton.setBounds(250, 450, 50, 50);
semesterLabel.setBounds(500, 400, 200, 30);
semesterUpButton.setBounds(700, 400, 50, 50);
semesterDownButton.setBounds(700, 550, 50, 50);
multiPanel.setLayout(null);
titelLabel.setFont(robotoFont.deriveFont(50f));
semesterLabel.setFont(robotoFont.deriveFont(20f));
multiPanel.add(PlayerName);
multiPanel.add(titelLabel);
multiPanel.add(PlayerIcon);
multiPanel.add(PlayerTextField);
multiPanel.add(semesterCounterLabel);
multiPanel.add(semesterUpButton);
multiPanel.add(semesterDownButton);
multiPanel.add(PlayerLeftButton);
multiPanel.add(PlayerRightButton);
multiPanel.add(semesterLabel);
} }
public void buildFrame() { public JPanel getMultiPanel() {
frame.setLayout(null); return multiPanel;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1500,1000);
frame.setVisible(true);
frame.getContentPane().setBackground( Color.decode("#98F5FF"));
JLabel backgroundLabel = new JLabel(new ImageIcon("Grafik/mainmenubackground.png"));
frame.setContentPane(backgroundLabel);
frame.add(soundButton);
frame.setLocationRelativeTo(null);
} }
public void toggleMute(){ //public void showMultiPanel(String panelName) {
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png"); // CardLayout cl = (CardLayout)mainPanel.getLayout();
if(soundButton.getIcon()==SoundIcon) { // cl.show(multiPanel, panelName);
soundButton.setIcon(MuteIcon); //}
}else{
soundButton.setIcon(SoundIcon); public void togglePlayerIcon() {
if (PlayerIcon.getIcon() == humanPlayerIcon) {
PlayerIcon.setIcon(aiPlayerIcon);
} else {
PlayerIcon.setIcon(humanPlayerIcon);
} }
} }
public void closeWindOw(){ public JButton getPlayerLeftButton() {
frame.dispose(); return PlayerLeftButton;
}
public JFrame getFrame() {
return frame;
} }
public JButton getSoundButton() { public JButton getPlayerRightButton() {
return soundButton; return PlayerRightButton;
} }
} }

View File

@ -1,19 +1,29 @@
import java.awt.*; import java.awt.*;
import java.util.List;
public abstract class Player { public abstract class Player {
private boolean myTurn; protected boolean myTurn;
private boolean isServer; protected boolean isServer;
private boolean waitingForResponse; protected boolean waitingForResponse;
private Player enemy; protected Player enemy;
private String name; protected String name;
private Board board; protected Board board;
public Player(int size) {
this.board = new Board(size);
}
public void receiveShoot(Point point) { public void receiveShoot(Point point) {
HitResponse hitResponse = board.getHitResponsOnPoint(point);
if (!(hitResponse == null)){
enemy.receiveHit(hitResponse);
} else {
enemy.receiveHit(this.board.hit(point));
}
} }
public void receiveHit(HitResponse hitResponse) { public void receiveHit(HitResponse hitResponse) {
enemy.board.addHits(hitResponse);
} }
public void click(Point point) { public void click(Point point) {
@ -23,4 +33,8 @@ public abstract class Player {
public void beginTrun() { public void beginTrun() {
} }
public void setEnemy(Player enemy) {
this.enemy = enemy;
}
} }

100
src/Ship.java Normal file
View File

@ -0,0 +1,100 @@
import java.awt.Point;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
record ShipData (int size, String name){
}
public class Ship {
static List<List<ShipData>> semeterList = Arrays.asList(Arrays.asList(
new ShipData(2, "PRG 1"),
new ShipData(2, "GDI"),
new ShipData(2, "MAT 1"),
new ShipData(2, "THI"),
new ShipData(4, "STP"),
new ShipData(6, "ENG")),
Arrays.asList(
new ShipData(2, "PRG 2"),
new ShipData(2, "DBS 1"),
new ShipData(2, "MAT 2"),
new ShipData(2, "STA"),
new ShipData(2, "AUD")),
Arrays.asList(
new ShipData(2, "PRG 3"),
new ShipData(2, "DBS 2"),
new ShipData(2, "MAT 3"),
new ShipData(2, "BSN 1"),
new ShipData(4, "PRP"),
new ShipData(6, "BWL")),
Arrays.asList(
new ShipData(2, "WEB"),
new ShipData(2, "SE 1"),
new ShipData(2, "CG 1"),
new ShipData(2, "BSN 2"),
new ShipData(4, "SEM"),
new ShipData(6, "E BWL")),
Arrays.asList(
new ShipData(2, "WPF 1"),
new ShipData(2, "SE 2"),
new ShipData(2, "CG 2"),
new ShipData(2, "PXP 1"),
new ShipData(6, "EF 1")),
Arrays.asList(
new ShipData(2, "WPF 2"),
new ShipData(1, "PXP 2"),
new ShipData(8, "BAA"))
);
private int size;
private boolean horizontal;
private Point position;
private String name;
private int hitsOnMe;
private boolean sunk;
public Ship (int size, String name) {
this.size = size;
this.name = name;
this.horizontal = false;
this.position = null;
this.hitsOnMe = 0;
this.sunk = false;
}
public boolean setPosition(Point pos) {
//TODO Conte abrfrage ob shif da sein darf
this.position = pos;
return true;
}
public Point getPosition() {
return position;
}
public boolean isShipOnPos(Point pos){
if ((this.horizontal && pos.y == this.position.y && pos.x >= this.position.x && pos.x < this.position.x + size) ||
(!(this.horizontal) && pos.x == this.position.x && pos.y >= this.position.y && pos.y < this.position.y + size)) {
return true;
}
return false;
}
public HitResponseType shootOnShip(Point pos) {
if (this.isShipOnPos(pos)) {
hitsOnMe++;
if (hitsOnMe >= size) {
this.sunk = true;
return HitResponseType.SUNK;
} else {
return HitResponseType.HIT;
}
} else {
return HitResponseType.MISS;
}
}
public boolean isSunk() {
return sunk;
}
}

View File

@ -0,0 +1,7 @@
public class SpecificAiPlayer1 extends AiPlayer{
public SpecificAiPlayer1(int size) {
super(size);
}
}

View File

@ -0,0 +1,7 @@
public class SpecificAiPlayer1 extends AiPlayer{
public SpecificAiPlayer1(int size) {
super(size);
}
}

View File

@ -0,0 +1,65 @@
public class SpecificAiPlayerMedium extends AiPlayer{
private List<Point> hitsQueue = new ArrayList<>();
public SpecificAiPlayerMedium(int size) {
super(size);
}
@Override
public void AiShoot() {
Point nextShot = ComputeNextShot();
// Shoot at the enemy and receive the hit response
enemy.receiveShoot(nextShot);
HitResponse hitResponse = enemy.board.getHitResponsOnPoint(nextShot)
// If it's a hit or sunk, add adjacent cells to the hitsQueue
if (hitResponse.getHitResponse() == HitResponseType.HIT) {
addAdjacentPoints(nextShot);
}
}
public Point ComputeNextShot() {
Point nextShot;
// Prioritize shots from the hitsQueue
while (!hitsQueue.isEmpty()) {
nextShot = hitsQueue.remove(0);
if (!alreadyShot(nextShot)) {
return nextShot;
}
}
// If hitsQueue is empty, pick a random point that hasn't been shot
do {
nextShot = RandomPoint();
} while (alreadyShot(nextShot));
return nextShot;
}
private void addAdjacentPoints(Point point) {
int x = point.x;
int y = point.y;
// Possible adjacent positions (up, down, left, right)
Point[] adjacentPoints = {
new Point(x, y - 1),
new Point(x, y + 1),
new Point(x - 1, y),
new Point(x + 1, y)
};
for (Point p : adjacentPoints) {
if (isValidPoint(p) && !alreadyShot(p) && !hitsQueue.contains(p)) {
hitsQueue.add(p);
}
}
}
private boolean isValidPoint(Point point) {
return point.x >= 0 && point.x < board.getSize() &&
point.y >= 0 && point.y < board.getSize();
}
}

39
src/coinToss.java Normal file
View File

@ -0,0 +1,39 @@
import javax.swing.*;
import java.awt.*;
public class coinToss extends JPanel {
private int reihenfolge = 1; // 1 = Spieler 1 fängt an, 0 = Spieler 2 fängt an
private Timer timer;
private JLabel infoLabel;
// Konstruktor
public coinToss(MainFrame frame) {
setLayout(new BorderLayout());
// Info-Label für den Anzeigetext
infoLabel = new JLabel("", SwingConstants.CENTER);
infoLabel.setFont(new Font("Arial", Font.BOLD, 24));
add(infoLabel, BorderLayout.CENTER);
// Bestimme den Anfangstext basierend auf der "reihenfolge" Variable
if (reihenfolge == 1) {
infoLabel.setText("Du fängst an, mach dich bereit...");
} else {
infoLabel.setText("Dein Gegner fängt an, mach dich bereit...");
}
// Erster Timer, der den Text nach 3 Sekunden auf "Es geht Los!" setzt
/*timer = new Timer(3000, e -> {
infoLabel.setText("Es geht Los!");
// Zweiter Timer, der nach weiteren 3 Sekunden zum Hauptmenü zurückkehrt
Timer backToMenuTimer = new Timer(3000, ev -> {
frame.showPanel("MainMenu");
});
//backToMenuTimer.setRepeats(false); // Timer nur einmal ausführen
backToMenuTimer.start();
});
//timer.setRepeats(false); // Erster Timer soll nur einmal ausgeführt werden
timer.start();*/
}
}

View File

@ -1,29 +1,28 @@
import javax.swing.*; import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
public class startLocalGame { public class startLocalGame extends JPanel {
// Funktionshilfen // Funktionshilfen
int semesterCounter = 1; // Semester Counter Label int semesterCounter = 1; // Semester Counter Label
String leftPlayerNickname = "Spieler 1";
String rightPlayerNickname = "Spieler 2";
// 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 aiPlayerIcon = new ImageIcon("graphics/aiPlayer.png");
// Frame // Labels und Buttons
JFrame frame = new JFrame("Lokales Spiel");
// Labels
JLabel frameTitle = new JLabel("Lokales Spiel"); JLabel frameTitle = new JLabel("Lokales Spiel");
JLabel semesterlable = new JLabel("Semester"); JLabel semesterLabel = new JLabel("Semester");
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(aiPlayerIcon);
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("->");
@ -33,141 +32,150 @@ public class startLocalGame {
JButton rightPlayerRightButton = new JButton("->"); JButton rightPlayerRightButton = new JButton("->");
JButton startButton = new JButton("Start!"); JButton startButton = new JButton("Start!");
// Textfelder
JTextField leftPlayerTextField = new JTextField(20); JTextField leftPlayerTextField = new JTextField(20);
JTextField rightPlayerTextField = new JTextField(20); JTextField rightPlayerTextField = new JTextField(20);
startLocalGame() {
// Erstelle Frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(1500, 1000);
// Layout Manager (absolute ositionierung) // Methode zur Erstellung des Panels
frame.setLayout(null); startLocalGame(MainFrame frame) {
setLayout(null); // Stelle das Layout des Panels ein
// Erstelle Label // Setze Komponentenpositionen
frameTitle.setBounds(20, 20, 200, 30); frameTitle.setBounds(20, 20, 200, 30);
frame.add(frameTitle); add(frameTitle);
semesterlable.setBounds(700, 300, 200, 30); semesterLabel.setBounds(700, 300, 200, 30);
frame.add(semesterlable); add(semesterLabel);
leftPlayerName.setBounds(50, 625, 200, 30); leftPlayerName.setBounds(50, 625, 200, 30);
frame.add(leftPlayerName); add(leftPlayerName);
rightPlayerName.setBounds(1200, 625, 200, 30); rightPlayerName.setBounds(1200, 625, 200, 30);
frame.add(rightPlayerName); add(rightPlayerName);
leftPlayerIcon.setBounds(75, 400, 200, 128); leftPlayerIcon.setBounds(75, 400, 200, 128);
frame.add(leftPlayerIcon); add(leftPlayerIcon);
rightPlayerIcon.setBounds(1225, 400, 200, 128); rightPlayerIcon.setBounds(1225, 400, 200, 128);
frame.add(rightPlayerIcon); add(rightPlayerIcon);
semesterCounterLabel.setBounds(725, 475, 50, 50); // zwischen den Up/Down-Buttons semesterCounterLabel.setBounds(725, 475, 50, 50);
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER); semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
frame.add(semesterCounterLabel); add(semesterCounterLabel);
// Erstellt Buttons
backButton.setBounds(1380, 20, 80, 80); backButton.setBounds(1380, 20, 80, 80);
frame.add(backButton); add(backButton);
leftPlayerLeftButton.setBounds(50, 450, 50, 50); leftPlayerLeftButton.setBounds(50, 450, 50, 50);
frame.add(leftPlayerLeftButton); add(leftPlayerLeftButton);
leftPlayerRightButton.setBounds(250, 450, 50, 50); leftPlayerRightButton.setBounds(250, 450, 50, 50);
frame.add(leftPlayerRightButton); add(leftPlayerRightButton);
semesterUpButton.setBounds(725, 400, 50, 50); semesterUpButton.setBounds(725, 400, 50, 50);
frame.add(semesterUpButton); add(semesterUpButton);
semesterDownButton.setBounds(725, 550, 50, 50); semesterDownButton.setBounds(725, 550, 50, 50);
frame.add(semesterDownButton); add(semesterDownButton);
rightPlayerLeftButton.setBounds(1200, 450, 50, 50); rightPlayerLeftButton.setBounds(1200, 450, 50, 50);
frame.add(rightPlayerLeftButton); add(rightPlayerLeftButton);
rightPlayerRightButton.setBounds(1400, 450, 50, 50); rightPlayerRightButton.setBounds(1400, 450, 50, 50);
frame.add(rightPlayerRightButton); add(rightPlayerRightButton);
startButton.setBounds(700, 750, 100, 50); startButton.setBounds(700, 750, 100, 50);
frame.add(startButton); add(startButton);
// Erstellt Textfelder
leftPlayerTextField.setBounds(50, 650, 250, 50); leftPlayerTextField.setBounds(50, 650, 250, 50);
frame.add(leftPlayerTextField); leftPlayerTextField.setText(leftPlayerNickname);
add(leftPlayerTextField);
rightPlayerTextField.setBounds(1200, 650, 250, 50); rightPlayerTextField.setBounds(1200, 650, 250, 50);
frame.add(rightPlayerTextField); rightPlayerTextField.setText(rightPlayerNickname);
add(rightPlayerTextField);
// ActionListener für die Buttons // ActionListener für Buttons
semesterUpButton.addActionListener(new ActionListener() { semesterUpButton.addActionListener(e -> {
@Override if (semesterCounter < 6) {
public void actionPerformed(ActionEvent e) { semesterCounter++;
if (semesterCounter < 6) { semesterCounterLabel.setText(String.valueOf(semesterCounter));
semesterCounter++;
semesterCounterLabel.setText(String.valueOf(semesterCounter));
}
} }
}); });
semesterDownButton.addActionListener(new ActionListener() { semesterDownButton.addActionListener(e -> {
@Override if (semesterCounter > 1) {
public void actionPerformed(ActionEvent e) { semesterCounter--;
if (semesterCounter > 1) { // Verhindert, dass der Wert unter 1 fällt semesterCounterLabel.setText(String.valueOf(semesterCounter));
semesterCounter--;
semesterCounterLabel.setText(String.valueOf(semesterCounter));
}
} }
}); });
leftPlayerLeftButton.addActionListener(new ActionListener() { leftPlayerLeftButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png"); toggleLeftPlayerIcon();
if(leftPlayerIcon.getIcon()==humanPlayerIcon) { updateTextFields();
leftPlayerIcon.setIcon(aiPlayerIcon);
}else{
leftPlayerIcon.setIcon(humanPlayerIcon);
}
} }
}); });
leftPlayerRightButton.addActionListener(new ActionListener() { leftPlayerRightButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png"); toggleLeftPlayerIcon();
if(leftPlayerIcon.getIcon()==humanPlayerIcon) { updateTextFields();
leftPlayerIcon.setIcon(aiPlayerIcon);
}else{
leftPlayerIcon.setIcon(humanPlayerIcon);
}
} }
}); });
rightPlayerLeftButton.addActionListener(new ActionListener() { rightPlayerLeftButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png"); toggleRightPlayerIcon();
if(rightPlayerIcon.getIcon()==humanPlayerIcon) { updateTextFields();
rightPlayerIcon.setIcon(aiPlayerIcon);
}else{
rightPlayerIcon.setIcon(humanPlayerIcon);
}
} }
}); });
rightPlayerRightButton.addActionListener(new ActionListener() { rightPlayerRightButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ImageIcon MuteIcon = new ImageIcon("Grafik/sound button muted.png"); toggleRightPlayerIcon();
if(rightPlayerIcon.getIcon()==humanPlayerIcon) { updateTextFields();
rightPlayerIcon.setIcon(aiPlayerIcon);
}else{
rightPlayerIcon.setIcon(humanPlayerIcon);
}
} }
}); });
frame.setVisible(true); backButton.addActionListener(e -> frame.showPanel("MainMenu"));
startButton.addActionListener(e -> frame.showPanel("coinToss")); // TODO ECHTE FUNKTION EINFÜGEN
} }
}
private void toggleLeftPlayerIcon() {
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
leftPlayerIcon.setIcon(aiPlayerIcon);
} else {
leftPlayerIcon.setIcon(humanPlayerIcon);
}
}
private void toggleRightPlayerIcon() {
if (rightPlayerIcon.getIcon() == humanPlayerIcon) {
rightPlayerIcon.setIcon(aiPlayerIcon);
} else {
rightPlayerIcon.setIcon(humanPlayerIcon);
}
}
// Methode zum Aktualisieren der Textfelder basierend auf den ausgewählten Icons
private void updateTextFields() {
// Linker Spieler
if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
leftPlayerTextField.setText("Spieler 1");
} else {
leftPlayerTextField.setText("Leicht");
}
// Rechter Spieler
if (rightPlayerIcon.getIcon() == humanPlayerIcon) {
rightPlayerTextField.setText("Spieler 2");
} else {
rightPlayerTextField.setText("Leicht");
}
}
}

View File

@ -0,0 +1,131 @@
import javax.swing.*;
import java.awt.*;
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");
ImageIcon aiPlayerIcon = new ImageIcon("graphics/aiPlayer.png");
// Labels
JLabel frameTitle = new JLabel("Multiplayer Spiel");
JLabel semesterLabel = new JLabel("Semester");
JLabel PlayerName = new JLabel("Name");
JLabel PlayerIcon = new JLabel(humanPlayerIcon);
JLabel semesterCounterLabel = new JLabel(String.valueOf(semesterCounter));
// Buttons
JButton backButton = new JButton(backButtonIcon);
JButton PlayerLeftButton = new JButton("<-");
JButton PlayerRightButton = new JButton("->");
JButton semesterUpButton = new JButton("^");
JButton semesterDownButton = new JButton("v");
JButton createGameButton = new JButton("Spiel erstellen");
JButton joinGameButton = new JButton("Spiel beitreten");
// Textfelder
JTextField PlayerTextField = new JTextField(20);
// Konstruktor
startMultiplayerGame(MainFrame frame) {
setLayout(null); // Setze das Layout für das Panel auf null
// Setze Komponentenpositionen und füge sie dem Panel hinzu
frameTitle.setBounds(20, 20, 200, 30);
add(frameTitle);
semesterLabel.setBounds(700, 300, 200, 30);
add(semesterLabel);
PlayerName.setBounds(50, 625, 200, 30);
add(PlayerName);
PlayerIcon.setBounds(75, 400, 200, 128);
add(PlayerIcon);
semesterCounterLabel.setBounds(725, 475, 50, 50); // zwischen den Up/Down-Buttons
semesterCounterLabel.setHorizontalAlignment(SwingConstants.CENTER);
add(semesterCounterLabel);
// Füge Buttons hinzu und setze ihre Positionen
backButton.setBounds(1380, 20, 80, 80);
add(backButton);
PlayerLeftButton.setBounds(50, 450, 50, 50);
add(PlayerLeftButton);
PlayerRightButton.setBounds(250, 450, 50, 50);
add(PlayerRightButton);
semesterUpButton.setBounds(725, 400, 50, 50);
add(semesterUpButton);
semesterDownButton.setBounds(725, 550, 50, 50);
add(semesterDownButton);
joinGameButton.setBounds(1100, 350, 200, 50);
add(joinGameButton);
createGameButton.setBounds(1100, 550, 200, 50);
add(createGameButton);
// Füge das Textfeld hinzu
PlayerTextField.setBounds(50, 650, 250, 50);
PlayerTextField.setText(PlayerNickname);
add(PlayerTextField);
// ActionListener für Buttons
// SEMESTERBUTTONS
semesterUpButton.addActionListener(e -> {
if (semesterCounter < 6) {
semesterCounter++;
semesterCounterLabel.setText(String.valueOf(semesterCounter));
}
});
semesterDownButton.addActionListener(e -> {
if (semesterCounter > 1) {
semesterCounter--;
semesterCounterLabel.setText(String.valueOf(semesterCounter));
}
});
// PLAYERTOGGLEBUTTONS
PlayerLeftButton.addActionListener(e -> {
toggleLeftPlayerIcon();
updateTextFields();
});
PlayerRightButton.addActionListener(e -> {
toggleLeftPlayerIcon();
updateTextFields();
});
// ActionListener für den "Back" Button, um zum vorherigen Panel zurückzukehren
backButton.addActionListener(e -> frame.showPanel("MainMenu"));
joinGameButton.addActionListener(e -> frame.showPanel("JoinGame"));
}
// TOGGLE METHODEN
private void toggleLeftPlayerIcon() {
if (PlayerIcon.getIcon() == humanPlayerIcon) {
PlayerIcon.setIcon(aiPlayerIcon);
} else {
PlayerIcon.setIcon(humanPlayerIcon);
}
}
private void updateTextFields() {
if (PlayerIcon.getIcon() == humanPlayerIcon) {
PlayerTextField.setText(PlayerNickname);
} else {
PlayerTextField.setText("Leicht");
}
}
}