Пример #1
0
 public object Clone()
 {
     Cards cloneTarget = new Cards();
     foreach (Card cloneCard in this)
     {
         cloneTarget.Add((Card)cloneCard.Clone());
     }
     return cloneTarget;
 }
Пример #2
0
 public object Clone()
 {
     Cards newCards = new Cards();
     foreach (Card sourceCard in List)
     {
         newCards.Add(sourceCard.Clone() as Card);
     }
     return newCards;
 }
Пример #3
0
 private void InsertAllCards()
 {
     for (int suitVal = 0; suitVal < 4; suitVal++)
     {
         for (int rankVal = 3; rankVal < 16; rankVal++)
         {
             cards.Add(new Card((Suit)suitVal, (Rank)rankVal));
         }
     }
     cards.Add(new Card((Suit)3, (Rank)16));
     cards.Add(new Card((Suit)1, (Rank)17));
 }
Пример #4
0
        /// <summary>
        /// to shuffled the deck cards
        /// </summary>
        public void Shuffle()
        {
            Cards newDeck = new Cards();

            bool[] assigned  = new bool[cards.Count];
            Random sourceGen = new Random();

            for (int i = 0; i < cards.Count; i++)
            {
                int  sourceCard = 0;
                bool foundCard  = false;
                while (foundCard == false)
                {
                    sourceCard = sourceGen.Next(cards.Count);
                    if (assigned[sourceCard] == false)
                    {
                        foundCard = true;
                    }
                }
                assigned[sourceCard] = true;
                newDeck.Add(cards[sourceCard]);
            }
            newDeck.CopyTo(cards);
        }
Пример #5
0
        //shuffle method, randomizes the order of the cards,
        //then uses the copy to method in cardlist to copy over the cards to a new deck.
        public void Shuffle(int deckSize)
        {
            Cards newDeck = new Cards();

            bool[] assigned  = new bool[deckSize];
            Random sourceGen = new Random();

            for (int i = 0; i < deckSize; i++)
            {
                int  sourceCard = 0;
                bool foundCard  = false;
                while (foundCard == false)
                {
                    sourceCard = sourceGen.Next(deckSize);
                    if (assigned[sourceCard] == false)
                    {
                        foundCard = true;
                    }
                }
                assigned[sourceCard] = true;
                newDeck.Add(theBoard[sourceCard]);
            }
            newDeck.CopyTo(theBoard);
        }
Пример #6
0
 public virtual void AddCard(PlayingCard card)
 {
     card.FaceUp = true;
     Cards.Add(card);
 }
Пример #7
0
 public void DrawNewHand(Deck deck)
 {
     Hand = new Cards();
       for (int i = 0; i < 7; i++)
     Hand.Add(deck.Draw());
 }
Пример #8
0
 public void DrawNewHand(Deck deck)
 {
     Hand = new Cards();
       Chosen = new Cards();
       for (int i = 0; i < 17; i++)
     Hand.Add(deck.Draw());
       if (Landlord)
       {
       for (int i = 0; i < 3; i++)
       Hand.Add(deck.Draw());
       }
       Hand.Sort();
 }
Пример #9
0
 //addcardtoriver method, will add a card to Board
 public void AddCard(Card card)
 {
     theBoard.Add(card);
     riverCardsRemaning = theBoard.Count();
 }
Пример #10
0
 public void Shuffle()
 {
     Cards newDeck = new Cards();
       bool[] assigned = new bool[cards.Count ];
       Random sourceGen = new Random();
       for (int i = 0; i < cards.Count ; i++)
       {
     int sourceCard = 0;
     bool foundCard = false;
     while (foundCard == false)
     {
       sourceCard = sourceGen.Next(cards.Count );
       if (assigned[sourceCard] == false)
     foundCard = true;
     }
     assigned[sourceCard] = true;
     newDeck.Add(cards[sourceCard]);
       }
       newDeck.CopyTo(cards);
 }
Пример #11
0
 //addcardtohand method, add a card to the players hand
 public void AddCard(Card card)
 {
     hand.Add(card);
     cardCount = hand.Count();
 }
Пример #12
0
 //Shuffle cards in deck
 public void Shuffle()
 {
     Cards tempDeck = new Cards();
     Random position = new Random();
     bool[] isSelect = new bool[52];
     for (int countPos = 0; countPos <= 51; countPos++)
     {
         bool isAssigned = false;
         do
         {
             int posCard = position.Next(52);
             if (isSelect[posCard])
                 continue;
             else
             {
                 isSelect[posCard] = true;
                 isAssigned = true;
                 tempDeck.Add(this.deck[posCard]);
             }
             tempDeck.CopyTo(this.deck);
         } while (!isAssigned);
     }
 }
Пример #13
0
 private void player_OnCardPlayed(object sender, CardEventArgs e)
 {
     var nextIndex = CurrentPlayer.Index + 1 >= 3 ? 0 : CurrentPlayer.Index + 1;
     CurrentAvailableCard = new Cards();
     var cardsInPlay = new List<Card>();
     for (int i = 0; i < e.Cards.Count; i++)
         CurrentAvailableCard.Add(e.Cards[i]);
     if (e.Cards.Count > 0)
     {
         CurrentAvailableCardPlayer = e.index;
         Combination = e.CurrentCombination;
     }
     AssignCurrentPlayer(nextIndex);
 }
