Android Open Source - AndroSol Game Properties






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;
//  w  w w .  ja  v a2  s.  com
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

public class GameProperties {
    private String mName;
    private String mTitle;

    // Decks

    private int mNumberOfDecks;

    public int getNumberOfCards() {
        return getNumberOfDecks() * Card.CARDS_PER_DECK;
    }

    // Tableau Rules

    private TableauType mTableauType;

    private int mNumberOfTableauPiles; // 4 to 35

    private int mNumberOfCardsPerTableau; // 1 to 13

    private int mNumberOfFaceDownCards; // 0 to (NumberOfCardsPerTableau-1)

    private int mNumberOfFreeCells;

    public int getNumberOfFoundations() {
        return getNumberOfDecks() * 4;
    }

    private TableauSequence mTableauBuildingMethod;

    private EmptyTableauPileFilledBy mEmptyTableauPileFilledBy;

    private TableauSequence mTableauGroupSequence;

    // Foundation Rules

    private FoundationBaseCard mFoundationBaseCard;
    // public bool FoundationBaseDealtAtStart;

    private FoundationSequence mFoundationBuildingMethod;

    private MoveGroupsOfCardsAsAUnit mMoveGroupsOfCardsAsAUnit;
    private NumberOfCardsDealtFromStock mNumberOfCardsDealtFromStock;

    // Redeals
    private RedealsAllowed mRedealsAllowed;

    // Spider only
    private boolean mMakeLastDealComeOutEven;

    private boolean mRemoveCompletedSequencesFromTableau;

    // Other
    private boolean mWasteVisible;

    public String getName() {
        return mName;
    }

    public void setName(String name) {
        this.mName = name;
    }

    public String getTitle() {
        return mTitle;
    }

    public void setTitle(String title) {
        this.mTitle = title;
    }

    public int getNumberOfDecks() {
        return mNumberOfDecks;
    }

    public void setNumberOfDecks(int numberOfDecks) {
        this.mNumberOfDecks = numberOfDecks;
    }

    public TableauType getTableauType() {
        return mTableauType;
    }

    public void setTableauType(TableauType tableauType) {
        this.mTableauType = tableauType;
    }

    public int getNumberOfTableauPiles() {
        return mNumberOfTableauPiles;
    }

    public void setNumberOfTableauPiles(int numberOfTableauPiles) {
        this.mNumberOfTableauPiles = numberOfTableauPiles;
    }

    public int getNumberOfCardsPerTableau() {
        return mNumberOfCardsPerTableau;
    }

    public void setNumberOfCardsPerTableau(int numberOfCardsPerTableau) {
        this.mNumberOfCardsPerTableau = numberOfCardsPerTableau;
    }

    public int getNumberOfFaceDownCards() {
        return mNumberOfFaceDownCards;
    }

    public void setNumberOfFaceDownCards(int numberOfFaceDownCards) {
        this.mNumberOfFaceDownCards = numberOfFaceDownCards;
    }

    public int getNumberOfFreeCells() {
        return mNumberOfFreeCells;
    }

    public void setNumberOfFreeCells(int numberOfFreeCells) {
        this.mNumberOfFreeCells = numberOfFreeCells;
    }

    public TableauSequence getTableauBuildingMethod() {
        return mTableauBuildingMethod;
    }

    public void setTableauBuildingMethod(TableauSequence tableauBuildingMethod) {
        this.mTableauBuildingMethod = tableauBuildingMethod;
    }

    public EmptyTableauPileFilledBy getEmptyTableauPileFilledBy() {
        return mEmptyTableauPileFilledBy;
    }

    public void setEmptyTableauPileFilledBy(
            EmptyTableauPileFilledBy emptyTableauPileFilledBy) {
        this.mEmptyTableauPileFilledBy = emptyTableauPileFilledBy;
    }

    public TableauSequence getTableauGroupSequence() {
        return mTableauGroupSequence;
    }

    public void setTableauGroupSequence(TableauSequence tableauGroupSequence) {
        this.mTableauGroupSequence = tableauGroupSequence;
    }

