Merge pull request 'die letzten javadoc kommentare' (#23) from cleanup-work into main
Reviewed-on: #23
This commit is contained in:
commit
d97826db6c
|
@ -60,6 +60,12 @@ public class Ship {
|
|||
private int hitsOnMe;
|
||||
private boolean sunk;
|
||||
|
||||
/**
|
||||
* initialises a Ship with a given size and name
|
||||
* @param size the size of the ship
|
||||
* @param name the name of the ship
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public Ship (int size, String name) {
|
||||
this.size = size;
|
||||
this.name = name;
|
||||
|
@ -69,10 +75,23 @@ public class Ship {
|
|||
this.sunk = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* resets the position of this ship
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void resetPosition() {
|
||||
this.position = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the position of this ship, provided it is valid
|
||||
* @param pos the position to move the ship to
|
||||
* @param horizontal whether the ship is horizontal or not
|
||||
* @param shipsList the list of other ships on this board. It will be checked whether the ship is touching any of them
|
||||
* @param boardSize the size of the board the ship is to be placed on
|
||||
* @return true if the position was set successfully. false if the ship is out of the bounds of the board or touches a different ship
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public boolean setPosition(Point pos, boolean horizontal, List<Ship> shipsList, int boardSize) {
|
||||
if (!this.checkValidPlacement(pos, horizontal, shipsList, boardSize)) return false;
|
||||
|
||||
|
@ -82,6 +101,15 @@ public class Ship {
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks whether a position is valid for ship placement
|
||||
* @param pos the position to check the ship placement at
|
||||
* @param horizontal whether the ship is to be placed horizontally or not
|
||||
* @param shipsList the list of other ships on this board. It will be checked whether the ship is touching any of them
|
||||
* @param boardSize the size of the board the ship is to be placed on
|
||||
* @return true if the position is valid. false if the ship is out of the bounds of the board or touches a different ship
|
||||
* @author Florian Hantzschel, Peer Ole Wachtel, Luca Conte
|
||||
*/
|
||||
public boolean checkValidPlacement(Point pos, boolean horizontal, List<Ship> shipsList, int boardSize) {
|
||||
// ueberpruefe boundaries
|
||||
if (pos.getX() < 0 || pos.getY() < 0 || pos.getX() >= boardSize || pos.getY() >= boardSize) {
|
||||
|
@ -130,7 +158,11 @@ public class Ship {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns the Points on the ship if it were to be placed at positino `pos` in orientation defined by `horizontal`
|
||||
* Returns the Points on the ship if it were to be placed at position `pos` in orientation defined by `horizontal`
|
||||
* @param pos the position where the ship should be placed
|
||||
* @param horizontal whether the ship should be placed horizontally
|
||||
* @return a list of points the ship would occupy, were it placed at position `pos` in orientation `horizontal`
|
||||
* @author Florian Hantzschel, Luca Conte
|
||||
*/
|
||||
public List<Point> getVirtualOccupiedPoints(Point pos, boolean horizontal) {
|
||||
List<Point> points = new ArrayList<>();
|
||||
|
@ -145,23 +177,30 @@ public class Ship {
|
|||
return points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Points the ship occupies
|
||||
* @return a list of points the ship occupies
|
||||
* @author Florian Hantzschel, Luca Conte
|
||||
*/
|
||||
public List<Point> getOccupiedPoints() {
|
||||
List<Point> points = new ArrayList<>();
|
||||
if (this.position == null) {
|
||||
return points;
|
||||
}
|
||||
for (int i = 0; i < this.size; i++) {
|
||||
int x = this.horizontal ? this.position.getX() + i : this.position.getX();
|
||||
int y = this.horizontal ? this.position.getY() : this.position.getY() + i;
|
||||
points.add(new Point(x, y));
|
||||
}
|
||||
return points;
|
||||
return this.getVirtualOccupiedPoints(this.position, this.horizontal);
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the position of this ship
|
||||
* @return the position of this ship
|
||||
* @author Peer Ole Wachte
|
||||
*/
|
||||
public Point getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* checks whether the ship occupies a certain point
|
||||
* @param pos the point to be checkd
|
||||
* @return whether the point provided is one of the points occupied by the ship
|
||||
* @author Peer Ole Wachtel, Lucas Bronson
|
||||
*/
|
||||
public boolean isShipOnPos(Point pos){
|
||||
if(this.position == null){
|
||||
return false;
|
||||
|
@ -173,6 +212,13 @@ public class Ship {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* "shoots" this ship.
|
||||
* @return a hit response, depending on whether the ship was hit or not. If the amount of times
|
||||
* the ship was hit is greater or equal to the size of the ship, the ship is considered sunk.
|
||||
* @param pos the point where the ship is shot
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public HitResponseType shootOnShip(Point pos) {
|
||||
if (this.isShipOnPos(pos)) {
|
||||
hitsOnMe++;
|
||||
|
@ -187,22 +233,47 @@ public class Ship {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns whether the ship has been sunk or not
|
||||
* @return whether the ship has been sunk or not
|
||||
* @author Peer Ole Wachtel
|
||||
*/
|
||||
public boolean isSunk() {
|
||||
return sunk;
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the orientation of the ship
|
||||
* @param horizontal whether the ship is to be placed in a horizontal orientation
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public void setHorizontal(boolean horizontal) {
|
||||
this.horizontal = horizontal;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the size of the ship
|
||||
* @return the size of the ship
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the name of the ship
|
||||
* @return the name of the ship
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
//potentiell falsch neu
|
||||
/**
|
||||
* returns whether the ship has been placed or not
|
||||
* @return whether the ship has been placed or not
|
||||
* @author Lucas Bronson
|
||||
*/
|
||||
public boolean isPlaced(){
|
||||
return this.position != null;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,37 @@
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
/**
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public class SocketPackage {
|
||||
|
||||
private String name = "";
|
||||
private String data = "";
|
||||
|
||||
/**
|
||||
* initialises a socket package by prividing a package name and data
|
||||
* @param name the name of the package
|
||||
* @param data the data of the package
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public SocketPackage(String name, String data) {
|
||||
this.setName(name);
|
||||
this.setData(data);
|
||||
}
|
||||
/**
|
||||
* initialises an empty socket package
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public SocketPackage() {
|
||||
this("","");
|
||||
}
|
||||
|
||||
/**
|
||||
* initialises a socket package from a message
|
||||
* the message is parsed according to https://github.com/lgc-4/ProgProjekt-Netzwerkstandard
|
||||
* @param message the message to be parsed
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public SocketPackage(String message) {
|
||||
if (message.length() <= 0) {
|
||||
throw new IllegalArgumentException("Socket message cannot be empty.");
|
||||
|
@ -25,24 +45,50 @@ public class SocketPackage {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the package name
|
||||
* the name is always stored in upper case
|
||||
* @param name the new name of the package
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void setName(String name) {
|
||||
if (name == null) name = "";
|
||||
this.name = name.toUpperCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* sets the package data
|
||||
* @param name the new data of the package
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public void setData(String data) {
|
||||
if (data == null) data = "";
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the name of the package
|
||||
* @return the name of the package
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the data of the package
|
||||
* @return the data of the package
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public String getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public String toString() {
|
||||
if (this.data == null || this.data.length() == 0) {
|
||||
return this.name;
|
||||
|
@ -51,6 +97,11 @@ public class SocketPackage {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the data string as a list, split at every space " " `0x20`
|
||||
* @return the data string as a list, split at every space " " `0x20`
|
||||
* @author Luca Conte
|
||||
*/
|
||||
public List<String> splitData() {
|
||||
return Arrays.asList(this.data.split(" "));
|
||||
}
|
||||
|
|
|
@ -67,9 +67,9 @@ public class SoundHandler {
|
|||
}
|
||||
|
||||
/**
|
||||
* TODO funktion beschreiben (potentiell nicht benötigte Funktion?)
|
||||
* @param soundName
|
||||
* @param path
|
||||
* fügt einen neuen Sound zum SoundHanlder hinzu
|
||||
* @param soundName der intern zu verwendende Name des Sounds
|
||||
* @param path der Dateipfad zur Sound Datei
|
||||
* @author Ole Wachtel
|
||||
*/
|
||||
static void add(String soundName, String path){
|
||||
|
@ -77,8 +77,8 @@ public class SoundHandler {
|
|||
}
|
||||
|
||||
/**
|
||||
* TODO funktion beschreiben (potentiell nicht benötigte Funktion?)
|
||||
* @param sound
|
||||
* schaltet den Ton an oder aus
|
||||
* @param sound ob der sound an ist
|
||||
* @author Ole Wachtel
|
||||
*/
|
||||
static void setSoundOn(boolean sound){
|
||||
|
|
Loading…
Reference in New Issue