Android Open Source - AndroSol Card






From Project

Back to project page AndroSol.

License

The source code is released under:

MIT License

If you think the Android project AndroSol 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 lib.cards.models;
//from w  w w.j ava  2  s  .com
public class Card {
    public static final int CARDS_PER_DECK = 52;

    /*
     * ' Card id values: Ace| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10
     * |Jack|Queen|King ' CLUBS: 0 4 8 12 16 20 24 28 32 36 40 44 48 ' DIAMONDS:
     * 1 5 9 13 17 21 25 29 33 37 41 45 49 ' HEARTS: 2 6 10 14 18 22 26 30 34 38
     * 42 46 50 ' SPADES: 3 7 11 15 19 23 27 31 35 39 43 47 51
     */

    private int id;

    public int getId() {
        return id;
    }

    // Index value from table above

    public int getIndex() {
        return getId() % CARDS_PER_DECK;
    }

    public int getPack() {
        return getId() / CARDS_PER_DECK;
    }

    public Card(int id) {
        this.id = id;
        this.faceUp = false;
    }

    protected Card(int id, boolean faceUp) {
        this.id = id;
        this.faceUp = faceUp;
    }

    private boolean faceUp;

    public boolean isFaceUp() {
        return faceUp;
    }

    public void setFaceUp(boolean faceUp) {
        this.faceUp = faceUp;
    }

    public CardSuit getSuit() {
        return CardSuit.getAt(getIndex() % 4);
    }

    public CardValue getValue() {
        return CardValue.getAt((getIndex() / 4) + 1);
    }

    public CardColor getColor() {
        return (getSuit().equals(CardSuit.DIAMONDS) || getSuit().equals(
                CardSuit.HEARTS)) ? CardColor.RED : CardColor.BLACK;
    }

    public String getName() {
        return getValue().toString() + "Of" + getSuit().toString();
    }

    public String getShortName() {
        String[] valueShortNames = { "", "A", "2", "3", "4", "5", "6", "7",
                "8", "9", "X", "J", "Q", "K" };
        String value = valueShortNames[getValue().toInt()];
        return value + getSuit().toString().substring(0, 1);
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + id;
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        Card other = (Card) obj;
        if (id != other.id) {
            return false;
        }
        return true;
    }
}




Java Source Code List

com.example.androsol.AndroidDeck.java
com.example.androsol.AndroidGameBoard.java
com.example.androsol.CardSpriteImpl.java
com.example.androsol.DeckTheme.java
com.example.androsol.DisplayMessageActivity.java
com.example.androsol.GameSurface.java
com.example.androsol.MainActivity.java
com.example.androsol.SpriteImpl.java
com.example.androsol.StackSpriteImpl.java
com.example.androsol.StandardDeck.java
lib.cards.controllers.Actions.java
lib.cards.controllers.DealAction.java
lib.cards.controllers.GameActionState.java
lib.cards.controllers.GameAction.java
lib.cards.controllers.GameController.java
lib.cards.controllers.NewGameActionState.java
lib.cards.controllers.NewGameAction.java
lib.cards.controllers.StackMoveAction.java
lib.cards.controllers.StackMoveState.java
lib.cards.models.CardColor.java
lib.cards.models.CardStackId.java
lib.cards.models.CardStack.java
lib.cards.models.CardState.java
lib.cards.models.CardSuit.java
lib.cards.models.CardValue.java
lib.cards.models.Card.java
lib.cards.models.CardsMovedEventHandler.java
lib.cards.models.CardsMovedEventObject.java
lib.cards.models.EmptyTableauPileFilledBy.java
lib.cards.models.EventHandler.java
lib.cards.models.FoundationBaseCard.java
lib.cards.models.FoundationSequence.java
lib.cards.models.Foundation.java
lib.cards.models.FreeCell.java
lib.cards.models.GameEventObject.java
lib.cards.models.GameOverEventHandler.java
lib.cards.models.GameOverEventObject.java
lib.cards.models.GameProperties.java
lib.cards.models.GameState.java
lib.cards.models.Game.java
lib.cards.models.MoveGroupsOfCardsAsAUnit.java
lib.cards.models.NewGameEventHandler.java
lib.cards.models.NumberOfCardsDealtFromStock.java
lib.cards.models.RedealsAllowed.java
lib.cards.models.RestoreGameEventHandler.java
lib.cards.models.ScoreChangedEventHandler.java
lib.cards.models.ScoreChangedEventObject.java
lib.cards.models.StackType.java
lib.cards.models.Stock.java
lib.cards.models.SubStackMovedEventHandler.java
lib.cards.models.SubStackMovedEventObject.java
lib.cards.models.SubStack.java
lib.cards.models.TableauSequence.java
lib.cards.models.TableauType.java
lib.cards.models.Tableau.java
lib.cards.models.Waste.java
lib.cards.utilities.CollectionUtils.java
lib.cards.utilities.CommandImpl.java
lib.cards.utilities.Command.java
lib.cards.utilities.Point.java
lib.cards.utilities.Rect.java
lib.cards.utilities.Size.java
lib.cards.utilities.UndoStack.java
lib.cards.views.CardSprite.java
lib.cards.views.DeckMetrics.java
lib.cards.views.Deck.java
lib.cards.views.GameBoardImpl.java
lib.cards.views.GameBoardMetrics.java
lib.cards.views.GameBoard.java
lib.cards.views.SpriteAddedEventHandler.java
lib.cards.views.SpriteDefaultActionEventHandler.java
lib.cards.views.SpriteEventObject.java
lib.cards.views.SpriteRemovedEventHandler.java
lib.cards.views.SpriteSelectedEventHandler.java
lib.cards.views.Sprite.java
lib.cards.views.StackSprite.java