Android Open Source - septica-for-android Card Deck






From Project

Back to project page septica-for-android.

License

The source code is released under:

MIT License

If you think the Android project septica-for-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fera.costin.alexandru.logic;
// w  w w.j  ava 2  s  .c  o  m
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


/**
 * 
 * @author Alexandru Fera
 * 
 */
public final class CardDeck implements Serializable
{
  /**
   * 
   */
  
  private static final long serialVersionUID = -2722815733284738808L;
  private List<ICard> cardList;
  private char[] suits = { ICard.CLUBS, ICard.SPADES, ICard.HEARTS,
      ICard.DIAMONDS };
  private char[] values = { '7', '8', '9', ICard.TEN, ICard.JACK,
      ICard.QUEEN, ICard.KING, ICard.ACE };

  /**
   * Constructor. Create a deck of cards, for the game ?eptic?, which has 32
   * cards ranging from 7 to K.
   */
  public CardDeck()
  {
    cardList = new ArrayList<ICard>();

    for (char suit : suits)
    {
      for (char value : values)
      {
        cardList.add(new Card(suit, value));
      }
    }
  }
  

  /**
   * Shuffle the deck of cards into a random order.
   */
  public void shuffle()
  {
    Collections.shuffle(cardList);
  }

  /**
   * 
   * @return The number of cards that are still left in the deck.
   */
  public int cardsLeft()
  {
    return cardList.size();
  }

  /**
   * 
   * @return Whether the deck is empty or not.
   */
  public boolean isEmpty()
  {
    return cardList.size() == 0;
  }

  /**
   * Deals one card from the deck and removes it. If there is no card in the
   * deck it returns null.
   * 
   * @return An object of the type Card.
   */
  public ICard dealCard()
  {
    ICard card = null;

    try
    {
      card = cardList.remove(0);
    } catch (ArrayIndexOutOfBoundsException e)
    {
      System.out.println("Numai sunt c?r?i n pachet");
      e.printStackTrace();
    }

    return card;
  }
  
  public ICard peek(int i)
  {
    return cardList.get(i);
  }

}




Java Source Code List

fera.costin.alexandru.ai.AI.java
fera.costin.alexandru.ai.BaseAI.java
fera.costin.alexandru.ai.EasyAI.java
fera.costin.alexandru.ai.HardAI.java
fera.costin.alexandru.ai.MediumAI.java
fera.costin.alexandru.db.PersistenceAdapter.java
fera.costin.alexandru.logic.CardDeck.java
fera.costin.alexandru.logic.Card.java
fera.costin.alexandru.logic.Game.java
fera.costin.alexandru.logic.ICard.java
fera.costin.alexandru.ui.MainActivity.java
fera.costin.alexandru.ui.PreferencesActivity.java
fera.costin.alexandru.ui.SepticaActivity.java