Example #1
0
  public void offerNewGame() {
    GameOpt gameOpt;
    if (Game.hasInstance()) {
      // Copy the game options of the active instance.
      gameOpt = new GameOpt(Game.getInstance().getOpt());
      gameOpt.setRules(Rules.REPLAY);
    } else {
      // Start with the default game options.
      gameOpt = new GameOpt();
    }

    final int maxHands = ParmBox3.HANDS_DEALT_MAX;
    final HandOpt handOpts[] = new HandOpt[maxHands];
    for (int iHand = 0; iHand < maxHands; iHand++) {
      HandOpt handOpt;
      if (Game.hasInstance() && iHand < gameOpt.getHandsDealt()) {
        final ReadHand hand = Game.getInstance().getHand(iHand);
        handOpt = new HandOpt(hand.getOpt());
      } else {
        handOpt = new HandOpt("User");
      }
      handOpts[iHand] = handOpt;
    }

    final Wizard wizard = new Wizard(frame);

    final ParmBox1 parmBox1 = new ParmBox1(wizard);
    wizard.addCard(parmBox1);

    final WizardCard parmBox2 = new ParmBox2(wizard);
    wizard.addCard(parmBox2);

    final WizardCard parmBox3 = new ParmBox3(wizard);
    wizard.addCard(parmBox3);

    final WizardCard handBox = new HandBox(wizard);
    wizard.addCard(handBox);

    // pack and go
    final boolean completed = wizard.run(parmBox1, gameOpt, handOpts);

    if (!completed) {
      Console.print("New game aborted.\n");
      return;
    }

    final GameView view = GameView.getInstance();
    view.saveHand();
    final GameStyle oldStyle = Game.getStyle();
    new Game(gameOpt, handOpts);
    view.newGame(oldStyle);
  }
Example #2
0
  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();
    }
  }
Example #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();
    }
  }
Example #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();
    }
  }