From 6bca92419295fcbb2eb8b5a672d1405e9cd685f7 Mon Sep 17 00:00:00 2001 From: beppe Date: Sat, 11 Jan 2020 19:37:44 +0100 Subject: [PATCH] bord kan getoont worden, inlezen schepen werkt --- .../src/main/java/com/battleShipAi/Game.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/project/src/main/java/com/battleShipAi/Game.java b/project/src/main/java/com/battleShipAi/Game.java index fb5487f..340fad8 100644 --- a/project/src/main/java/com/battleShipAi/Game.java +++ b/project/src/main/java/com/battleShipAi/Game.java @@ -30,7 +30,7 @@ public class Game { while(true) { System.out.println("\nDo you want to set the ship vertical or horizontal? (v/h)"); String type = in.next(); - if (placeShip(in, ships[i], type.equals("v"))){ + if (placeShip(in, ships[i], type.equals("h"))){ break; } else { continue; @@ -48,20 +48,20 @@ public class Game { private static boolean placeShip(Scanner in, int ship, boolean vert) { - System.out.println("Enter the column position of the top of the ship"); - int col = in.nextInt(); - System.out.println("Enter the row position of the top of the ship"); - int row = in.nextInt(); - int turn = (vert) ? row : col; + System.out.println("Enter the column position of the top-left of the ship"); + int col = in.nextInt()-1; + System.out.println("Enter the row position of the top-left of the ship"); + int row = in.nextInt()-1; + int turn = (vert) ? col : row; boolean success = (vert && ship + row < height) || (!vert && ship + col < width); for (int ij = turn; ij < turn+ship; ij++) { if (!vert) { - success = !(field[ij][row].equals("S")); - field[ij][row] = "S"; + success = !(field[ij][col].equals("S")); + field[ij][col] = "S"; } else { - success = !(field[col][ij].equals("S")); - field[col][ij] = "S"; + success = !(field[row][ij].equals("S")); + field[row][ij] = "S"; } } if (success) {