|
|
|
@ -7,25 +7,18 @@ public class Ship{ |
|
|
|
private int[] end; |
|
|
|
private int length; |
|
|
|
|
|
|
|
|
|
|
|
public Ship(int[] start,int[] end){ |
|
|
|
int cord; |
|
|
|
boolean vertical = start[Y] == end[Y]; |
|
|
|
this.vertical = vertical; |
|
|
|
if (vertical) { |
|
|
|
cord = X; |
|
|
|
} |
|
|
|
else { |
|
|
|
cord = Y; |
|
|
|
} |
|
|
|
if (start[cord] < end[cord]){ |
|
|
|
this.start = start; |
|
|
|
this.end = end; |
|
|
|
this.correctSE(); |
|
|
|
int cord; |
|
|
|
if (this.vertical) { |
|
|
|
cord = Y; |
|
|
|
} |
|
|
|
else { |
|
|
|
this.start = end; |
|
|
|
this.end = start; |
|
|
|
cord = X; |
|
|
|
} |
|
|
|
|
|
|
|
this.length = this.end[cord] - this.start[cord]+1; |
|
|
|
} |
|
|
|
|
|
|
|
@ -73,13 +66,14 @@ public class Ship{ |
|
|
|
} |
|
|
|
|
|
|
|
// ensures start and end are in the right place |
|
|
|
private void correntSE(){ |
|
|
|
private void correctSE(){ |
|
|
|
int cord; |
|
|
|
this.vertical = this.start[X] == this.end[X]; |
|
|
|
if (this.vertical) { |
|
|
|
cord = X; |
|
|
|
cord = Y; |
|
|
|
} |
|
|
|
else { |
|
|
|
cord = Y; |
|
|
|
cord = X; |
|
|
|
} |
|
|
|
|
|
|
|
int[] third_point; |
|
|
|
@ -122,7 +116,7 @@ public class Ship{ |
|
|
|
for (int i = 0; i < n; i++){ |
|
|
|
this.rotate(point); |
|
|
|
} |
|
|
|
this.correntSE(); |
|
|
|
this.correctSE(); |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isVertical() { |
|
|
|
@ -190,16 +184,19 @@ public class Ship{ |
|
|
|
} |
|
|
|
|
|
|
|
public void placeOnBoard(int[][] board){ |
|
|
|
int x_col = this.start[X] |
|
|
|
this.correctSE(); |
|
|
|
int x_col = this.start[X]; |
|
|
|
int y_col = this.start[Y]; |
|
|
|
int c; |
|
|
|
if (this.vertical){ |
|
|
|
for (int c = this.start[Y];c <= this.end[Y];c++){ |
|
|
|
board[x_col][c] = this.length; |
|
|
|
for (c = this.start[Y];c <= this.end[Y];c++){ |
|
|
|
System.out.println(c); |
|
|
|
board[c][x_col] = this.length; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
for (int c = this.start[X];c <= this.end[X];c++){ |
|
|
|
board[c][y_col] = this.lenth; |
|
|
|
for (c = this.start[X];c <= this.end[X];c++){ |
|
|
|
board[y_col][c] = this.length; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|