public boolean aroundView(int x, int y) { x = x - 1; y = y - 1; int n = shipValue; ArrayList<MyClass> list = new ArrayList<>(); // try { while (n > 0) { if (enemyField[x][y] == 0) { MyClass myClass = new MyClass(x, y); // list.add(myClass); if (directionVertical) { x++; } else { y++; } n--; } else { viewPossibility(false); return false; } if ((x == 10 || y > 10) & n != 0) { viewPossibility(false); return true; } } } catch (ArrayIndexOutOfBoundsException e) { viewPossibility(true); return false; } for (MyClass mC : list) { int xx = mC.getX(); int yy = mC.getY(); for (int i = -1; i < 2; i++) { if (xx + i > -1 && xx + i < 10) { for (int j = -1; j < 2; j++) { if (yy + j > -1 && yy + j < 10) { if (!(i == 0 && j == 0)) { int q = xx + i; int w = yy + j; if (!list.contains(new MyClass(q, w)) && enemyField[q][w] != 0) { viewPossibility(false); return false; } } } } } } } for (MyClass mC : list) { int i = mC.getX(); int j = mC.getY(); enemyField[i][j] = shipValue; BattleShipeSourses.changeJButtonStyle(field[i][j], "X", Color.DARK_GRAY); } if (shipValue == 1) { n1--; } if (shipValue == 2) { n2--; } if (shipValue == 3) { n3--; } if (shipValue == 4) { n4--; } shipValue = 0; viewPossibility(false); return true; // true if empty }