From 6f98a82a90ee4ea4efa56193aea6c0bb872c2cb1 Mon Sep 17 00:00:00 2001 From: Luca Conte Date: Mon, 23 Dec 2024 21:36:19 +0100 Subject: [PATCH] KOOMMMEEENTTAAAREEEEEEEE --- src/AiPlayer.java | 17 ++++++------ src/AsyncSocket.java | 2 +- src/AsyncSocketListener.java | 1 + src/Board.java | 15 ++++++----- src/BoardDisplay.java | 2 +- src/GameBoard.java | 5 ++++ src/GameController.java | 4 ++- src/HalloSchiffeVersenken.java | 3 ++- src/HitResponse.java | 17 +++++++++++- src/HumanPlayer.java | 4 +++ src/LocalPlayer.java | 6 +++++ src/LoseScreen.java | 1 + src/MainFrame.java | 6 ++--- src/OnlinePlayer.java | 21 ++++++++++++++- src/OnlinePlayer_1_1_0.java | 26 ++++++++++++++++-- src/Player.java | 47 ++++++++++++++++++++++++++++++++- src/Point.java | 4 +++ src/Ship.java | 6 ++++- src/SocketPackage.java | 3 +++ src/SpecificAiPlayerHard.java | 9 ++++--- src/SpecificAiPlayerMedium.java | 10 +++---- src/startLocalGame.java | 15 +++++++++++ src/startMultiplayerGame.java | 9 +++++++ 23 files changed, 196 insertions(+), 37 deletions(-) diff --git a/src/AiPlayer.java b/src/AiPlayer.java index 9865295..071f896 100644 --- a/src/AiPlayer.java +++ b/src/AiPlayer.java @@ -1,14 +1,12 @@ -/** - * Die Klasse AiPlayer ist die Basis für alle Ki Spieler und jede Spezifische Ki erweitert diese Klasse. - * @author Florian Alexy und Florian Hantzschel - * */ - import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Random; - +/** + * Die Klasse AiPlayer ist die Basis für alle Ki Spieler und jede Spezifische Ki erweitert diese Klasse. + * @author Florian Alexy und Florian Hantzschel + * */ public abstract class AiPlayer extends LocalPlayer implements Runnable { /** @@ -18,6 +16,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable { /** * Konstruktor + * @author Florian Alexy und Florian Hantzschel */ public AiPlayer() { this.setName("AI Player"); @@ -73,7 +72,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable { * Nachdem receiveShoot beim gegner den schuss verarbeitet hat, * wird diese Methode mit der antwort aufgerufen. * @param hitResponse the hitresponse - * @author Florian Alexy und Florian Hantzschel + * @author Florian Alexy und Florian Hantzschel und Luca Conte */ @Override public synchronized void receiveHit(HitResponse hitResponse) { @@ -91,7 +90,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable { /** * Erhält einen schuss vom gegner und verarbeitet ihn. * @param point the location to be shot - * @author Florian Alexy und Florian Hantzschel + * @author Florian Alexy und Florian Hantzschel und Luca Conte */ @Override public synchronized void receiveShoot(Point point) { @@ -106,7 +105,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable { /** * Wird aufgerufen, wenn in determineCoinToss festgestellt wurde das die Ki anfängt. * Erster Schuss wird gestartet. - * @author Florian Alexy und Florian Hantzschel + * @author Florian Alexy und Florian Hantzschel und Luca Conte */ @Override public void beginTurn() { diff --git a/src/AsyncSocket.java b/src/AsyncSocket.java index 1937afb..d0a9839 100644 --- a/src/AsyncSocket.java +++ b/src/AsyncSocket.java @@ -9,7 +9,7 @@ import java.net.Socket; /** * Provides an Interface to communicate using a socket asynchronously - * @author Luca Conte + * @author Luca Conte, Peer Ole Wachtel */ public class AsyncSocket { private Socket socket; diff --git a/src/AsyncSocketListener.java b/src/AsyncSocketListener.java index af3594e..3461c3e 100644 --- a/src/AsyncSocketListener.java +++ b/src/AsyncSocketListener.java @@ -1,4 +1,5 @@ /** + * defines a message listener for AsyncSockets * @author Luca Conte */ public interface AsyncSocketListener { diff --git a/src/Board.java b/src/Board.java index 9a6ac92..a871f8a 100644 --- a/src/Board.java +++ b/src/Board.java @@ -1,13 +1,12 @@ +import java.util.ArrayList; +import java.util.List; + /** * Diese Klasse ist das Board von eimem spieler und enthält alle logischen operationen. * Sprich ist das Backend Board. * * @author Peer Ole Wachtel, Florian Alexy und Florian Hantzschel */ - -import java.util.ArrayList; -import java.util.List; - public class Board { /** @@ -41,7 +40,7 @@ public class Board { } /** - * Nimmt einen punkt entgegen und Gibt einen Hitrespons zurück. + * Nimmt einen punkt entgegen und Gibt einen HitResponse zurück. * @param point auf den geschossen wurde * @return * @author Peer Ole Wachtel @@ -104,7 +103,9 @@ public class Board { } /** + * returns a list of all the Ships on the board * @return a list of all the Ships on the board + * @author Peer Ole Wachtel */ public List getShips() { return ships; @@ -117,7 +118,7 @@ public class Board { * to all adjacened hit responses with type HIT using `propagateSunk`. * @param hitResponse the HitResponse to be added * @return true when the hit response was added, otherwise false - * + * @author Peer Ole Wachtel, Luca Conte */ public synchronized boolean addHits(HitResponse hitResponse) { if (this.getHitResponseOnPoint(hitResponse.getPoint()) == null){ @@ -149,7 +150,9 @@ public class Board { } /** + * returns the size of the board * @return the size of the board + * @author Florian Alexy, Florian Hantzschel */ public int getSize() { return this.size; diff --git a/src/BoardDisplay.java b/src/BoardDisplay.java index f8542d7..5295ad7 100644 --- a/src/BoardDisplay.java +++ b/src/BoardDisplay.java @@ -39,7 +39,7 @@ public class BoardDisplay extends JPanel { } /** - * Konstruktor der startLocalGame. + * Konstruktor des Board Displays * @param gridSize Die Größe des Spielfelds * @param player Der Spieler * @author Lucas Bronson diff --git a/src/GameBoard.java b/src/GameBoard.java index 1370b1c..a67bc58 100644 --- a/src/GameBoard.java +++ b/src/GameBoard.java @@ -225,6 +225,11 @@ public class GameBoard extends JPanel { public Player getP1() { return p1; } + /** + * Getter für Player2 + * @return Player 2 + * @author Luca Conte + */ public Player getP2() { return p2; } diff --git a/src/GameController.java b/src/GameController.java index 6a921c9..b8a7efc 100644 --- a/src/GameController.java +++ b/src/GameController.java @@ -14,6 +14,7 @@ public class GameController { private static MainFrame mainFrame; /** + * returns the current MainFrame * @return the current MainFrame * @author Luca Conte */ @@ -21,6 +22,7 @@ public class GameController { return GameController.mainFrame; } /** + * sets the current MainFrame * @param mainFrame the current MainFrame * @author Luca Conte */ @@ -124,7 +126,7 @@ public class GameController { /** * finds the largest common version in two lists of version strings - * @return null if no common versions are found + * @return null if no common versions are found otherwise returns the most recent version present in both lists * @author Luca Conte */ public static String findMostRecentVersion(List versions1, List versions2) { diff --git a/src/HalloSchiffeVersenken.java b/src/HalloSchiffeVersenken.java index 7eaa176..77be9f0 100644 --- a/src/HalloSchiffeVersenken.java +++ b/src/HalloSchiffeVersenken.java @@ -1,6 +1,6 @@ /** * Hauptklasse über die der MainFrame gestartet wird - * @author Lucas Bronson, Ole Wachtel, Joshua Kuklok + * @author Lucas Bronson, Peer Ole Wachtel, Joshua Kuklok */ public class HalloSchiffeVersenken { @@ -8,6 +8,7 @@ public class HalloSchiffeVersenken { * Erstellt und setzt den Mainframe * @param args Argumente an Main durch Konsole etc. * @throws InterruptedException + * @author Peer Ole Wachtel */ public static void main(String[] args) throws InterruptedException { MainFrame mf = new MainFrame(); diff --git a/src/HitResponse.java b/src/HitResponse.java index 56560d3..c6d70b9 100644 --- a/src/HitResponse.java +++ b/src/HitResponse.java @@ -1,5 +1,10 @@ - +/** + * Eine Antwort auf einen Schuss + * enthält einen Punkt, auf den geschossen wurde, sowie einen typen, + * der angibt, ob es sich bei dem Schuss um einen Treffer handelt + * @author Peer Ole Wachtel + */ public class HitResponse { /** * Speichert den typ der HitResponse. @@ -37,10 +42,20 @@ public class HitResponse { } } + /** + * returns the type of the HitResponse + * @return the type of the HitResponse + * @author Florian Hantzschel + */ public HitResponseType getHitResponse() { return this.type; } + /** + * returns the point of the HitResponse + * @return the point of the HitResponse + * @author Florian Hantzschel + */ public Point getPoint() { return this.point; } diff --git a/src/HumanPlayer.java b/src/HumanPlayer.java index 36203ec..68a93c2 100644 --- a/src/HumanPlayer.java +++ b/src/HumanPlayer.java @@ -1,4 +1,8 @@ +/** + * Repräsentiert einen menschlichen Spieler + * @author Luca Conte, Florian Hantzschel + */ public class HumanPlayer extends LocalPlayer { /** * shoots a shot onto the provided point on the enemy board diff --git a/src/LocalPlayer.java b/src/LocalPlayer.java index 70d3cef..96b9f1b 100644 --- a/src/LocalPlayer.java +++ b/src/LocalPlayer.java @@ -1,5 +1,10 @@ import java.util.Random; +/** + * repräsentiert einen Player, der Lokal an dem Gerät spielt, + * auf dem dieses Programm läuft + * @author Luca Conte, Peer Ole Wachtel, Florian Hantzschel + */ public class LocalPlayer extends Player { @@ -77,6 +82,7 @@ public class LocalPlayer extends Player { /** * sends shot to enemy player. * should ONLY be called on HumanPlayer + * @author Luca Conte */ @Override public void shoot(Point point){ diff --git a/src/LoseScreen.java b/src/LoseScreen.java index dffa8f2..db49fc5 100644 --- a/src/LoseScreen.java +++ b/src/LoseScreen.java @@ -6,6 +6,7 @@ import javax.swing.*; /** * Klasse für Erstellung von looseScreen Objekten * Dient zur Anzeige das ein Spiel verloren wurde + * @author Joshua Kuklok, Luca Bronson */ public class LoseScreen extends JPanel { JLabel loseLabel = new JLabel("Du hast Verloren"); diff --git a/src/MainFrame.java b/src/MainFrame.java index edef294..004c068 100644 --- a/src/MainFrame.java +++ b/src/MainFrame.java @@ -126,7 +126,7 @@ public class MainFrame extends JFrame { * Spezifische ShowPanel für WinScreen Klasse * @param panelName Name des anzuzeigenden Panels * @param player Player von dem die funktion aufgerufen worden ist - * @author Lucas Bronson, Peer Ole Wachtel + * @author Lucas Bronson, Peer Ole Wachtel, Luca Conte */ public void showPanelWin(String panelName, Player player){ if(player != gameBoard.getP1()){ @@ -149,7 +149,7 @@ public class MainFrame extends JFrame { * Spezifische ShowPanel für LooseScreen Klasse * @param panelName Name des anzuzeigenden Panels * @param player Player von dem die funktion aufgerufen worden ist - * @author Lucas Bronson, Peer Ole Wachtel + * @author Lucas Bronson, Peer Ole Wachtel, Luca Conte */ public void showPanelLose(String panelName, Player player){ if(player != gameBoard.getP1()){ @@ -169,7 +169,7 @@ public class MainFrame extends JFrame { } /** - * Aktualisiert das Spielfeld (kontextText) + * Aktualisiert das Spielfeld * @author Luca Conte */ public void refreshGameBoard() { diff --git a/src/OnlinePlayer.java b/src/OnlinePlayer.java index 486a48d..08c418b 100644 --- a/src/OnlinePlayer.java +++ b/src/OnlinePlayer.java @@ -1,3 +1,8 @@ +/** + * Abstrakte Repräsentation eines Spielers, der an einem anderen gerät spielt + * und durch eine Online Verbindung mit dieser Instanz kommuniziert + * @author Luca Conte, Peer Ole Wachtel + */ public abstract class OnlinePlayer extends Player implements AsyncSocketListener { protected AsyncSocket socket; protected int wantedBoardSize; @@ -9,19 +14,33 @@ public abstract class OnlinePlayer extends Player implements AsyncSocketListener * @param size the size of the board the enemy player wants to play with * the actual board size will be determined once the semester of the online partner is known * @param socket an AsyncSocket to communicate with the enemy through + * @author Peer Ole Wachtel, Luca Conte */ public OnlinePlayer(Integer size, AsyncSocket socket) { this.socket = socket; this.wantedBoardSize = size; this.myCoin = null; socket.setHandler(this); - //TODO Auto-generated constructor stub } + /** + * sends the IAM Package for introduction + * @author Luca Conte + */ public abstract void sendIAM(); + /** + * receives a message from the AsyncSocket + * satisfies AsyncSocketListener interface + * @author Luca Conte + */ public abstract void receive(String message); + /** + * receives the coin toss result from the enemy + * @param coin the result of the coin toss + * @author Peer Ole Wachtel + */ @Override public abstract void receiveCoin(boolean coin); diff --git a/src/OnlinePlayer_1_1_0.java b/src/OnlinePlayer_1_1_0.java index 2ba932a..63ea7f5 100644 --- a/src/OnlinePlayer_1_1_0.java +++ b/src/OnlinePlayer_1_1_0.java @@ -1,6 +1,18 @@ import java.util.List; + +/** + * eine Implementierung des Kommunikationsprotokoll nach Version 1.1.0 des Netzwerkstandards + * https://github.com/lgc-4/ProgProjekt-Netzwerkstandard + * @author Peer Ole Wachtel, Luca Conte + */ public class OnlinePlayer_1_1_0 extends OnlinePlayer { + + /** + * Erstellt einen Online Player + * @param size die maximale Größe des Spielfelds + * @param socket der Socket zur Kommunikation mit dem Online Partner + */ public OnlinePlayer_1_1_0(Integer size, AsyncSocket socket) { super(size, socket); } @@ -107,7 +119,7 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer { * receives a shot from the enemy and sends it to the online partner * if it is not the enemies turn, this method does nothing. * @param point the point to be shot - * @author Peer Ole Wachtel + * @author Peer Ole Wachtel, Luca Conte */ @Override public synchronized void receiveShoot(Point point){ @@ -118,7 +130,7 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer { /** * receives a hitresponse from the enemy player and sends it to the online partner * @param hitResponse the hitresponse to be sent - * @author Peer Ole Wachtel + * @author Peer Ole Wachtel, Luca Conte */ @Override public synchronized void receiveHit(HitResponse hitResponse) { @@ -152,12 +164,22 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer { } } + /** + * für Online Player nicht zu implementieren + * nur für HumanPlayer relevant + * @author Luca Conte, Peer Ole Wachtel + */ @Override public synchronized void shoot(Point point) { // SHOULD NEVER BE CALLED ON ONLINE PLAYER. ONLY ON HUMAN PLAYER return; } + /** + * empfängt Withdraw vom Gegner und leitet es an den Online Partner weiter + * beendet das Spiel + * @author Luca Conte + */ @Override public void receiveWithdraw() { this.socket.send(new SocketPackage("WITHDRAW")); diff --git a/src/Player.java b/src/Player.java index 8dfc776..07bebe3 100644 --- a/src/Player.java +++ b/src/Player.java @@ -1,3 +1,7 @@ +/** + * abstrakte repräsentation eines Spielers + * @author Peer Ole Wachtel, Luca Conte, Lucas Bronson + */ public abstract class Player { protected boolean myTurn; protected boolean isServer; @@ -12,6 +16,10 @@ public abstract class Player { protected boolean hasReceivedCoin; + /** + * Konstruktor + * @author Peer Ole Wachtel, Luca Conte + */ public Player() { this.setName("Player"); this.hasReceivedCoin = false; @@ -29,10 +37,25 @@ public abstract class Player { this.board = new Board(size); } + /** + * receives a shot onto a point from the enemy + * @param point the location to be shot + * @author Luca Conte, Peer Ole Wachtel + */ public abstract void receiveShoot(Point point); + /** + * receives a hit response from the enemy as a response to a receiveShoot call + * @param hitResponse the hitresponse + * @author Peer Ole Wachtel + */ public abstract void receiveHit(HitResponse hitResponse); + /** + * sends shot to enemy player. + * should ONLY be called on HumanPlayer + * @author Luca Conte + */ public abstract void shoot(Point point); /** @@ -60,6 +83,7 @@ public abstract class Player { public void setName(String name) { this.name = name; } + /** * returns the name of this player * @return the name of this player @@ -126,6 +150,7 @@ public abstract class Player { /** * returns whether this player is ready and has sent their coin to the enemy player * @return the player's ready state + * @author Lucas Bronson */ public boolean isReady() { return this.sentCoin; @@ -137,7 +162,6 @@ public abstract class Player { * and players * * This method should be called at the end of a game - * This method should be called at the end of a game * * @author Luca Conte */ @@ -148,18 +172,39 @@ public abstract class Player { this.enemy = null; } + /** + * the player wins + * ends the game + * @author Luca Conte + */ public void win() { GameController.getMainFrame().showPanelWin("", this); } + + /** + * the player loses + * ends the game + * @author Luca Conte + */ public void lose() { GameController.getMainFrame().showPanelLose("", this); } + /** + * the player loses by withdrawal + * ends the game + * @author Luca Conte + */ public void withdraw() { this.enemy.receiveWithdraw(); this.lose(); } + /** + * the enemy player withdraws + * ends the game + * @author Luca Conte + */ public void receiveWithdraw(){ this.win(); } diff --git a/src/Point.java b/src/Point.java index 3f37221..d77f266 100644 --- a/src/Point.java +++ b/src/Point.java @@ -1,3 +1,7 @@ +/** + * repräsentation der Koordinaten eines Feldes auf dem Spielfeld + * @author Peer Ole Wachtel, Luca Conte + */ public class Point { private int x; private int y; diff --git a/src/Ship.java b/src/Ship.java index 8844dc9..4c55df6 100644 --- a/src/Ship.java +++ b/src/Ship.java @@ -5,6 +5,10 @@ import java.util.List; record ShipData (int size, String name){} +/** + * repräsentation eines Schiffes auf dem Spielfeld + * @author Peer Ole Wachtel, Lucas Bronson, Florian Hanzschel + */ public class Ship { static List> semeterList = Arrays.asList( @@ -189,7 +193,7 @@ public class Ship { /** * returns the position of this ship * @return the position of this ship - * @author Peer Ole Wachte + * @author Peer Ole Wachtel */ public Point getPosition() { return position; diff --git a/src/SocketPackage.java b/src/SocketPackage.java index 767d0e2..fb6dd20 100644 --- a/src/SocketPackage.java +++ b/src/SocketPackage.java @@ -1,6 +1,8 @@ import java.util.Arrays; import java.util.List; /** + * beschreibt ein Package das durch einen AsyncSocket gesendet werden kann nach Netzwerkstandard + * https://github.com/lgc-4/ProgProjekt-Netzwerkstandard * @author Luca Conte */ public class SocketPackage { @@ -88,6 +90,7 @@ public class SocketPackage { * parses the package into a string according to https://github.com/lgc-4/ProgProjekt-Netzwerkstandard * the package name and data are joined using a space " " `0x20` * @return the package in string format + * @author Luca Conte */ public String toString() { if (this.data == null || this.data.length() == 0) { diff --git a/src/SpecificAiPlayerHard.java b/src/SpecificAiPlayerHard.java index 292bf6d..08a43cf 100644 --- a/src/SpecificAiPlayerHard.java +++ b/src/SpecificAiPlayerHard.java @@ -1,10 +1,10 @@ +import java.util.ArrayList; +// import java.util.Random; wird nicht mehr verwendet + /** * Diese Klasse implementiert den Harten Ki Spieler. * @author Florian Alexy und Florian Hantzschel * */ -import java.util.ArrayList; -// import java.util.Random; wird nicht mehr verwendet - public class SpecificAiPlayerHard extends AiPlayer{ private int gridSize; @@ -21,7 +21,8 @@ public class SpecificAiPlayerHard extends AiPlayer{ VERTIKAL } private Orientierung orientierung; - private Point firstHit; // Speichert den ersten Treffer zur Bestimmung der Orientierung + // Speichert den ersten Treffer zur Bestimmung der Orientierung + private Point firstHit; /** diff --git a/src/SpecificAiPlayerMedium.java b/src/SpecificAiPlayerMedium.java index aa2c6ca..2ceb3d7 100644 --- a/src/SpecificAiPlayerMedium.java +++ b/src/SpecificAiPlayerMedium.java @@ -1,10 +1,10 @@ +import java.util.ArrayList; +import java.util.List; + /** * Diese Klasse implementiert den Medium Ki Spieler. * @author Florian Alexy und Florian Hantzschel * */ -import java.util.ArrayList; -import java.util.List; - public class SpecificAiPlayerMedium extends AiPlayer{ /** * Liste an Punkten die beschossen werden sollen. (Mögliche weitere Segmente vom schiff) @@ -48,7 +48,7 @@ public class SpecificAiPlayerMedium extends AiPlayer{ /** * Die Methode bestimmt welche Position als nächstes beschossen werden soll. - * @return + * @return der Punkt auf den als nächtest geschossen werden soll * @author Florian Alexy und Florian Hantzschel */ public Point ComputeNextShot() { @@ -72,7 +72,7 @@ public class SpecificAiPlayerMedium extends AiPlayer{ /** * Diese Methode erweitert die hitsQueue um die umliegenden Punkte die Schiffe seien könnten. - * @param point + * @param point der Punkt dessen nachbarn zur hitQueue hinzugefügt werden sollen * @author Florian Alexy und Florian Hantzschel */ private void addAdjacentPoints(Point point) { diff --git a/src/startLocalGame.java b/src/startLocalGame.java index 81a47db..20b2b27 100644 --- a/src/startLocalGame.java +++ b/src/startLocalGame.java @@ -225,10 +225,13 @@ public class startLocalGame extends JPanel { private void toggleLeftPlayerIconLeft() { if (leftPlayerIcon.getIcon() == humanPlayerIcon) { leftPlayerIcon.setIcon(aiPlayerHardIcon); + } else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){ leftPlayerIcon.setIcon(humanPlayerIcon); + } else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) { leftPlayerIcon.setIcon(aiPlayerEasyIcon); + } else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) { leftPlayerIcon.setIcon(aiPlayerNormalIcon); } @@ -241,10 +244,13 @@ public class startLocalGame extends JPanel { 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); } @@ -257,8 +263,10 @@ public class startLocalGame extends JPanel { private void toggleRightPlayerIconLeft() { if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) { rightPlayerIcon.setIcon(aiPlayerHardIcon); + } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){ rightPlayerIcon.setIcon(aiPlayerEasyIcon); + } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) { rightPlayerIcon.setIcon(aiPlayerNormalIcon); } @@ -271,8 +279,10 @@ public class startLocalGame extends JPanel { 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); } @@ -286,10 +296,13 @@ public class startLocalGame extends JPanel { // Für Linken Spieler if (leftPlayerIcon.getIcon() == humanPlayerIcon) { leftPlayerTextField.setText(leftPlayerNickname); + } else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){ leftPlayerTextField.setText("Einfach"); + } else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) { leftPlayerTextField.setText("Mittel"); + } else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) { leftPlayerTextField.setText("Schwer"); } @@ -297,8 +310,10 @@ public class startLocalGame extends JPanel { // Für Rechten Spieler if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon){ rightPlayerTextField.setText("Einfach"); + } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) { rightPlayerTextField.setText("Mittel"); + } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) { rightPlayerTextField.setText("Schwer"); } diff --git a/src/startMultiplayerGame.java b/src/startMultiplayerGame.java index cd10369..f2f0397 100644 --- a/src/startMultiplayerGame.java +++ b/src/startMultiplayerGame.java @@ -192,10 +192,13 @@ public class startMultiplayerGame extends JPanel { private void togglePlayerIconLeft() { if (PlayerIcon.getIcon() == humanPlayerIcon) { PlayerIcon.setIcon(aiPlayerHardIcon); + } else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){ PlayerIcon.setIcon(humanPlayerIcon); + } else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) { PlayerIcon.setIcon(aiPlayerEasyIcon); + } else if (PlayerIcon.getIcon() == aiPlayerHardIcon) { PlayerIcon.setIcon(aiPlayerNormalIcon); } @@ -208,10 +211,13 @@ public class startMultiplayerGame extends JPanel { 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); } @@ -224,10 +230,13 @@ public class startMultiplayerGame extends JPanel { private void updateTextFields() { if (PlayerIcon.getIcon() == humanPlayerIcon) { PlayerTextField.setText(PlayerNickname); + } else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){ PlayerTextField.setText("Einfach"); + } else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) { PlayerTextField.setText("Mittel"); + } else if (PlayerIcon.getIcon() == aiPlayerHardIcon) { PlayerTextField.setText("Schwer"); }