java-dhbw/SchiffeVersenken/src/Schiff.java
2023-04-24 14:04:50 +02:00

51 lines
1.3 KiB
Java

public abstract class Schiff {
public int laenge;
public char repr = '?';
public Schiff(int schiffLaenge) {
laenge = schiffLaenge;
}
public char repr() {
return this.repr;
}
public boolean insertToMap(int x, int y, Feld map, char orientation) {
if (orientation == '>') {
for (int i = 0; i < this.laenge; i++){
if (!map.insertShip(this, x+i, y)) {
return false;
}
}
return true;
}
else if (orientation == '<') {
for (int i = 0; i < this.laenge; i++){
if (!map.insertShip(this, x-i, y)) {
return false;
}
}
return true;
}
else if (orientation == 'v') {
for (int i = 0; i < this.laenge; i++){
if (!map.insertShip(this, x, y+i)) {
return false;
}
}
return true;
}
else if (orientation == '|') {
for (int i = 0; i < this.laenge; i++){
if (!map.insertShip(this, x, y-i)) {
return false;
}
}
return true;
}
return false;
}
public Schiff() {
}
}