コード例 #1
0
        /// <summary>
        /// Turns cards from the stock into the waste.
        /// </summary>
        private void DoTurnStock()
        {
            //  If the stock is empty, put every card from the waste back into the stock.
            if (Stock.Count == 0)
            {
                foreach (var card in Waste)
                {
                    card.IsFaceDown = true;
                    card.IsPlayable = false;

                    Stock.Insert(0, card);
                }

                Waste.Clear();
            }
            else
            {
                //  Everything in the waste so far must now have no offset.
                foreach (var wasteCard in Waste)
                {
                    wasteCard.FaceUpOffset = 0;
                }

                if (Stock.Count > 0)
                {
                    var card = Stock.Last();

                    Stock.Remove(card);

                    card.IsFaceDown   = false;
                    card.IsPlayable   = false;
                    card.FaceUpOffset = 30;

                    Waste.Add(card);
                }
            }

            //  Everything in the waste must be not playable,
            //  apart from the top card.
            foreach (var wasteCard in Waste)
            {
                wasteCard.IsPlayable = wasteCard == Waste.Last();
            }
        }
コード例 #2
0
        /// <summary>
        /// Deals a new game.
        /// </summary>
        /// <param name="parameter">The parameter.</param>
        protected override void NewGameCommandExecute(object parameter)
        {
            //  Call the base, which stops the timer, clears
            //  the score etc.
            base.NewGameCommandExecute(parameter);

            //  Clear everything.
            Stock.Clear();
            Waste.Clear();

            foreach (var tableau in _tableaus)
            {
                tableau.Clear();
            }

            foreach (var foundation in _foundations)
            {
                foundation.Clear();
            }

            //  Create a list of card types.
            var eachCardType = Enum.GetValues(typeof(CardType)).Cast <CardType>().ToList();

            //  Create a playing card from each card type.
            var playingCards = eachCardType.Select(cardType => new PlayingCardViewModel
            {
                CardType   = cardType,
                IsFaceDown = true
            }).ToList();

            //  Shuffle the playing cards.
            playingCards.Shuffle();

            //  Now distribute them - do the tableaus first.
            for (var i = 0; i < 7; i++)
            {
                //  We have i face down cards and 1 face up card.
                for (var j = 0; j < i; j++)
                {
                    var faceDownCard = playingCards.First();

                    playingCards.Remove(faceDownCard);

                    faceDownCard.IsFaceDown = true;

                    _tableaus[i].Add(faceDownCard);
                }

                //  Add the face up card.
                var faceUpCard = playingCards.First();

                playingCards.Remove(faceUpCard);

                faceUpCard.IsFaceDown = false;
                faceUpCard.IsPlayable = true;

                _tableaus[i].Add(faceUpCard);
            }

            //  Finally we add every card that's left over to the stock.
            foreach (var playingCard in playingCards)
            {
                playingCard.IsFaceDown = true;
                playingCard.IsPlayable = false;

                Stock.Add(playingCard);
            }

            playingCards.Clear();
        }