Android Open Source - AndroSol Game State






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  ww  w. ja  va 2s .  c  o  m
import java.util.ArrayList;
import java.util.List;

public class GameState {
    // Rules
    private GameProperties gameProperties;

    // State
    private int gameNumber;
    private int oldScore;

    // Cards
    private List<CardState> stock;
    private List<CardState> waste;
    private List<List<CardState>> freeCells;
    private List<List<CardState>> tableaus;
    private List<List<CardState>> foundations;

    public GameState(Game game) {
        setGameProperties(game.getGameProperties());
        setGameNumber(game.getGameNumber());

        // Extract all the card IDs from the stacks in the game and save those.
        // Cards
        setStock(GameState.stackState(game.getStock()));
        setWaste(GameState.stackState(game.getWaste()));
        setFreeCells(GameState.stackCollectionState(game.getFreeCells()));
        setTableaus(GameState.stackCollectionState(game.getTableaus()));
        setFoundations(GameState.stackCollectionState(game.getFoundations()));

        // State
        setOldScore(game.getOldScore());
    }

    public GameProperties getGameProperties() {
        return gameProperties;
    }

    public void setGameProperties(GameProperties gameProperties) {
        this.gameProperties = gameProperties;
    }

    public int getGameNumber() {
        return gameNumber;
    }

    public void setGameNumber(int gameNumber) {
        this.gameNumber = gameNumber;
    }

    public int getOldScore() {
        return oldScore;
    }

    public void setOldScore(int oldScore) {
        this.oldScore = oldScore;
    }

    public List<CardState> getStock() {
        return stock;
    }

    public void setStock(List<CardState> stock) {
        this.stock = stock;
    }

    public List<CardState> getWaste() {
        return waste;
    }

    public void setWaste(List<CardState> waste) {
        this.waste = waste;
    }

    public List<List<CardState>> getFreeCells() {
        return freeCells;
    }

    public void setFreeCells(List<List<CardState>> freeCells) {
        this.freeCells = freeCells;
    }

    public List<List<CardState>> getTableaus() {
        return tableaus;
    }

    public void setTableaus(List<List<CardState>> tableaus) {
        this.tableaus = tableaus;
    }

    public List<List<CardState>> getFoundations() {
        return foundations;
    }

    public void setFoundations(List<List<CardState>> foundations) {
        this.foundations = foundations;
    }

    // Helpers
    public static List<CardState> stackState(Iterable<? extends Card> stack) {
        List<CardState> stackState = new ArrayList<CardState>();
        if (stack == null) {
            return stackState;
        }
        for (Card card : stack) {
            CardState cardState = new CardState();
            cardState.setId(card.getId());
            cardState.setFaceUp(card.isFaceUp());
            stackState.add(cardState);
        }

        return stackState;
    }

    public static List<List<CardState>> stackCollectionState(
            Iterable<? extends CardStack> collection) {
        List<List<CardState>> stacksState = new ArrayList<List<CardState>>();
        if (collection == null) {
            return stacksState;
        }

        for (Iterable<? extends Card> stack : collection) {
            stacksState.add(stackState(stack));
        }
        return stacksState;
    }
}




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