private Point getShotReverseSequence() { Point nextShot = null; if (isXIncreasing()) nextShot = new Point(origHit.getX() - 1, origHit.getY()); else if (isXDecreasing()) nextShot = new Point(origHit.getX() + 1, origHit.getY()); else if (isYIncreasing()) nextShot = new Point(origHit.getX(), origHit.getY() - 1); else if (isYDecreasing()) nextShot = new Point(origHit.getX(), origHit.getY() + 1); return nextShot; }
private Point getShotInSequence() { Point nextShot = null; if (isXIncreasing()) nextShot = new Point(lastHit.getX() + 1, lastHit.getY()); else if (isXDecreasing()) nextShot = new Point(lastHit.getX() - 1, lastHit.getY()); else if (isYIncreasing()) nextShot = new Point(lastHit.getX(), lastHit.getY() + 1); else if (isYDecreasing()) nextShot = new Point(lastHit.getX(), lastHit.getY() - 1); return nextShot; }
private Point getRandomShot() { Random random = new Random(); Point nextShot = null; boolean validShot = false; int nextX; int nextY; int origX = origHit.getX(); int origY = origHit.getY(); while (!validShot) { if (random.nextInt() % 2 == 0) { if (random.nextInt() % 2 == 0) nextX = origX - 1; else nextX = origX + 1; nextY = origY; } else { nextX = origX; if (random.nextInt() % 2 == 0) nextY = origY - 1; else nextY = origY + 1; } nextShot = new Point(nextX, nextY); if (!board.isValidShot(nextShot) || alreadyTriedShot(nextShot)) validShot = false; else validShot = true; } return nextShot; }
private boolean isYIncreasing() { if (lastHit.getY() > origHit.getY()) return true; else return false; }