add Komentare
This commit is contained in:
parent
d97826db6c
commit
70749c2c62
|
@ -1,14 +1,38 @@
|
|||
/**
|
||||
* Diese Klasse ist das Board von eimem spieler und enthält alle logischen operationen.
|
||||
* Sprich ist das Backend Board.
|
||||
*
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Board {
|
||||
|
||||
/**
|
||||
* Alle bisher empfangenen HitResponsen
|
||||
*/
|
||||
private List<HitResponse> hits;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public Board(int size) {
|
||||
this.size = size;
|
||||
this.ships = new ArrayList<>();
|
||||
|
@ -16,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++) {
|
||||
|
@ -64,6 +94,7 @@ public class Board {
|
|||
/**
|
||||
* creates all the ships on a board given a certain semester
|
||||
* @param semester the semester to be played in
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
private void createShip(int semester){
|
||||
List<ShipData> shipData = Ship.semeterList.get(semester -1);
|
||||
|
@ -86,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){
|
||||
|
@ -106,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++){
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -31,7 +31,8 @@ public abstract class Player {
|
|||
|
||||
public abstract void receiveShoot(Point point);
|
||||
|
||||
public abstract void receiveHit(HitResponse hitResponse);
|
||||
public abstract
|
||||
void receiveHit(HitResponse hitResponse);
|
||||
|
||||
public abstract void shoot(Point point);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue