Exemplo n.º 1
0
  @Override
  public void mouseMoved(MouseEvent event) {
    assert event != null;
    assert GameView.hasInstance();
    assert !dragBoard;
    assert !leftButtonDown;

    final Point point = event.getPoint();
    if (GameView.getInstance().hasActiveTile()) {
      assert mouseLast != null;
      handleDragView(point);
    }
    mouseLast = point;
  }
Exemplo n.º 2
0
  private void leftButtonRelease(Point point) {
    assert point != null;
    assert GameView.hasInstance();
    assert mouseLast != null;

    final Game game = Game.getInstance();
    if (game != null) {
      if (game.isPaused()) {
        GameView.getInstance().startClock();
      } else {
        handleReleaseView(point);
      }
    }
    leftButtonDown = false;
    mouseLast = point;
  }
Exemplo n.º 3
0
  private void handleDragView(Point point) {
    assert point != null;
    assert Game.hasInstance();
    assert !Game.getInstance().isPaused();
    assert GameView.hasInstance();

    if (GameView.getInstance().hasActiveTile()) {
      assert !dragBoard;
      repaint();

    } else if (dragBoard) {
      final int dx = point.x - mouseLast.x;
      final int dy = point.y - mouseLast.y;
      GameView.getInstance().translate(dx, dy);
      dragBoardPixelCount += Math.abs(dx) + Math.abs(dy);
      repaint();
    }
  }
Exemplo n.º 4
0
  private void handleClickView(Point point) {
    assert point != null;
    assert Game.hasInstance();
    assert !Game.getInstance().isPaused();
    assert GameView.hasInstance();
    assert !dragBoard;

    final GameView view = GameView.getInstance();

    if (view.hasActiveTile()) {
      // Continue moving the active tile.
      assert mouseLast != null;
      assert deactivateOnRelease;
      repaint();
      return;
    }

    final Tile tile = view.findPlayableTile(point);
    if (tile != null) {
      /*
       * The local user clicked on a playable tile.
       * Activate the tile and start dragging it around.
       */
      view.activate(tile);
      deactivateOnRelease = false;
      repaint();

    } else if (!view.isInHandRect(point) && !view.isInSwapRect(point)) {
      // Start dragging the board around.
      dragBoard = true;
      view.deactivate();
      dragBoardPixelCount = 0;
      setCursor(DRAG_CURSOR);
      repaint();
    }
  }