    public FoundationBaseCard getFoundationBaseCard() {
        return mFoundationBaseCard;
    }

    public void setFoundationBaseCard(FoundationBaseCard foundationBaseCard) {
        this.mFoundationBaseCard = foundationBaseCard;
    }

    public FoundationSequence getFoundationBuildingMethod() {
        return mFoundationBuildingMethod;
    }

    public void setFoundationBuildingMethod(
            FoundationSequence foundationBuildingMethod) {
        this.mFoundationBuildingMethod = foundationBuildingMethod;
    }

    public MoveGroupsOfCardsAsAUnit getMoveGroupsOfCardsAsAUnit() {
        return mMoveGroupsOfCardsAsAUnit;
    }

    public void setMoveGroupsOfCardsAsAUnit(
            MoveGroupsOfCardsAsAUnit moveGroupsOfCardsAsAUnit) {
        this.mMoveGroupsOfCardsAsAUnit = moveGroupsOfCardsAsAUnit;
    }

    public NumberOfCardsDealtFromStock getNumberOfCardsDealtFromStock() {
        return mNumberOfCardsDealtFromStock;
    }

    public void setNumberOfCardsDealtFromStock(
            NumberOfCardsDealtFromStock numberOfCardsDealtFromStock) {
        this.mNumberOfCardsDealtFromStock = numberOfCardsDealtFromStock;
    }

    public RedealsAllowed getRedealsAllowed() {
        return mRedealsAllowed;
    }

    public void setRedealsAllowed(RedealsAllowed redealsAllowed) {
        this.mRedealsAllowed = redealsAllowed;
    }

    public boolean getMakeLastDealComeOutEven() {
        return mMakeLastDealComeOutEven;
    }

    public void setMakeLastDealComeOutEven(boolean makeLastDealComeOutEven) {
        this.mMakeLastDealComeOutEven = makeLastDealComeOutEven;
    }

    public boolean getRemoveCompletedSequencesFromTableau() {
        return mRemoveCompletedSequencesFromTableau;
    }

    public void setRemoveCompletedSequencesFromTableau(
            boolean removeCompletedSequencesFromTableau) {
        this.mRemoveCompletedSequencesFromTableau = removeCompletedSequencesFromTableau;
    }

    public boolean getWasteVisible() {
        return mWasteVisible;
    }

    public void setWasteVisible(boolean wasteVisible) {
        this.mWasteVisible = wasteVisible;
    }

    public static GameProperties getGameFromName(String name) {
        Method[] methods = Method.class.getEnclosingMethod().getClass()
                .getDeclaredMethods();
        String methodName = "get" + name;
        for (Method m : methods) {
            if (m.getName().equals(methodName)) {
                try {
                    return (GameProperties) m.invoke(null);
                } catch (Exception e) {
                    // Will return NULL in failure case.
                }
            }
        }
        return null;
    }

    public static List<GameProperties> getGames() {
        List<GameProperties> games = new ArrayList<GameProperties>();
        Method[] methods = GameProperties.class.getDeclaredMethods();
        for (Method m : methods) {
            if (m.getReturnType() == GameProperties.class
                    && Modifier.isStatic(m.getModifiers())) {
                try {
                    games.add((GameProperties) m.invoke(null));
                } catch (Exception e) {
                    // OK to eat errors here.
                    System.out.println("Game property not invoked correctly.");
                }
            }
        }
        return games;
    }

