コード例 #1
0
  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;
  }
コード例 #2
0
  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;
  }
コード例 #3
0
  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;
  }
コード例 #4
0
 private boolean isYIncreasing() {
   if (lastHit.getY() > origHit.getY()) return true;
   else return false;
 }