コード例 #1
0
ファイル: ShopScreen.cs プロジェクト: AlanWills/SpaceCardGame
        private void PurchaseCard(BaseObject clickedObject)
        {
            // The clicked object has the card data stored (this is set up by the CardGridControl)
            Debug.Assert(clickedObject is Card);
            CardData cardData = (clickedObject as Card).CardData;

            Debug.Assert(PlayerMoney >= cardData.Price);
            PlayerMoney -= cardData.Price;

            PlayerDataRegistry.Instance.PlayerData.CardDataAssets.Add(CentralCardRegistry.FindCardDataAsset(cardData));
            Debug.Fail("Add UI for cards we already own/don't own");

            RefreshUI();
        }
コード例 #2
0
        /// <summary>
        /// A click callback when we click on a pack.
        /// Opens the pack and populates our screen with cards
        /// </summary>
        /// <param name="baseObject"></param>
        private void OnPackLeftClicked(BaseObject baseObject)
        {
            // Remove any previous cards from packs we have opened
            foreach (Card card in CardsFromPack)
            {
                card.Die();
            }

            // Clear our previous packs from the reference list
            CardsFromPack.Clear();

            // Remove the image in the grid control
            baseObject.Die();

            // Remove an available pack from our player
            PlayerDataRegistry.Instance.PlayerData.AvailablePacksToOpen--;

            // Pick random cards from the registry
            List <CardData> cardData = CentralCardRegistry.PickCardsForPackOpening();

            Debug.Assert(cardData.Count == CentralCardRegistry.PackSize);

            // Add cards to our screen to show these new cards
            for (int i = 0; i < cardData.Count; i++)
            {
                // Position the cards incrementally along the screen and halfway between the top of the grid control and the top of the screen
                // CreateCard calls LoadContent and Initialise
                Card card = AddScreenUIObject(cardData[i].CreateCard(null));
                card.LocalPosition = new Vector2(300 * (i + 1), (PacksGridControl.WorldPosition.Y - PacksGridControl.Size.Y * 0.5f) * 0.5f);
                card.ClickableModule.OnLeftClicked += OnCardLeftClicked;
                card.Flip(CardFlipState.kFaceDown);         // Make sure the card is face down initially, so we have the excitement of turning it over!
                card.StoredObject = PlayerDataRegistry.Instance.PlayerData.CardDataAssets.Contains(CentralCardRegistry.FindCardDataAsset(cardData[i]));
                card.HandAnimationModule.OffsetToHighlightedPosition = Vector2.Zero;

                CardsFromPack.Add(card);
            }

            // Add the newly unlocked cards to the Player's card registry
            PlayerDataRegistry.Instance.PlayerData.CardDataAssets.AddRange(CentralCardRegistry.ConvertToAssetList(cardData));

            // Stop our grid control from accepting input
            PacksGridControl.ShouldHandleInput = false;
        }
コード例 #3
0
        /// <summary>
        /// Save our player's configuration to XML.
        /// </summary>
        public void SaveAssets()
        {
            PlayerData.Decks.Clear();

            // Now add our decks to our data
            for (int i = 0; i < maxDeckNumber; i++)
            {
                if (Decks[i].IsCreated)
                {
                    // If we have created this deck then create deck data and add to our PlayerCardRegistryData
                    DeckData deckData = new DeckData();
                    deckData.Name           = Decks[i].Name;
                    deckData.CardDataAssets = CentralCardRegistry.ConvertToAssetList(Decks[i].Cards);

                    PlayerData.Decks.Add(deckData);
                }
            }

            // Save our player card registry data
            AssetManager.SaveData(PlayerData, playerDataRegistryDataAsset);
        }
コード例 #4
0
        /// <summary>
        /// Create our two controls for showing the cards in our deck and that are available to be added
        /// </summary>
        public override void Initialise()
        {
            base.Initialise();

            DeckCardListControl = new CardGridControl(Deck.Cards, deckColumns, new Vector2(Size.X * ratio, Size.Y), new Vector2(Size.X * (0.5f - 0.5f * ratio), 0));
            // Add all the cards in our deck that are of our type
            DeckCardListControl.IncludePredicate = new Predicate <CardData>(x => x.Type == CardType);
            DeckCardListControl.OnRightClicked  += RemoveFromDeck;

            // Do this here because we need to add the IncludePredicate before we initialise the control.
            AddChild(DeckCardListControl, true, true);

            List <CardData> availableCards = CentralCardRegistry.ConvertToDataList(PlayerDataRegistry.Instance.PlayerData.CardDataAssets);

            RegistryCardListControl = new CardGridControl(availableCards, registryColumns, new Vector2(Size.X * (1 - ratio), Size.Y), new Vector2(-ratio * 0.5f * Size.X, 0));
            // Find all cards of our type that are also not in our deck already
            RegistryCardListControl.IncludePredicate = new Predicate <CardData>(x => x.Type == CardType);
            RegistryCardListControl.OnLeftClicked   += AddToDeck;

            // Do this here because we need to add the IncludePredicate before we initialise the control.
            AddChild(RegistryCardListControl, true, true);
        }
コード例 #5
0
ファイル: Deck.cs プロジェクト: AlanWills/SpaceCardGame
        /// <summary>
        /// Creates a list and loads the card data assets we have inputted.
        /// </summary>
        /// <param name="cards">The initial card data assets to add to this deck</param>
        public void Create(List <string> cards)
        {
            Create();

            Cards.AddRange(CentralCardRegistry.ConvertToDataList(cards));
        }