Merge pull request 'Add komentare' (#27) from ole into main
Reviewed-on: #27
This commit is contained in:
commit
27157fb0a3
|
@ -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
|
* @author Peer Ole Wachtel, Florian Alexy und Florian Hantzschel
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -8,13 +10,27 @@ import java.util.List;
|
||||||
|
|
||||||
public class Board {
|
public class Board {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Alle bisher empfangenen HitResponsen
|
||||||
|
*/
|
||||||
private List<HitResponse> hits;
|
private List<HitResponse> hits;
|
||||||
private List<Ship> ships;
|
|
||||||
private final int size;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialisiert das Board und die zu Setzenden schiffe.
|
* Alle Schiffe des Semesters
|
||||||
* @param size
|
*/
|
||||||
|
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
|
* @author Peer Ole Wachtel, Florian Alexy und Florian Hantzschel
|
||||||
*/
|
*/
|
||||||
public Board(int size) {
|
public Board(int size) {
|
||||||
|
@ -24,6 +40,12 @@ public class Board {
|
||||||
this.createShip(size - 13);
|
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){
|
public synchronized HitResponse hit (Point point){
|
||||||
HitResponse response = new HitResponse(HitResponseType.MISS,point);
|
HitResponse response = new HitResponse(HitResponseType.MISS,point);
|
||||||
for (int i = 0; i < this.ships.size(); i++) {
|
for (int i = 0; i < this.ships.size(); i++) {
|
||||||
|
@ -115,6 +137,7 @@ public class Board {
|
||||||
/**
|
/**
|
||||||
* @param point the position to get the hit response from
|
* @param point the position to get the hit response from
|
||||||
* @return the hit response at the position `point`
|
* @return the hit response at the position `point`
|
||||||
|
* @author Peer Ole Wachtel
|
||||||
*/
|
*/
|
||||||
public synchronized HitResponse getHitResponseOnPoint(Point point) {
|
public synchronized HitResponse getHitResponseOnPoint(Point point) {
|
||||||
for (int i = 0; i < this.hits.size(); i++){
|
for (int i = 0; i < this.hits.size(); i++){
|
||||||
|
|
|
@ -1,14 +1,33 @@
|
||||||
|
|
||||||
|
|
||||||
public class HitResponse {
|
public class HitResponse {
|
||||||
|
/**
|
||||||
|
* Speichert den typ der HitResponse.
|
||||||
|
*/
|
||||||
private HitResponseType type;
|
private HitResponseType type;
|
||||||
|
/**
|
||||||
|
* Speicher den Punkt wofür die HitResponse gilt.
|
||||||
|
*/
|
||||||
private Point point;
|
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) {
|
public HitResponse(HitResponseType type, Point point) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.point = point;
|
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) {
|
public HitResponse (int typeIndex, Point point) {
|
||||||
if (typeIndex >= 0 && typeIndex < HitResponseType.values().length) {
|
if (typeIndex >= 0 && typeIndex < HitResponseType.values().length) {
|
||||||
this.type = HitResponseType.values()[typeIndex];
|
this.type = HitResponseType.values()[typeIndex];
|
||||||
|
@ -26,15 +45,30 @@ public class HitResponse {
|
||||||
return this.point;
|
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) {
|
public void setType(HitResponseType type) {
|
||||||
this.type = 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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.getPoint().toString() + " " + this.type.ordinal();
|
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() {
|
public HitResponseType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
/**
|
||||||
|
* Stellt die verschiedenen möglichkeiten einer HitResponse als typ dar.
|
||||||
|
* @author Peer Ole Wachtel
|
||||||
|
*/
|
||||||
public enum HitResponseType {
|
public enum HitResponseType {
|
||||||
MISS, HIT, SUNK, VICTORY
|
MISS, HIT, SUNK, VICTORY
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,11 @@ import java.util.Random;
|
||||||
|
|
||||||
public class LocalPlayer extends Player {
|
public class LocalPlayer extends Player {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* erstellt einen LocalPlayer und setzt myCoin random
|
||||||
|
* @author Peer Ole Wachtel
|
||||||
|
*/
|
||||||
public LocalPlayer(){
|
public LocalPlayer(){
|
||||||
super();
|
super();
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
|
|
|
@ -6,6 +6,7 @@ public class Point {
|
||||||
* initialises a point using X and Y coordinates starting at 0
|
* initialises a point using X and Y coordinates starting at 0
|
||||||
* @param x the x coordinate of the point 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
|
* @param y the y coordinate of the point starting at 0
|
||||||
|
* @author Peer Ole Wachtel
|
||||||
*/
|
*/
|
||||||
public Point (int x, int y) {
|
public Point (int x, int y) {
|
||||||
this.setX(x);
|
this.setX(x);
|
||||||
|
|
Loading…
Reference in New Issue