コード例 #1
0
        //card methods

        //Given another DeckController, move all Cards to that controller
        //This is used to move Claims piles into a Deck
        public bool MoveCards(DeckController target)
        {
            try
            {
                //move cards over to new controller
                target.AddCards(Cards);

                //reinit cards in this deck
                Cards = new Queue <CardModel>();

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(false);
            }
        }
コード例 #2
0
        //A method to request a card from the deck
        //The method returns True if a card can be drawn, and outputs a CardModel of the drawn card
        //The method returns False if a card cannot be drawn (the deck and claims are empty), and outputs a null CardModel
        public bool TryDrawCard(out CardModel outCard, DeckController claims)
        {
            //Sense number of cards left in deck
            int numDeck = Cards.Count;

            if (numDeck < 1)
            {
                //no cards are left, so try to shuffle claims pile into the deck
                claims.MoveCards(this);
                //now check number of cards again
                numDeck = Cards.Count;
                if (numDeck < 1)
                {
                    //this actor has no more cards left
                    outCard = null;
                    return(false);
                }
            }
            outCard = Cards.Dequeue();
            return(true);
        }