kommentar-check #28

Merged
lgc merged 3 commits from kommentar-check into main 2024-12-23 20:37:06 +00:00
23 changed files with 210 additions and 36 deletions

View File

@ -1,14 +1,12 @@
/**
* Die Klasse AiPlayer ist die Basis für alle Ki Spieler und jede Spezifische Ki erweitert diese Klasse.
* @author Florian und Florian
* */
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random; 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 { public abstract class AiPlayer extends LocalPlayer implements Runnable {
/** /**
@ -18,6 +16,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
/** /**
* Konstruktor * Konstruktor
* @author Florian Alexy und Florian Hantzschel
*/ */
public AiPlayer() { public AiPlayer() {
this.setName("AI Player"); this.setName("AI Player");
@ -27,6 +26,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
/** /**
* Gibt einen zufälligen Punkt im Spielfeld zurück. * Gibt einen zufälligen Punkt im Spielfeld zurück.
* @return Ein zufälliger Punkt * @return Ein zufälliger Punkt
* @author Florian Alexy und Florian Hantzschel
*/ */
public Point RandomPoint() { public Point RandomPoint() {
Random random = new Random(); // Pseudo Random für zufallszahlen Random random = new Random(); // Pseudo Random für zufallszahlen
@ -38,6 +38,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
/** /**
* Initialisiert das Board. * Initialisiert das Board.
* @param size größe des Boards * @param size größe des Boards
* @author Florian Alexy und Florian Hantzschel
*/ */
@Override @Override
public void createBoard(int size) { public void createBoard(int size) {
@ -48,6 +49,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
/** /**
* Ki Methode zum zufälligen Setzten der Schiffe * Ki Methode zum zufälligen Setzten der Schiffe
* @author Florian Alexy und Florian Hantzschel
*/ */
public void aiSetShips() { public void aiSetShips() {
for(int i = 0; i < super.board.getShips().size(); i++) { // Interiert durch alle Shiffe for(int i = 0; i < super.board.getShips().size(); i++) { // Interiert durch alle Shiffe
@ -58,6 +60,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
} }
/** /**
* Ki Methode zum zufälligen Schießen auf das gegnerische Board. * Ki Methode zum zufälligen Schießen auf das gegnerische Board.
* @author Florian Alexy und Florian Hantzschel
*/ */
public void aiShoot() { public void aiShoot() {
if (!this.myTurn) return; if (!this.myTurn) return;
@ -65,7 +68,12 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
return; return;
} }
/**
* 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 und Luca Conte
*/
@Override @Override
public synchronized void receiveHit(HitResponse hitResponse) { public synchronized void receiveHit(HitResponse hitResponse) {
// Eltern-Klasse LocalPlayer updatet myTurn // Eltern-Klasse LocalPlayer updatet myTurn
@ -79,6 +87,11 @@ 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 und Luca Conte
*/
@Override @Override
public synchronized void receiveShoot(Point point) { public synchronized void receiveShoot(Point point) {
super.receiveShoot(point); super.receiveShoot(point);
@ -92,6 +105,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
/** /**
* Wird aufgerufen, wenn in determineCoinToss festgestellt wurde das die Ki anfängt. * Wird aufgerufen, wenn in determineCoinToss festgestellt wurde das die Ki anfängt.
* Erster Schuss wird gestartet. * Erster Schuss wird gestartet.
* @author Florian Alexy und Florian Hantzschel und Luca Conte
*/ */
@Override @Override
public void beginTurn() { public void beginTurn() {
@ -102,7 +116,7 @@ public abstract class AiPlayer extends LocalPlayer implements Runnable {
/** /**
* Closes past threads and tries firing a shot. * Closes past threads and tries firing a shot.
* @author Luca Conte * @author Luca Conte, Florian Alexy und Florian Hantzschel
*/ */
public void run() { public void run() {
Iterator<Thread> i = this.shootThreads.iterator(); Iterator<Thread> i = this.shootThreads.iterator();

View File

@ -9,7 +9,7 @@ import java.net.Socket;
/** /**
* Provides an Interface to communicate using a socket asynchronously * Provides an Interface to communicate using a socket asynchronously
* @author Luca Conte * @author Luca Conte, Peer Ole Wachtel
*/ */
public class AsyncSocket { public class AsyncSocket {
private Socket socket; private Socket socket;

View File

@ -1,4 +1,5 @@
/** /**
* defines a message listener for AsyncSockets
* @author Luca Conte * @author Luca Conte
*/ */
public interface AsyncSocketListener { public interface AsyncSocketListener {

View File

@ -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. * Diese Klasse ist das Board von eimem spieler und enthält alle logischen operationen.
* Sprich ist das Backend Board. * Sprich ist das Backend Board.
* *
* @author Peer Ole Wachtel, Florian Alexy und Florian Hantzschel * @author Peer Ole Wachtel, Florian Alexy und Florian Hantzschel
*/ */
import java.util.ArrayList;
import java.util.List;
public class Board { 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 * @param point auf den geschossen wurde
* @return * @return
* @author Peer Ole Wachtel * @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 * @return a list of all the Ships on the board
* @author Peer Ole Wachtel
*/ */
public List<Ship> getShips() { public List<Ship> getShips() {
return ships; return ships;
@ -117,7 +118,7 @@ public class Board {
* to all adjacened hit responses with type HIT using `propagateSunk`. * to all adjacened hit responses with type HIT using `propagateSunk`.
* @param hitResponse the HitResponse to be added * @param hitResponse the HitResponse to be added
* @return true when the hit response was added, otherwise false * @return true when the hit response was added, otherwise false
* * @author Peer Ole Wachtel, Luca Conte
*/ */
public synchronized boolean addHits(HitResponse hitResponse) { public synchronized boolean addHits(HitResponse hitResponse) {
if (this.getHitResponseOnPoint(hitResponse.getPoint()) == null){ 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 * @return the size of the board
* @author Florian Alexy, Florian Hantzschel
*/ */
public int getSize() { public int getSize() {
return this.size; return this.size;

View File

@ -39,7 +39,7 @@ public class BoardDisplay extends JPanel {
} }
/** /**
* Konstruktor der startLocalGame. * Konstruktor des Board Displays
* @param gridSize Die Größe des Spielfelds * @param gridSize Die Größe des Spielfelds
* @param player Der Spieler * @param player Der Spieler
* @author Lucas Bronson * @author Lucas Bronson

View File

@ -225,6 +225,11 @@ public class GameBoard extends JPanel {
public Player getP1() { public Player getP1() {
return p1; return p1;
} }
/**
* Getter für Player2
* @return Player 2
* @author Luca Conte
*/
public Player getP2() { public Player getP2() {
return p2; return p2;
} }

View File

@ -14,6 +14,7 @@ public class GameController {
private static MainFrame mainFrame; private static MainFrame mainFrame;
/** /**
* returns the current MainFrame
* @return the current MainFrame * @return the current MainFrame
* @author Luca Conte * @author Luca Conte
*/ */
@ -21,6 +22,7 @@ public class GameController {
return GameController.mainFrame; return GameController.mainFrame;
} }
/** /**
* sets the current MainFrame
* @param mainFrame the current MainFrame * @param mainFrame the current MainFrame
* @author Luca Conte * @author Luca Conte
*/ */
@ -124,7 +126,7 @@ public class GameController {
/** /**
* finds the largest common version in two lists of version strings * 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 * @author Luca Conte
*/ */
public static String findMostRecentVersion(List<String> versions1, List<String> versions2) { public static String findMostRecentVersion(List<String> versions1, List<String> versions2) {

View File

@ -1,6 +1,6 @@
/** /**
* Hauptklasse über die der MainFrame gestartet wird * 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 { public class HalloSchiffeVersenken {
@ -8,6 +8,7 @@ public class HalloSchiffeVersenken {
* Erstellt und setzt den Mainframe * Erstellt und setzt den Mainframe
* @param args Argumente an Main durch Konsole etc. * @param args Argumente an Main durch Konsole etc.
* @throws InterruptedException * @throws InterruptedException
* @author Peer Ole Wachtel
*/ */
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
MainFrame mf = new MainFrame(); MainFrame mf = new MainFrame();

View File

@ -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 { public class HitResponse {
/** /**
* Speichert den typ der 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() { public HitResponseType getHitResponse() {
return this.type; return this.type;
} }
/**
* returns the point of the HitResponse
* @return the point of the HitResponse
* @author Florian Hantzschel
*/
public Point getPoint() { public Point getPoint() {
return this.point; return this.point;
} }

View File

@ -1,4 +1,8 @@
/**
* Repräsentiert einen menschlichen Spieler
* @author Luca Conte, Florian Hantzschel
*/
public class HumanPlayer extends LocalPlayer { public class HumanPlayer extends LocalPlayer {
/** /**
* shoots a shot onto the provided point on the enemy board * shoots a shot onto the provided point on the enemy board

View File

@ -1,5 +1,10 @@
import java.util.Random; 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 { public class LocalPlayer extends Player {
@ -77,6 +82,7 @@ public class LocalPlayer extends Player {
/** /**
* sends shot to enemy player. * sends shot to enemy player.
* should ONLY be called on HumanPlayer * should ONLY be called on HumanPlayer
* @author Luca Conte
*/ */
@Override @Override
public void shoot(Point point){ public void shoot(Point point){

View File

@ -6,6 +6,7 @@ import javax.swing.*;
/** /**
* Klasse für Erstellung von looseScreen Objekten * Klasse für Erstellung von looseScreen Objekten
* Dient zur Anzeige das ein Spiel verloren wurde * Dient zur Anzeige das ein Spiel verloren wurde
* @author Joshua Kuklok, Luca Bronson
*/ */
public class LoseScreen extends JPanel { public class LoseScreen extends JPanel {
JLabel loseLabel = new JLabel("Du hast Verloren"); JLabel loseLabel = new JLabel("Du hast Verloren");

View File

@ -126,7 +126,7 @@ public class MainFrame extends JFrame {
* Spezifische ShowPanel für WinScreen Klasse * Spezifische ShowPanel für WinScreen Klasse
* @param panelName Name des anzuzeigenden Panels * @param panelName Name des anzuzeigenden Panels
* @param player Player von dem die funktion aufgerufen worden ist * @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){ public void showPanelWin(String panelName, Player player){
if(player != gameBoard.getP1()){ if(player != gameBoard.getP1()){
@ -149,7 +149,7 @@ public class MainFrame extends JFrame {
* Spezifische ShowPanel für LooseScreen Klasse * Spezifische ShowPanel für LooseScreen Klasse
* @param panelName Name des anzuzeigenden Panels * @param panelName Name des anzuzeigenden Panels
* @param player Player von dem die funktion aufgerufen worden ist * @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){ public void showPanelLose(String panelName, Player player){
if(player != gameBoard.getP1()){ if(player != gameBoard.getP1()){
@ -169,7 +169,7 @@ public class MainFrame extends JFrame {
} }
/** /**
* Aktualisiert das Spielfeld (kontextText) * Aktualisiert das Spielfeld
* @author Luca Conte * @author Luca Conte
*/ */
public void refreshGameBoard() { public void refreshGameBoard() {

View File

@ -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 { public abstract class OnlinePlayer extends Player implements AsyncSocketListener {
protected AsyncSocket socket; protected AsyncSocket socket;
protected int wantedBoardSize; 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 * @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 * 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 * @param socket an AsyncSocket to communicate with the enemy through
* @author Peer Ole Wachtel, Luca Conte
*/ */
public OnlinePlayer(Integer size, AsyncSocket socket) { public OnlinePlayer(Integer size, AsyncSocket socket) {
this.socket = socket; this.socket = socket;
this.wantedBoardSize = size; this.wantedBoardSize = size;
this.myCoin = null; this.myCoin = null;
socket.setHandler(this); socket.setHandler(this);
//TODO Auto-generated constructor stub
} }
/**
* sends the IAM Package for introduction
* @author Luca Conte
*/
public abstract void sendIAM(); public abstract void sendIAM();
/**
* receives a message from the AsyncSocket
* satisfies AsyncSocketListener interface
* @author Luca Conte
*/
public abstract void receive(String message); 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 @Override
public abstract void receiveCoin(boolean coin); public abstract void receiveCoin(boolean coin);

View File

@ -1,6 +1,18 @@
import java.util.List; 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 { 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) { public OnlinePlayer_1_1_0(Integer size, AsyncSocket socket) {
super(size, 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 * receives a shot from the enemy and sends it to the online partner
* if it is not the enemies turn, this method does nothing. * if it is not the enemies turn, this method does nothing.
* @param point the point to be shot * @param point the point to be shot
* @author Peer Ole Wachtel * @author Peer Ole Wachtel, Luca Conte
*/ */
@Override @Override
public synchronized void receiveShoot(Point point){ 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 * receives a hitresponse from the enemy player and sends it to the online partner
* @param hitResponse the hitresponse to be sent * @param hitResponse the hitresponse to be sent
* @author Peer Ole Wachtel * @author Peer Ole Wachtel, Luca Conte
*/ */
@Override @Override
public synchronized void receiveHit(HitResponse hitResponse) { 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 @Override
public synchronized void shoot(Point point) { public synchronized void shoot(Point point) {
// SHOULD NEVER BE CALLED ON ONLINE PLAYER. ONLY ON HUMAN PLAYER // SHOULD NEVER BE CALLED ON ONLINE PLAYER. ONLY ON HUMAN PLAYER
return; return;
} }
/**
* empfängt Withdraw vom Gegner und leitet es an den Online Partner weiter
* beendet das Spiel
* @author Luca Conte
*/
@Override @Override
public void receiveWithdraw() { public void receiveWithdraw() {
this.socket.send(new SocketPackage("WITHDRAW")); this.socket.send(new SocketPackage("WITHDRAW"));

View File

@ -1,3 +1,7 @@
/**
* abstrakte repräsentation eines Spielers
* @author Peer Ole Wachtel, Luca Conte, Lucas Bronson
*/
public abstract class Player { public abstract class Player {
protected boolean myTurn; protected boolean myTurn;
protected boolean isServer; protected boolean isServer;
@ -12,6 +16,10 @@ public abstract class Player {
protected boolean hasReceivedCoin; protected boolean hasReceivedCoin;
/**
* Konstruktor
* @author Peer Ole Wachtel, Luca Conte
*/
public Player() { public Player() {
this.setName("Player"); this.setName("Player");
this.hasReceivedCoin = false; this.hasReceivedCoin = false;
@ -29,10 +37,25 @@ public abstract class Player {
this.board = new Board(size); 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); 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); 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); public abstract void shoot(Point point);
/** /**
@ -60,6 +83,7 @@ public abstract class Player {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/** /**
* returns the name of this player * returns the name of this player
* @return 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 * returns whether this player is ready and has sent their coin to the enemy player
* @return the player's ready state * @return the player's ready state
* @author Lucas Bronson
*/ */
public boolean isReady() { public boolean isReady() {
return this.sentCoin; return this.sentCoin;
@ -137,7 +162,6 @@ public abstract class Player {
* and players * and players
* *
* This method should be called at the end of a game * 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 * @author Luca Conte
*/ */
@ -148,18 +172,39 @@ public abstract class Player {
this.enemy = null; this.enemy = null;
} }
/**
* the player wins
* ends the game
* @author Luca Conte
*/
public void win() { public void win() {
GameController.getMainFrame().showPanelWin("", this); GameController.getMainFrame().showPanelWin("", this);
} }
/**
* the player loses
* ends the game
* @author Luca Conte
*/
public void lose() { public void lose() {
GameController.getMainFrame().showPanelLose("", this); GameController.getMainFrame().showPanelLose("", this);
} }
/**
* the player loses by withdrawal
* ends the game
* @author Luca Conte
*/
public void withdraw() { public void withdraw() {
this.enemy.receiveWithdraw(); this.enemy.receiveWithdraw();
this.lose(); this.lose();
} }
/**
* the enemy player withdraws
* ends the game
* @author Luca Conte
*/
public void receiveWithdraw(){ public void receiveWithdraw(){
this.win(); this.win();
} }

View File

@ -1,3 +1,7 @@
/**
* repräsentation der Koordinaten eines Feldes auf dem Spielfeld
* @author Peer Ole Wachtel, Luca Conte
*/
public class Point { public class Point {
private int x; private int x;
private int y; private int y;

View File

@ -5,6 +5,10 @@ import java.util.List;
record ShipData (int size, String name){} record ShipData (int size, String name){}
/**
* repräsentation eines Schiffes auf dem Spielfeld
* @author Peer Ole Wachtel, Lucas Bronson, Florian Hanzschel
*/
public class Ship { public class Ship {
static List<List<ShipData>> semeterList = static List<List<ShipData>> semeterList =
Arrays.asList( Arrays.asList(
@ -189,7 +193,7 @@ public class Ship {
/** /**
* returns the position of this ship * returns the position of this ship
* @return the position of this ship * @return the position of this ship
* @author Peer Ole Wachte * @author Peer Ole Wachtel
*/ */
public Point getPosition() { public Point getPosition() {
return position; return position;

View File

@ -1,6 +1,8 @@
import java.util.Arrays; import java.util.Arrays;
import java.util.List; 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 * @author Luca Conte
*/ */
public class SocketPackage { 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 * 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` * the package name and data are joined using a space " " `0x20`
* @return the package in string format * @return the package in string format
* @author Luca Conte
*/ */
public String toString() { public String toString() {
if (this.data == null || this.data.length() == 0) { if (this.data == null || this.data.length() == 0) {

View File

@ -1,10 +1,10 @@
import java.util.ArrayList;
// import java.util.Random; wird nicht mehr verwendet
/** /**
* Diese Klasse implementiert den Harten Ki Spieler. * Diese Klasse implementiert den Harten Ki Spieler.
* @author Florian Alexy und Florian Hantzschel * @author Florian Alexy und Florian Hantzschel
* */ * */
import java.util.ArrayList;
// import java.util.Random; wird nicht mehr verwendet
public class SpecificAiPlayerHard extends AiPlayer{ public class SpecificAiPlayerHard extends AiPlayer{
private int gridSize; private int gridSize;
@ -21,7 +21,8 @@ public class SpecificAiPlayerHard extends AiPlayer{
VERTIKAL VERTIKAL
} }
private Orientierung orientierung; 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;
/** /**

View File

@ -1,10 +1,10 @@
import java.util.ArrayList;
import java.util.List;
/** /**
* Diese Klasse implementiert den Medium Ki Spieler. * Diese Klasse implementiert den Medium Ki Spieler.
* @author Florian Alexy und Florian Hantzschel * @author Florian Alexy und Florian Hantzschel
* */ * */
import java.util.ArrayList;
import java.util.List;
public class SpecificAiPlayerMedium extends AiPlayer{ public class SpecificAiPlayerMedium extends AiPlayer{
/** /**
* Liste an Punkten die beschossen werden sollen. (Mögliche weitere Segmente vom schiff) * 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. * 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 * @author Florian Alexy und Florian Hantzschel
*/ */
public Point ComputeNextShot() { 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. * 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 * @author Florian Alexy und Florian Hantzschel
*/ */
private void addAdjacentPoints(Point point) { private void addAdjacentPoints(Point point) {

View File

@ -225,10 +225,13 @@ public class startLocalGame extends JPanel {
private void toggleLeftPlayerIconLeft() { private void toggleLeftPlayerIconLeft() {
if (leftPlayerIcon.getIcon() == humanPlayerIcon) { if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
leftPlayerIcon.setIcon(aiPlayerHardIcon); leftPlayerIcon.setIcon(aiPlayerHardIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){ } else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
leftPlayerIcon.setIcon(humanPlayerIcon); leftPlayerIcon.setIcon(humanPlayerIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
leftPlayerIcon.setIcon(aiPlayerEasyIcon); leftPlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) {
leftPlayerIcon.setIcon(aiPlayerNormalIcon); leftPlayerIcon.setIcon(aiPlayerNormalIcon);
} }
@ -241,10 +244,13 @@ public class startLocalGame extends JPanel {
private void toggleLeftPlayerIconRight() { private void toggleLeftPlayerIconRight() {
if (leftPlayerIcon.getIcon() == humanPlayerIcon) { if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
leftPlayerIcon.setIcon(aiPlayerEasyIcon); leftPlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){ } else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
leftPlayerIcon.setIcon(aiPlayerNormalIcon); leftPlayerIcon.setIcon(aiPlayerNormalIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
leftPlayerIcon.setIcon(aiPlayerHardIcon); leftPlayerIcon.setIcon(aiPlayerHardIcon);
} else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) {
leftPlayerIcon.setIcon(humanPlayerIcon); leftPlayerIcon.setIcon(humanPlayerIcon);
} }
@ -257,8 +263,10 @@ public class startLocalGame extends JPanel {
private void toggleRightPlayerIconLeft() { private void toggleRightPlayerIconLeft() {
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) { if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
rightPlayerIcon.setIcon(aiPlayerHardIcon); rightPlayerIcon.setIcon(aiPlayerHardIcon);
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){ } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){
rightPlayerIcon.setIcon(aiPlayerEasyIcon); rightPlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
rightPlayerIcon.setIcon(aiPlayerNormalIcon); rightPlayerIcon.setIcon(aiPlayerNormalIcon);
} }
@ -271,8 +279,10 @@ public class startLocalGame extends JPanel {
private void toggleRightPlayerIconRight() { private void toggleRightPlayerIconRight() {
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) { if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon) {
rightPlayerIcon.setIcon(aiPlayerNormalIcon); rightPlayerIcon.setIcon(aiPlayerNormalIcon);
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){ } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon){
rightPlayerIcon.setIcon(aiPlayerHardIcon); rightPlayerIcon.setIcon(aiPlayerHardIcon);
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
rightPlayerIcon.setIcon(aiPlayerEasyIcon); rightPlayerIcon.setIcon(aiPlayerEasyIcon);
} }
@ -286,10 +296,13 @@ public class startLocalGame extends JPanel {
// Für Linken Spieler // Für Linken Spieler
if (leftPlayerIcon.getIcon() == humanPlayerIcon) { if (leftPlayerIcon.getIcon() == humanPlayerIcon) {
leftPlayerTextField.setText(leftPlayerNickname); leftPlayerTextField.setText(leftPlayerNickname);
} else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){ } else if (leftPlayerIcon.getIcon() == aiPlayerEasyIcon){
leftPlayerTextField.setText("Einfach"); leftPlayerTextField.setText("Einfach");
} else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if (leftPlayerIcon.getIcon() == aiPlayerNormalIcon) {
leftPlayerTextField.setText("Mittel"); leftPlayerTextField.setText("Mittel");
} else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (leftPlayerIcon.getIcon() == aiPlayerHardIcon) {
leftPlayerTextField.setText("Schwer"); leftPlayerTextField.setText("Schwer");
} }
@ -297,8 +310,10 @@ public class startLocalGame extends JPanel {
// Für Rechten Spieler // Für Rechten Spieler
if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon){ if (rightPlayerIcon.getIcon() == aiPlayerEasyIcon){
rightPlayerTextField.setText("Einfach"); rightPlayerTextField.setText("Einfach");
} else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if (rightPlayerIcon.getIcon() == aiPlayerNormalIcon) {
rightPlayerTextField.setText("Mittel"); rightPlayerTextField.setText("Mittel");
} else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (rightPlayerIcon.getIcon() == aiPlayerHardIcon) {
rightPlayerTextField.setText("Schwer"); rightPlayerTextField.setText("Schwer");
} }

View File

@ -192,10 +192,13 @@ public class startMultiplayerGame extends JPanel {
private void togglePlayerIconLeft() { private void togglePlayerIconLeft() {
if (PlayerIcon.getIcon() == humanPlayerIcon) { if (PlayerIcon.getIcon() == humanPlayerIcon) {
PlayerIcon.setIcon(aiPlayerHardIcon); PlayerIcon.setIcon(aiPlayerHardIcon);
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){ } else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
PlayerIcon.setIcon(humanPlayerIcon); PlayerIcon.setIcon(humanPlayerIcon);
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
PlayerIcon.setIcon(aiPlayerEasyIcon); PlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
PlayerIcon.setIcon(aiPlayerNormalIcon); PlayerIcon.setIcon(aiPlayerNormalIcon);
} }
@ -208,10 +211,13 @@ public class startMultiplayerGame extends JPanel {
private void togglePlayerIconRight() { private void togglePlayerIconRight() {
if (PlayerIcon.getIcon() == humanPlayerIcon) { if (PlayerIcon.getIcon() == humanPlayerIcon) {
PlayerIcon.setIcon(aiPlayerEasyIcon); PlayerIcon.setIcon(aiPlayerEasyIcon);
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){ } else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
PlayerIcon.setIcon(aiPlayerNormalIcon); PlayerIcon.setIcon(aiPlayerNormalIcon);
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
PlayerIcon.setIcon(aiPlayerHardIcon); PlayerIcon.setIcon(aiPlayerHardIcon);
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
PlayerIcon.setIcon(humanPlayerIcon); PlayerIcon.setIcon(humanPlayerIcon);
} }
@ -224,10 +230,13 @@ public class startMultiplayerGame extends JPanel {
private void updateTextFields() { private void updateTextFields() {
if (PlayerIcon.getIcon() == humanPlayerIcon) { if (PlayerIcon.getIcon() == humanPlayerIcon) {
PlayerTextField.setText(PlayerNickname); PlayerTextField.setText(PlayerNickname);
} else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){ } else if (PlayerIcon.getIcon() == aiPlayerEasyIcon){
PlayerTextField.setText("Einfach"); PlayerTextField.setText("Einfach");
} else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) { } else if (PlayerIcon.getIcon() == aiPlayerNormalIcon) {
PlayerTextField.setText("Mittel"); PlayerTextField.setText("Mittel");
} else if (PlayerIcon.getIcon() == aiPlayerHardIcon) { } else if (PlayerIcon.getIcon() == aiPlayerHardIcon) {
PlayerTextField.setText("Schwer"); PlayerTextField.setText("Schwer");
} }