Package net.sf.nebulacards.main

Examples of net.sf.nebulacards.main.PlayingCard


   * value that may not occur as a suit).
     * @return The table position of the winning card.
     */
    public static int whoWinsTrick( Tableau tableau, int trump )
    {
        PlayingCard high;
    try { high = tableau.get( tableau.getLead() ); }
    catch (ArrayIndexOutOfBoundsException e) { return tableau.getLead(); }
        int winner = tableau.getLead();

    if (high == null)
      return winner;

      for (int i = 0; i < 4; i++)
    {
      if (i == tableau.getLead())
        continue;
           PlayingCard c = tableau.get( i );
      if (c.isNull())
      {
        continue;
      }
          else if (c.getSuit() == trump && high.getSuit() != trump)
      {
           high = c;
                 winner = i;
             }
             else if (c.getSuit() == high.getSuit())
      {
        if (c.getValue() == 1
          || (high.getValue() != 1 && c.getValue() > high.getValue())
          )
        {
                   high = c;
                   winner = i;
        }
View Full Code Here


    {
        int tally = 0;
    Enumeration cards = hand.elements();
    while (cards.hasMoreElements())
    {
      PlayingCard c = (PlayingCard)cards.nextElement();
            if (c.getValue() > 11 || c.getValue() == 1)
                tally++;
    }

        if (tally > 0)
            return tally;
View Full Code Here

    }

    protected PlayingCard thinkPlay()
    {
        boolean pWinning, pNil, meNil, pSafe;
    PlayingCard myPlay = null;

        pNil = (bids[partner] == 0); meNil = (bids[whereAmI] == 0);
        pWinning = ( tableau.howManyCardsNotNull() > 1
                     && rules.whoWinsTrick(tableau) == partner );
        pSafe = (tableau.hasPlayed(partner) && !pWinning) || !pNil;
View Full Code Here

   * Call the thinkPlay() method and send its result to the server.
   * It removes the chosen card from the hand.
   */
    public void yourTurn()
  {
    PlayingCard c = thinkPlay();
    hand.remove(c);
    callbacks.submitPlay(c);
  }
View Full Code Here

   */
  private synchronized void setLabels(PileOfCards h) {
    Enumeration e = h.elements();
    for (int i = 0; i < numButtons; i++) {
      if (e.hasMoreElements()) {
        PlayingCard n = (PlayingCard) (e.nextElement());
        buttons[i].setCard(n.toString());
        hand[i] = n;
      } else {
        buttons[i].setCard(null);
        hand[i] = NullPlayingCard.getInstance();
      }
View Full Code Here

  /*
   * (non-Javadoc)
   * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
   */
  public void mouseClicked(MouseEvent e) {
    PlayingCard c = null;
    Object src = e.getSource();
    if (src instanceof Card) {
      Card card = (Card) src;
      for (int i = 0; i < numButtons; i++) {
        if (card == buttons[i]) {
View Full Code Here

  public PlayingCardTest(String s) { super(s); }

  protected void setUp()
  {
    aceSpades = new PlayingCard( 1, PlayingCard.SPADES );
    twoClubs = new PlayingCard( 2, PlayingCard.CLUBS );
    jackDiamonds = new PlayingCard( 11, PlayingCard.DIAMONDS );
    tenHearts = new PlayingCard( 10, PlayingCard.HEARTS );
    PlayingCard[] _cards =
    {
      aceSpades, twoClubs, jackDiamonds, tenHearts,
      new PlayingCard(12,PlayingCard.HEARTS),
      new PlayingCard(13,PlayingCard.HEARTS)
    };
    cards = _cards;
    String[] _stringReps = { "As", "2c", "Jd", "10h", "Qh", "Kh" };
    stringReps = _stringReps;
  }
View Full Code Here

  public void testEquals()
  {
    assertTrue( !aceSpades.equals(twoClubs) );
    assertTrue( !twoClubs.equals(aceSpades) );
    assertTrue( !twoClubs.equals(new PlayingCard(2,PlayingCard.HEARTS)) );
    assertTrue( !twoClubs.equals(new PlayingCard(5,PlayingCard.CLUBS)) );
    assertEquals( twoClubs, (new PlayingCard(2,PlayingCard.CLUBS)) );
    assertTrue( !twoClubs.equals(NullPlayingCard.getInstance()) );
  }
View Full Code Here

  }

  public void testStringConstructor()
  {
    for (int i = 0; i < cards.length; i++)
      assertEquals( cards[i], new PlayingCard(stringReps[i]) );
  }
View Full Code Here

  }

  public void testComparison()
  {
    // try to trick the equals function
    PlayingCard c = new PlayingCard(npc.getVal(), npc.getSuit());
    assertFalse(npc.equals(c));
    assertFalse(c.equals(npc));
  }
View Full Code Here

TOP

Related Classes of net.sf.nebulacards.main.PlayingCard

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.