Beispiel #1
0
        /// <summary>
        ///     This is after the player has dropped 2 cards. To the Crib Do 2 things
        ///     1. Flip the cards to face down in the crib grid
        ///     2. flip the deck card to faceup
        /// </summary>
        /// <returns></returns>
        public async Task AnimateMoveToCribAndFlipDeckCard()
        {
            double beginTime = 0;
            var    taskList  = new List <Task>();

            var cards = _cgCrib.Cards;



            //
            //  when that is done flip the shared card
            beginTime = 0;
            taskList.AddRange(CardGrid.SetCardsToOrientationTask(_cgDeck.Cards, CardOrientation.FaceUp,
                                                                 FlipAnimationDuration, beginTime));

            //
            // run the animation
            await Task.WhenAll(taskList);
        }
Beispiel #2
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);
        }