コード例 #1
0
ファイル: GamePanel.java プロジェクト: stephengold/gold-tiles
  private void handleReleaseView(Point point) {
    assert point != null;
    assert mouseLast != null;
    assert Game.hasInstance();
    assert !Game.getInstance().isPaused();

    final int dx = point.x - mouseLast.x;
    final int dy = point.y - mouseLast.y;
    final GameView view = GameView.getInstance();
    if (view.hasActiveTile()) {
      assert !dragBoard;
      deactivateOnRelease = view.dropActiveTile(point, deactivateOnRelease);
      repaint();

    } else if (dragBoard) {
      view.translate(dx, dy);
      dragBoardPixelCount += Math.abs(dx) + Math.abs(dy);

      if (dragBoardPixelCount < DRAG_THRESHOLD) {
        /*
         * Board drags shorter than six pixels (clicks, basically)
         * also serve to alter or un-target the target cell.
         */
        view.toggleTargetCell(point);
      }

      // done dragging the board
      dragBoard = false;
      setCursor(Cursor.getDefaultCursor());
      repaint();
    }
  }
コード例 #2
0
ファイル: GamePanel.java プロジェクト: stephengold/gold-tiles
  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();
    }
  }