Пример #14
0
 public void Shuffle()
 {
     Random rnd = new Random();
     Cards newDeck = new Cards();
     bool[] assigned = new bool[52];
     for (int i = 0; i < 52; i++)
     {
         int sourceCard = 0;
         bool foundCard = false;
         while (foundCard == false)
         {
             sourceCard = rnd.Next(52);
             if (assigned[sourceCard] == false)
                 foundCard = true;
         }
         assigned[sourceCard] = true;
         newDeck.Add(cards[sourceCard]);
     }
     newDeck.CopyTo(cards);
 }
Пример #15
0
        /// <summary>
        /// PlayGame - The flow of the game, which cycles through each player, shows them a list of their current cards, and then prompts them to make their move
        /// </summary>
        /// <returns></returns>
        public int PlayGame()
        {
            // Only play if players exist.
            if (players == null)
            {
                return(-1);
            }
            // Deal initial hands.
            DealHands();

            // Initialize game vars, including an initial card to place on the
            // table: playCard.
            bool        GameWon = false;
            int         currentPlayer;
            PlayingCard playCard = playDeck.GetCard(currentCard++);

            discardedCards.Add(playCard);

            // Main game loop, continues until GameWon == true.
            do
            {
                // Loop through players in each game round.
                for (currentPlayer = 0; currentPlayer < players.Length;
                     currentPlayer++)
                {
                    // Draw starting trump card
                    PlayingCard initialCardDrawn = playDeck.GetCard(currentCard++);
                    CardSuit    trumpSuit        = initialCardDrawn.Suit;

                    Console.WriteLine("\nThe starting trump suit is {0}.\n", trumpSuit);

                    // Write out current player, player hand, and the card on the
                    // table.
                    Console.WriteLine("\n{0}'s turn.", players[currentPlayer].Name);
                    Console.WriteLine("********************");
                    Console.WriteLine("Current hand:");
                    foreach (PlayingCard card in players[currentPlayer].PlayHand)
                    {
                        Console.WriteLine(card);
                    }
                    Console.WriteLine("Initial card drawn from top of the deck: {0}", initialCardDrawn);
                    // Prompt player to pick up card on table or draw a new one.
                    bool inputOK = false;
                    do
                    {
                        Console.WriteLine("Press T to throw card or S to skip");
                        string input = Console.ReadLine();
                        if (input.ToLower() == "t")
                        {
                            // Add card from table to player hand.
                            Console.WriteLine("Thrown: {0}", playCard);

                            //// Remove from discarded cards if possible (if deck
                            //// is reshuffled it won't be there any more)
                            //if (discardedCards.Contains(playCard))
                            //{
                            //    discardedCards.Remove(playCard);
                            //}

                            players[currentPlayer].PlayHand.Remove(playCard);
                            inputOK = true;
                        }
                        if (input.ToLower() == "s")
                        {
                            // Add new card from deck to player hand.
                            PlayingCard newCard;
                            // Only add card if it isn't already in a player hand
                            // or in the discard pile
                            bool cardIsAvailable;
                            do
                            {
                                newCard = playDeck.GetCard(currentCard++);
                                // Check if card is in discard pile
                                cardIsAvailable = !discardedCards.Contains(newCard);
                                if (cardIsAvailable)
                                {
                                    // Loop through all player hands to see if newCard
                                    // is already in a hand.
                                    foreach (Player testPlayer in players)
                                    {
                                        if (testPlayer.PlayHand.Contains(newCard))
                                        {
                                            cardIsAvailable = false;
                                            break;
                                        }
                                    }
                                }
                            } while (!cardIsAvailable);
                            // Add the card found to player hand.
                            Console.WriteLine("Drawn: {0}", newCard);
                            players[currentPlayer].PlayHand.Add(newCard);
                            inputOK = true;
                        }
                    } while (inputOK == false);

                    // Display new hand with cards numbered.
                    Console.WriteLine("New hand:");
                    for (int i = 0; i < players[currentPlayer].PlayHand.Count; i++)
                    {
                        Console.WriteLine("{0}: {1}", i + 1,
                                          players[currentPlayer].PlayHand[i]);
                    }
                    // Prompt player for a card to discard.
                    inputOK = false;
                    int choice = -1;
                    do
                    {
                        Console.WriteLine("Choose card to discard:");
                        string input = Console.ReadLine();
                        try
                        {
                            // Attempt to convert input into a valid card number.
                            choice = Convert.ToInt32(input);
                            if ((choice > 0) && (choice <= 8))
                            {
                                inputOK = true;
                            }
                        }
                        catch
                        {
                            // Ignore failed conversions, just continue prompting.
                        }
                    } while (inputOK == false);

                    // Place reference to removed card in playCard (place the card
                    // on the table), then remove card from player hand and add
                    // to discarded card pile.
                    playCard = players[currentPlayer].PlayHand[choice - 1];
                    players[currentPlayer].PlayHand.RemoveAt(choice - 1);
                    discardedCards.Add(playCard);
                    Console.WriteLine("Discarding: {0}", playCard);

                    // Space out text for players
                    Console.WriteLine();

                    // Check to see if player has won the game, and exit the player
                    // loop if so.
                    GameWon = players[currentPlayer].HasWon();
                    if (GameWon == true)
                    {
                        break;
                    }
                }
            } while (GameWon == false);

            // End game, noting the winning player.
            return(currentPlayer);
        }