Beispiel #1
0
        public void RenewWindowPackage(GamePackage package)
        {
            _cardUIList = ConvertPackageToUI(package);

            if (_cardSpriteList.Count == 0) return;

            _cardSpriteList.ForEach((sprite) => sprite.OnClick -= CardClickHandler);

            for (var i = 0; i < _cardSpriteList.Count; i++)
            {
                for (var j = 0; j < _cardUIList.Count; j++)
                {
                    if (_cardSpriteList[i].Card.CardSuit == _cardUIList[j].CardSuit &&
                        _cardSpriteList[i].Card.CardType == _cardUIList[j].CardType)
                    {
                        Vector2 position; Texture2D texture; float rotation; float zIndex;

                        // Renew sprite state
                        CalculateNewSpriteState(_cardUIList[j], out position, out texture, out rotation, out zIndex);
                        var texturePosition = (texture == _backSprite) ? Point.Zero : new Point((int)_cardUIList[j].CardSuit, (int)_cardUIList[j].CardType);
                        _cardSpriteList[i].Reset(texture, texturePosition, rotation, zIndex, CardResizeIndex);
                        if (position != _cardSpriteList[i].Position) _cardSpriteList[i].Animate(position, AnimationTime);

                        // Set event handlers
                        if (_cardUIList[j].CardPosition == CardPosition.Player)
                        {
                            _cardSpriteList[i].OnClick += CardClickHandler;
                        }

                    }
                }
            }

            // Renew button state
            if (package.WhoseParty == PlayerType.Enemy)
                ResetButtons(ButtonType.GetAll);
            if (package.WhoseParty == PlayerType.Player)
                ResetButtons(ButtonType.Pass);

            ShowCards = true;
        }
Beispiel #2
0
        public void SetGameData(GamePackage gamePackage)
        {
            if (Trump != gamePackage.Trump ||
                PlayerCards != gamePackage.PlayerCards)
            {
                if (OnGameError != null) OnGameError(GameError.Error, "Trump suit and player's card list do not match");
                return;
            }

            Deck = gamePackage.Deck;
            EnemyCards = gamePackage.EnemyCards;
            DescPairs = gamePackage.DescPairs;
            WhoseParty = gamePackage.WhoseParty;
        }
Beispiel #3
0
        public List<CardUI> ConvertPackageToUI(GamePackage package)
        {
            _countPlayerCards = package.PlayerCards.Count;
            _countEnemyCards = package.EnemyCards.Count;

            List<CardUI> cardUIList = new List<CardUI> { };
            int index = 0;
            package.Deck.ForEach((card) =>
            {
                cardUIList.Add(new CardUI
                {
                    CardPosition = CardPosition.Deck,
                    CardSuit = card.CardSuit,
                    CardType = card.CardType,
                    Index = index++
                });
            });

            index = 0;
            package.DescPairs.ForEach((pair) =>
            {
                cardUIList.Add(new CardUI
                {
                    CardPosition = CardPosition.Desc,
                    CardSuit = pair.LowerCard.CardSuit,
                    CardType = pair.LowerCard.CardType,
                    Index = index++
                });

                if (pair.UpperCard != null)
                    cardUIList.Add(new CardUI
                    {
                        CardPosition = CardPosition.Desc,
                        CardSuit = pair.UpperCard.Value.CardSuit,
                        CardType = pair.UpperCard.Value.CardType,
                        Index = index++
                    });
            });

            index = 0;
            package.PlayerCards.ForEach((card) =>
            {
                cardUIList.Add(new CardUI
                {
                    CardPosition = CardPosition.Player,
                    CardSuit = card.CardSuit,
                    CardType = card.CardType,
                    Index = index++
                });
            });

            index = 0;
            package.EnemyCards.ForEach((card) =>
            {
                cardUIList.Add(new CardUI
                {
                    CardPosition = CardPosition.Enemy,
                    CardSuit = card.CardSuit,
                    CardType = card.CardType,
                    Index = index++
                });
            });

            // Get list of cards out of desc
            foreach (var sprite in _cardSpriteList)
            {
                var contains = false;
                foreach (var fui in cardUIList)
                {
                    if (fui.CardType == sprite.Card.CardType &&
                        fui.CardSuit == sprite.Card.CardSuit)
                    {
                        contains = true; break;
                    }
                }

                if (!contains)
                {
                    cardUIList.Add(new CardUI
                    {
                        CardPosition = CardPosition.OutOfDesc,
                        CardSuit = sprite.Card.CardSuit,
                        CardType = sprite.Card.CardType,
                        Index = 0
                    });
                }
            }

            return cardUIList;
        }