Example #1
0
  /**
   * Moving the frog to the new position
   *
   * @param x x-coordinate position of the new position
   * @param y y-coordinate position of the new position
   * @return {@code true} if the movement succeeded, otherwise {@code false}
   */
  private boolean jumpFrog(int x, int y) {
    if (y < 0 || y >= boardHeight) return true;

    if (x < 0 || x >= boardWidth) return false;

    Board board = getBoard();

    // Erase the frog to not interfere with the checks
    board = drawShape(board, curX, curY, frog, Cell.Empty);

    // check for collisions
    if (checkCollision(board, frog, x, y)) return false;

    // draw the frog on the new place
    if (y == boardHeight - 1) {
      frogs[x] = Cell.Full;
      board.setRow(frogs, y);

      setBoard(board);
      GameSound.playEffect(Effects.add_cell);

      checkForWin();
    } else {
      setBoard(drawShape(board, x, y, frog, frog.getFill()));
      curX = x;
      curY = y;
    }

    return true;
  }
Example #2
0
  /** Processing of key presses */
  @Override
  protected void processKeys() {
    if (keys.isEmpty() || getStatus() == Status.None) return;

    super.processKeys();

    if (getStatus() == Status.Running) {
      int newX = curX, newY = curY;
      boolean move = false;

      if (containsKey(KeyPressed.KeyLeft)) {
        newX = newX - 1;
        move = true;
        keys.remove(KeyPressed.KeyLeft);
      }
      if (containsKey(KeyPressed.KeyRight)) {
        newX = newX + 1;
        move = true;
        keys.remove(KeyPressed.KeyRight);
      }

      if (isStarted) {
        if (containsKey(KeyPressed.KeyDown)) {
          newY = newY - 2;
          move = true;
          keys.remove(KeyPressed.KeyDown);
        }
        if (containsKey(KeyPressed.KeyUp)) {
          newY = newY + (curY < boardHeight - 2 ? 2 : 1);
          move = true;
          keys.remove(KeyPressed.KeyUp);
        }
        if (containsKey(KeyPressed.KeyRotate)) {
          newY = newY + (curY < boardHeight - 2 ? 2 : 1);
          move = true;
          keys.remove(KeyPressed.KeyRotate);
        }
      }

      if (move) {
        if (jumpFrog(newX, newY)) {
          GameSound.playEffect(Effects.move);
        } else {
          loss(curX, curY);
        }
      }
    }
  }
 protected Collection<GameSound> getSoundResources() {
   return GameSound.values();
 }