mirror of
https://github.com/bvanroll/battleShipAi.git
synced 2025-08-28 19:42:46 +00:00
bord kan getoont worden, inlezen schepen werkt
This commit is contained in:
@@ -30,7 +30,7 @@ public class Game {
|
|||||||
while(true) {
|
while(true) {
|
||||||
System.out.println("\nDo you want to set the ship vertical or horizontal? (v/h)");
|
System.out.println("\nDo you want to set the ship vertical or horizontal? (v/h)");
|
||||||
String type = in.next();
|
String type = in.next();
|
||||||
if (placeShip(in, ships[i], type.equals("v"))){
|
if (placeShip(in, ships[i], type.equals("h"))){
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
@@ -48,20 +48,20 @@ public class Game {
|
|||||||
|
|
||||||
|
|
||||||
private static boolean placeShip(Scanner in, int ship, boolean vert) {
|
private static boolean placeShip(Scanner in, int ship, boolean vert) {
|
||||||
System.out.println("Enter the column position of the top of the ship");
|
System.out.println("Enter the column position of the top-left of the ship");
|
||||||
int col = in.nextInt();
|
int col = in.nextInt()-1;
|
||||||
System.out.println("Enter the row position of the top of the ship");
|
System.out.println("Enter the row position of the top-left of the ship");
|
||||||
int row = in.nextInt();
|
int row = in.nextInt()-1;
|
||||||
int turn = (vert) ? row : col;
|
int turn = (vert) ? col : row;
|
||||||
|
|
||||||
boolean success = (vert && ship + row < height) || (!vert && ship + col < width);
|
boolean success = (vert && ship + row < height) || (!vert && ship + col < width);
|
||||||
for (int ij = turn; ij < turn+ship; ij++) {
|
for (int ij = turn; ij < turn+ship; ij++) {
|
||||||
if (!vert) {
|
if (!vert) {
|
||||||
success = !(field[ij][row].equals("S"));
|
success = !(field[ij][col].equals("S"));
|
||||||
field[ij][row] = "S";
|
field[ij][col] = "S";
|
||||||
} else {
|
} else {
|
||||||
success = !(field[col][ij].equals("S"));
|
success = !(field[row][ij].equals("S"));
|
||||||
field[col][ij] = "S";
|
field[row][ij] = "S";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (success) {
|
if (success) {
|
||||||
|
Reference in New Issue
Block a user