die letzten javadoc kommentare #23
|
@ -60,6 +60,12 @@ public class Ship {
|
||||||
private int hitsOnMe;
|
private int hitsOnMe;
|
||||||
private boolean sunk;
|
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) {
|
public Ship (int size, String name) {
|
||||||
this.size = size;
|
this.size = size;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
@ -69,10 +75,23 @@ public class Ship {
|
||||||
this.sunk = false;
|
this.sunk = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* resets the position of this ship
|
||||||
|
* @author Luca Conte
|
||||||
|
*/
|
||||||
public void resetPosition() {
|
public void resetPosition() {
|
||||||
this.position = null;
|
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) {
|
public boolean setPosition(Point pos, boolean horizontal, List<Ship> shipsList, int boardSize) {
|
||||||
if (!this.checkValidPlacement(pos, horizontal, shipsList, boardSize)) return false;
|
if (!this.checkValidPlacement(pos, horizontal, shipsList, boardSize)) return false;
|
||||||
|
|
||||||
|
@ -82,6 +101,15 @@ public class Ship {
|
||||||
return true;
|
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) {
|
public boolean checkValidPlacement(Point pos, boolean horizontal, List<Ship> shipsList, int boardSize) {
|
||||||
// ueberpruefe boundaries
|
// ueberpruefe boundaries
|
||||||
if (pos.getX() < 0 || pos.getY() < 0 || pos.getX() >= boardSize || pos.getY() >= boardSize) {
|
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) {
|
public List<Point> getVirtualOccupiedPoints(Point pos, boolean horizontal) {
|
||||||
List<Point> points = new ArrayList<>();
|
List<Point> points = new ArrayList<>();
|
||||||
|
@ -145,23 +177,30 @@ public class Ship {
|
||||||
return points;
|
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() {
|
public List<Point> getOccupiedPoints() {
|
||||||
List<Point> points = new ArrayList<>();
|
return this.getVirtualOccupiedPoints(this.position, this.horizontal);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the position of this ship
|
||||||
|
* @return the position of this ship
|
||||||
|
* @author Peer Ole Wachte
|
||||||
|
*/
|
||||||
public Point getPosition() {
|
public Point getPosition() {
|
||||||
return position;
|
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){
|
public boolean isShipOnPos(Point pos){
|
||||||
if(this.position == null){
|
if(this.position == null){
|
||||||
return false;
|
return false;
|
||||||
|
@ -173,6 +212,13 @@ public class Ship {
|
||||||
return false;
|
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) {
|
public HitResponseType shootOnShip(Point pos) {
|
||||||
if (this.isShipOnPos(pos)) {
|
if (this.isShipOnPos(pos)) {
|
||||||
hitsOnMe++;
|
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() {
|
public boolean isSunk() {
|
||||||
return sunk;
|
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) {
|
public void setHorizontal(boolean horizontal) {
|
||||||
this.horizontal = horizontal;
|
this.horizontal = horizontal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the size of the ship
|
||||||
|
* @return the size of the ship
|
||||||
|
* @author Lucas Bronson
|
||||||
|
*/
|
||||||
public int getSize() {
|
public int getSize() {
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the name of the ship
|
||||||
|
* @return the name of the ship
|
||||||
|
* @author Lucas Bronson
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
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(){
|
public boolean isPlaced(){
|
||||||
return this.position != null;
|
return this.position != null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,37 @@
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
/**
|
||||||
|
* @author Luca Conte
|
||||||
|
*/
|
||||||
public class SocketPackage {
|
public class SocketPackage {
|
||||||
|
|
||||||
private String name = "";
|
private String name = "";
|
||||||
private String data = "";
|
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) {
|
public SocketPackage(String name, String data) {
|
||||||
this.setName(name);
|
this.setName(name);
|
||||||
this.setData(data);
|
this.setData(data);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* initialises an empty socket package
|
||||||
|
* @author Luca Conte
|
||||||
|
*/
|
||||||
public SocketPackage() {
|
public SocketPackage() {
|
||||||
this("","");
|
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) {
|
public SocketPackage(String message) {
|
||||||
if (message.length() <= 0) {
|
if (message.length() <= 0) {
|
||||||
throw new IllegalArgumentException("Socket message cannot be empty.");
|
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) {
|
public void setName(String name) {
|
||||||
if (name == null) name = "";
|
if (name == null) name = "";
|
||||||
this.name = name.toUpperCase();
|
this.name = name.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* sets the package data
|
||||||
|
* @param name the new data of the package
|
||||||
|
* @author Luca Conte
|
||||||
|
*/
|
||||||
public void setData(String data) {
|
public void setData(String data) {
|
||||||
if (data == null) data = "";
|
if (data == null) data = "";
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the name of the package
|
||||||
|
* @return the name of the package
|
||||||
|
* @author Luca Conte
|
||||||
|
*/
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns the data of the package
|
||||||
|
* @return the data of the package
|
||||||
|
* @author Luca Conte
|
||||||
|
*/
|
||||||
public String getData() {
|
public String getData() {
|
||||||
return this.data;
|
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() {
|
public String toString() {
|
||||||
if (this.data == null || this.data.length() == 0) {
|
if (this.data == null || this.data.length() == 0) {
|
||||||
return this.name;
|
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() {
|
public List<String> splitData() {
|
||||||
return Arrays.asList(this.data.split(" "));
|
return Arrays.asList(this.data.split(" "));
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,9 +67,9 @@ public class SoundHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO funktion beschreiben (potentiell nicht benötigte Funktion?)
|
* fügt einen neuen Sound zum SoundHanlder hinzu
|
||||||
* @param soundName
|
* @param soundName der intern zu verwendende Name des Sounds
|
||||||
* @param path
|
* @param path der Dateipfad zur Sound Datei
|
||||||
* @author Ole Wachtel
|
* @author Ole Wachtel
|
||||||
*/
|
*/
|
||||||
static void add(String soundName, String path){
|
static void add(String soundName, String path){
|
||||||
|
@ -77,8 +77,8 @@ public class SoundHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO funktion beschreiben (potentiell nicht benötigte Funktion?)
|
* schaltet den Ton an oder aus
|
||||||
* @param sound
|
* @param sound ob der sound an ist
|
||||||
* @author Ole Wachtel
|
* @author Ole Wachtel
|
||||||
*/
|
*/
|
||||||
static void setSoundOn(boolean sound){
|
static void setSoundOn(boolean sound){
|
||||||
|
|
Loading…
Reference in New Issue