Merge pull request 'Add komentare' (#27) from ole into main

Reviewed-on: #27
This commit is contained in:
Luca Conte 2024-12-23 19:49:01 +00:00
commit 27157fb0a3
5 changed files with 73 additions and 6 deletions

View File

@ -1,5 +1,7 @@
/**
* Die Board-Klasse repräsentiert das Spielfeld.
* 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
*/
@ -8,13 +10,27 @@ import java.util.List;
public class Board {
/**
* Alle bisher empfangenen HitResponsen
*/
private List<HitResponse> hits;
private List<Ship> ships;
private final int size;
/**
* Initialisiert das Board und die zu Setzenden schiffe.
* @param size
* Alle Schiffe des Semesters
*/
private List<Ship> ships;
/**
* Die größe des Spielfeldes
*/
private final int size;
/**
* Erstellt ein neues Board.
* setzt die übergebene Spielfeldgröße.
* Erstellt die Liste aller Schiffe des Semesters
* @param size Die größe des Spielfeldes
* @author Peer Ole Wachtel, Florian Alexy und Florian Hantzschel
*/
public Board(int size) {
@ -24,6 +40,12 @@ public class Board {
this.createShip(size - 13);
}
/**
* Nimmt einen punkt entgegen und Gibt einen Hitrespons zurück.
* @param point auf den geschossen wurde
* @return
* @author Peer Ole Wachtel
*/
public synchronized HitResponse hit (Point point){
HitResponse response = new HitResponse(HitResponseType.MISS,point);
for (int i = 0; i < this.ships.size(); i++) {
@ -95,7 +117,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
*
*
*/
public synchronized boolean addHits(HitResponse hitResponse) {
if (this.getHitResponseOnPoint(hitResponse.getPoint()) == null){
@ -115,6 +137,7 @@ public class Board {
/**
* @param point the position to get the hit response from
* @return the hit response at the position `point`
* @author Peer Ole Wachtel
*/
public synchronized HitResponse getHitResponseOnPoint(Point point) {
for (int i = 0; i < this.hits.size(); i++){

View File

@ -1,14 +1,33 @@
public class HitResponse {
/**
* Speichert den typ der HitResponse.
*/
private HitResponseType type;
/**
* Speicher den Punkt wofür die HitResponse gilt.
*/
private Point point;
/**
* Erstellt eine neue HitResponse und setzt den Punkt und typ.
* @param type der HitResponse.
* @param point für den die HitResponse gilt.
* @author Peer Ole Wachtel.
*/
public HitResponse(HitResponseType type, Point point) {
this.type = type;
this.point = point;
}
/**
*Erstellt eine neue HitResponse und setzt den Punkt und typ.
* @param typeIndex der HitResponse.
* @param point für den die HitResponse gilt.
* @throws IllegalArgumentException wenn der übergebene int nicht auf ein typ referenziert werden kann.
* @author Peer Ole Wachtel.
*/
public HitResponse (int typeIndex, Point point) {
if (typeIndex >= 0 && typeIndex < HitResponseType.values().length) {
this.type = HitResponseType.values()[typeIndex];
@ -26,15 +45,30 @@ public class HitResponse {
return this.point;
}
/**
* Setter für den type
* @param type auf den die HitResponse gesetzt werden soll.
* @author Peer Ole Wachtel
*/
public void setType(HitResponseType type) {
this.type = type;
}
/**
* Gibt den passenden string nach Netzwerkstandard für eine HitResponse zurück.
* @return den passenden string nach Netzwerkstandard für eine HitResponse.
* @author Peer Ole Wachtel.
*/
@Override
public String toString() {
return this.getPoint().toString() + " " + this.type.ordinal();
}
/**
* Getter für den typ der HitResponse.
* @return den typ der HitRespnse.
* @author Peer Ole Wachtel.
*/
public HitResponseType getType() {
return type;
}

View File

@ -1,3 +1,7 @@
/**
* Stellt die verschiedenen möglichkeiten einer HitResponse als typ dar.
* @author Peer Ole Wachtel
*/
public enum HitResponseType {
MISS, HIT, SUNK, VICTORY
}

View File

@ -2,6 +2,11 @@ import java.util.Random;
public class LocalPlayer extends Player {
/**
* erstellt einen LocalPlayer und setzt myCoin random
* @author Peer Ole Wachtel
*/
public LocalPlayer(){
super();
Random random = new Random();

View File

@ -6,6 +6,7 @@ public class Point {
* initialises a point using X and Y coordinates starting at 0
* @param x the x coordinate of the point starting at 0
* @param y the y coordinate of the point starting at 0
* @author Peer Ole Wachtel
*/
public Point (int x, int y) {
this.setX(x);