/**
   * ******************************************** to undo this move we must put the cards back IN
   * THE ORDER they were extracted.
   */
  public boolean undo(Solitaire theGame) {
    // VALIDATE:
    if ((discardsCard == null) || (drawnCard == null)) return false;

    // EXECUTE:
    if (!wasDiscardsEmpty) {
      discards.add(justDrawn.get());
    }
    discards.add(discardsCard);
    justDrawn.add(drawnCard);

    theGame.updateScore(-2);
    return true;
  }
  /** Validate MatchDiscardsAndJustDrawnMove */
  public boolean valid(Solitaire theGame) {
    boolean validation = false;

    // VALIDATE:
    Card c1 = null, c2 = null;
    if (!discards.empty()) c1 = discards.peek();
    if (!justDrawn.empty()) c2 = justDrawn.peek();

    if ((c1 != null) && (c2 != null)) {
      if ((c1.getRank() + c2.getRank()) == 13) {
        validation = true;
      }
    }

    return validation;
  }
Example #3
0
  /**
   * Paints the screen on a graphics context
   *
   * @param g the graphics context to paint on
   */
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    // draw all piles and the remaining cards left in the deck
    for (int i = 0; i < mainPiles.length; i++) {
      mainPiles[i].draw(g);
    }
    for (int i = 0; i < suitPiles.length; i++) {
      suitPiles[i].draw(g);
    }
    deckPile.draw(g);
    deck.draw(g);

    if (selectedPile != null) {
      selectedPile.draw(g);
    }
  }
  /** Do the MatchDiscardsAndJustDrawnMove. */
  public boolean doMove(Solitaire theGame) {
    // VALIDATE:
    if (valid(theGame) == false) {
      return false;
    }

    // EXECUTE:
    discardsCard = discards.get();
    drawnCard = justDrawn.get();

    // these cards are no longer selected.
    discardsCard.setSelected(false);
    drawnCard.setSelected(false);

    wasDiscardsEmpty = discards.empty();
    if (!wasDiscardsEmpty) {
      justDrawn.add(discards.get());
    }

    theGame.updateScore(+2);
    return true;
  }