コード例 #1
0
        public async Task AnimateMoveComputerCardstoCrib(List <CardCtrl> computerCribCards, bool moveCards = true)
        {
            double beginTime         = 0;
            var    taskList          = new List <Task>();
            var    animationDuration = FlipAnimationDuration;

            if (_firstDeal)
            {
                animationDuration *= 4;
                _firstDeal         = false;
            }

            var tList = CardGrid.MoveListOfCards(_cgComputer, _cgCrib, computerCribCards, animationDuration,
                                                 beginTime);

            if (tList != null)
            {
                taskList.AddRange(tList);
            }

            await Task.WhenAll(taskList);

            if (moveCards)
            {
                CardGrid.TransferCards(_cgComputer, _cgCrib, computerCribCards);
            }
        }
コード例 #2
0
        private async Task OnDeal()
        {
            ResetCards();

            var(computerCards, playerCards, sharedCard) = Game.GetHands();

            var orig = _cgDeck.GetNextCardPosition(sharedCard[0]);

            await Deal(playerCards, computerCards, sharedCard, new List <CardCtrl> {
                computerCards[0], computerCards[2]
            },
                       PlayerType.Computer);

            var playerCribCards = new List <CardCtrl> {
                _cgPlayer.Cards[0], _cgPlayer.Cards[1]
            };
            var index = 2;

            foreach (var card in playerCribCards)
            {
                await CardGrid.AnimateMoveOneCard(_cgPlayer, _cgDiscarded, card, index ++, false,
                                                  MOVE_CARDS_ANIMATION_DURATION, 0);
            }

            CardGrid.TransferCards(_cgPlayer, _cgDiscarded, playerCribCards);
        }
コード例 #3
0
        private async Task AnimateSendCardsBackToOwner()
        {
            var tList = new List <Task>();
            var targetIndexForComputer = 0;
            var targetIndexForPlayer   = 0;
            var playerCards            = new List <CardCtrl>();
            var computerCards          = new List <CardCtrl>();

            foreach (var card in _cgDiscarded.Cards)
            {
                card.Opacity = 1.0;
                Task task;
                if (card.Owner == Owner.Computer)
                {
                    task = CardGrid.AnimateMoveOneCard(_cgDiscarded, _cgComputer, card, targetIndexForComputer, false,
                                                       MOVE_CARDS_ANIMATION_DURATION, targetIndexForComputer * MOVE_CARDS_ANIMATION_DURATION);
                    computerCards.Add(card);
                    targetIndexForComputer++;
                }
                else
                {
                    task = CardGrid.AnimateMoveOneCard(_cgDiscarded, _cgPlayer, card, targetIndexForPlayer, false,
                                                       MOVE_CARDS_ANIMATION_DURATION, MOVE_CARDS_ANIMATION_DURATION * targetIndexForPlayer);
                    targetIndexForPlayer++;
                    playerCards.Add(card);
                }

                tList.Add(task);
            }

            playerCards.Sort(CardCtrl.CompareCardsByRank); // sort from lowest to highest, ignoring suit

            await Task.WhenAll(tList);

            CardGrid.TransferCards(_cgDiscarded, _cgPlayer, playerCards);
            CardGrid.TransferCards(_cgDiscarded, _cgComputer, computerCards);
        }
コード例 #4
0
        //
        //  if this is the computer, do the animation to move it to the shared grid and then flip the card.
        //
        //  if this is the player, update which cards can be played.
        //
        public async Task CountCard(PlayerType playerTurn, CardCtrl card, int newCount)
        {
            if (playerTurn == PlayerType.Computer)
            {
                var tList = new List <Task>();
                var task  = CardGrid.AnimateMoveOneCard(_cgComputer, _cgDiscarded, card, _cgDiscarded.Cards.Count, false,
                                                        MOVE_CARDS_ANIMATION_DURATION, 0);
                tList.Add(task);
                task = card.SetOrientationTask(CardOrientation.FaceUp, FlipAnimationDuration, 0);
                if (task != null)
                {
                    tList.Add(task);
                }

                CardGrid.TransferCards(_cgComputer, _cgDiscarded, new List <CardCtrl> {
                    card
                });

                await Task.WhenAll(tList);
            }


            _game.SetPlayableCards(); // both enables playable cards and disables non-playable ones
        }