    public static GameProperties getFreeCell() {
        GameProperties g = new GameProperties();
        g.setName("FreeCell");
        g.setTitle("Free Cell");
        g.setNumberOfDecks(1);
        g.setWasteVisible(false);
        g.setTableauType(TableauType.FORTY_THIEVES);
        g.setNumberOfTableauPiles(8);
        g.setNumberOfCardsPerTableau(7);
        g.setNumberOfFaceDownCards(0);
        g.setNumberOfFreeCells(4);
        g.setTableauBuildingMethod(TableauSequence.BUILD_DOWN_IN_ALTERNATE_COLORS);
        g.setEmptyTableauPileFilledBy(EmptyTableauPileFilledBy.ANY_CARD_IN_SEQUENCE);
        g.setMoveGroupsOfCardsAsAUnit(MoveGroupsOfCardsAsAUnit.NO);

        g.setFoundationBaseCard(FoundationBaseCard.ACE);
        g.setFoundationBuildingMethod(FoundationSequence.BUILD_UP_IN_SAME_SUIT);

        g.setNumberOfCardsDealtFromStock(NumberOfCardsDealtFromStock.ONE_TO_EACH_TABLEAU);
        g.setRedealsAllowed(RedealsAllowed.NONE);

        return g;
    }

    public static GameProperties getCanfield() {
        GameProperties g = new GameProperties();
        g.setName("CanField");
        g.setTitle("Canfield");
        g.setNumberOfDecks(1);
        g.setWasteVisible(false);
        g.setTableauType(TableauType.KLONDIKE);
        g.setNumberOfTableauPiles(7);
        g.setNumberOfCardsPerTableau(7);
        g.setNumberOfFaceDownCards(0);
        g.setNumberOfFreeCells(0);
        g.setTableauBuildingMethod(TableauSequence.BUILD_DOWN_IN_ALTERNATE_COLORS);
        g.setEmptyTableauPileFilledBy(EmptyTableauPileFilledBy.KING);
        g.setMoveGroupsOfCardsAsAUnit(MoveGroupsOfCardsAsAUnit.YES_IF_IN_SEQUENCE);

        g.setFoundationBaseCard(FoundationBaseCard.ACE);
        g.setFoundationBuildingMethod(FoundationSequence.BUILD_UP_IN_SAME_SUIT);

        g.setNumberOfCardsDealtFromStock(NumberOfCardsDealtFromStock.THREE_TO_WASTE);
        g.setRedealsAllowed(RedealsAllowed.UNLIMITED);

        return g;
    }

    public static GameProperties getFortyThieves() {
        GameProperties g = new GameProperties();
        g.setName("FourtyThieves");
        g.setTitle("Forty Thieves");
        g.setNumberOfDecks(2);
        g.setWasteVisible(false);
        g.setTableauType(TableauType.FORTY_THIEVES);
        g.setNumberOfTableauPiles(10);
        g.setNumberOfCardsPerTableau(4);
        g.setNumberOfFaceDownCards(0);
        g.setNumberOfFreeCells(0);
        g.setTableauBuildingMethod(TableauSequence.BUILD_DOWN_IN_SAME_SUIT);
        g.setEmptyTableauPileFilledBy(EmptyTableauPileFilledBy.ANY_CARD_IN_SEQUENCE);
        g.setMoveGroupsOfCardsAsAUnit(MoveGroupsOfCardsAsAUnit.NO);

        g.setFoundationBaseCard(FoundationBaseCard.ACE);
        g.setFoundationBuildingMethod(FoundationSequence.BUILD_UP_IN_SAME_SUIT);

        g.setNumberOfCardsDealtFromStock(NumberOfCardsDealtFromStock.ONE_TO_WASTE);
        g.setRedealsAllowed(RedealsAllowed.NONE);

        return g;
    }

    public static GameProperties getJosephine() {
        GameProperties g = GameProperties.getFortyThieves();
        g.setName("Josephine");
        g.setTitle("Josephine");
        g.setMoveGroupsOfCardsAsAUnit(MoveGroupsOfCardsAsAUnit.YES_IF_IN_SEQUENCE);
        return g;
    }

    public static GameProperties getCadran() {
        GameProperties g = GameProperties.getFortyThieves();
        g.setName("Cadran");
        g.setTitle("Cadran");
        g.setWasteVisible(true);
        return g;
    }

    public static GameProperties getMarieRose() {
        GameProperties g = GameProperties.getJosephine();
        g.setName("MarieRose");
        g.setTitle("Marie Rose");
        g.setNumberOfDecks(3);
        g.setNumberOfTableauPiles(12);
        return g;
    }

}




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