コード例 #5
0
        /// <summary>
        ///     Deal does the following
        ///     1. moves cards from the deck to the computer and player
        ///     2. flips the players cards faceup
        ///     3. moves 2 cards from the computer to the discard grid
        ///     Assume we start with the cards in the deck
        ///     One problem we have is that we can't animate (X,Y) in one TimeLine -- so we have to compose them.
        /// </summary>
        public async Task AnimateDeal(List <CardCtrl> playerCards, List <CardCtrl> computerCards,
                                      List <CardCtrl> discardedComputerCards, PlayerType dealer)
        {
            playerCards.Sort(CardCtrl.CompareCardsByRank); // sort from lowest to highest, ignoring suit

            var taskList = new List <Task>();

            //
            //  assume dealer is player and then set it if it is not
            var dealersCards   = playerCards;
            var nonDealerCards = computerCards;


            if (dealer == PlayerType.Computer)
            {
                dealersCards   = computerCards;
                nonDealerCards = playerCards;
            }


            Task   t         = null;
            double beginTime = 0;

            var zIndex = 53; // this number is important -- the layout engine for cards sets Zindex too...

            for (var z = 0; z < nonDealerCards.Count; z++)
            {
                nonDealerCards[z].ZIndex = zIndex;
                dealersCards[z].ZIndex   = zIndex - 1;
                zIndex -= 2;
            }


            _cgDeck.Cards.Sort((c1, c2) => Canvas.GetZIndex(c2) - Canvas.GetZIndex(c1));

            double targetIndex = 0; // just being a bit silly here -- by incrementing by 0.5 and casting to an int, we can increate the target index by 1 after 2 iterations through the loop

            foreach (var card in _cgDeck.Cards)
            {
                switch (card.Owner)
                {
                case Owner.Player:
                    t = CardGrid.AnimateMoveOneCard(_cgDeck, _cgPlayer, card, (int)targetIndex, true,
                                                    MOVE_CARDS_ANIMATION_DURATION, beginTime);
                    targetIndex  += 0.5;
                    card.Location = CardView.Location.Player;
                    break;

                case Owner.Computer:
                    t = CardGrid.AnimateMoveOneCard(_cgDeck, _cgComputer, card, (int)targetIndex, true,
                                                    MOVE_CARDS_ANIMATION_DURATION, beginTime);
                    targetIndex  += 0.5;
                    card.Location = CardView.Location.Computer;
                    break;

                case Owner.Shared:
                    continue;

                default:
                    throw new InvalidOperationException("Card owner not set");
                }

                taskList.Add(t);
                beginTime += MOVE_CARDS_ANIMATION_DURATION;
            }


            //
            //  Now flip the players cards
            taskList.AddRange(CardGrid.SetCardsToOrientationTask(playerCards, CardOrientation.FaceUp,
                                                                 FlipAnimationDuration, beginTime));
            await Task.WhenAll(taskList);

            taskList.Clear();
            //
            //  move computer cards to the crib.  do it slow the first time so that the user can learn where to place the cards
            //
            // don't Transfer the cards because they all still belong to the deck -- we'll transfer below
            await AnimateMoveComputerCardstoCrib(discardedComputerCards, false);

            //
            //  Now put the cards where they belong - they are all currently owned by the deck...
            CardGrid.TransferCards(_cgDeck, _cgComputer, computerCards);
            CardGrid.TransferCards(_cgDeck, _cgPlayer, playerCards);
            CardGrid.TransferCards(_cgComputer, _cgCrib, discardedComputerCards);
        }