private void DealHands() { for (int p = 0; p < players.Length; p++) { for (int c = 0; c < 6; c++) { players[p].PlayHand.Add(playDeck.GetCard(currentCard++)); } } }
/// <summary> /// 此程序演示了集合索引,运算符重载等内容 /// </summary> /// <param name="args"></param> static void Main(string[] args) { #region 向CardLib添加一个Cards集合 Deck myDeck = new Deck(); myDeck.Shuffle(); for (int i = 0; i < 52; i++) { Card tempCard = myDeck.GetCard(i); Console.Write(tempCard.ToString()); if (i != 51) Console.Write(", "); else Console.WriteLine(); } Console.ReadKey(); #endregion #region 向CardLib添加深复制集合 Deck deck1 = new Deck(); Deck deck2 = (Deck)deck1.Clone(); Console.WriteLine("The first card in the original deck is: {0}", deck1.GetCard(0)); Console.WriteLine("The first card in the clone deck is: {0}", deck2.GetCard(0)); deck1.Shuffle(); Console.WriteLine("Original deck shuffled."); Console.WriteLine("The first card in the original deck is: {0}", deck1.GetCard(0)); Console.WriteLine("The first card in the clone deck is: {0}", deck2.GetCard(0)); Console.ReadKey(); #endregion #region 向CardLib添加运算符重载 Card.isAceHigh = true; Console.WriteLine("Aces are high."); Card.useTrumps = true; Card.trump = Suit.Club; Console.WriteLine("Clubs are trumps."); Card card1, card2, card3, card4, card5; card1 = new Card(Suit.Club, Rank.Five); card2 = new Card(Suit.Club, Rank.Five); card3 = new Card(Suit.Club, Rank.Ace); card4 = new Card(Suit.Heart, Rank.Ten); card5 = new Card(Suit.Diamond, Rank.Ace); Console.WriteLine("{0} == {1} ? {2}", card1.ToString(), card2.ToString(), card1 == card2); Console.WriteLine("{0} != {1} ? {2}", card1.ToString(), card3.ToString(), card1 != card3); Console.WriteLine("{0}.Equals({1}) ? {2}", card1.ToString(), card4.ToString(), card1.Equals(card4)); Console.WriteLine("Card.Equals({0}, {1}) ? {2}", card3.ToString(), card4.ToString(), Card.Equals(card3, card4)); Console.WriteLine("{0} > {1} ? {2}", card1.ToString(), card2.ToString(), card1 > card2); Console.WriteLine("{0} <= {1} ? {2}", card1.ToString(), card3.ToString(), card1 <= card3); Console.WriteLine("{0} > {1} ? {2}", card1.ToString(), card4.ToString(), card1 > card4); Console.WriteLine("{0} < {1} ? {2}", card1.ToString(), card4.ToString(), card1 < card4); Console.WriteLine("{0} > {1} ? {2}", card5.ToString(), card4.ToString(), card1 > card4); Console.WriteLine("{0} > {1} ? {2}", card4.ToString(), card5.ToString(), card1 > card4); Console.ReadKey(); #endregion }
/// <summary> /// /// </summary> /// <param name="card"></param> /// <returns></returns> public bool DrawCard(ref Card card) { if (CardsRemaining > 0) { card = myDeck.GetCard(CurrentCardIndex); CurrentCardIndex++; CardsRemaining--; return(true); } else { return(false); } }
/// <summary> /// Looks for a sequence that makes a flush in a random deck, user for testing /// </summary> static void TryFlush() { Deck myDeck = new Deck(); myDeck.Shuffle(); int numberOfDraws = (int)Math.Round((double)(Deck.SIZE_OF_DECK / 5), 0); // Can draw 5 cards 10 times in a deck of 52 bool isFlush = false; for (int i = 0; i < numberOfDraws; i++) { try { int sameSuitCount = 0; PlayingCard tempCard = myDeck.GetCard(i * 5); CardSuit tempSuit = tempCard.Suit; for (int j = 1; j <= 4; j++) { if (myDeck.GetCard(i * 5 + j).Suit == tempSuit) // same suit as temp card { sameSuitCount++; } if (sameSuitCount == 4) // the other 4 cards are the same suit as the first of the 5 draws { isFlush = true; Console.WriteLine("*******************\n"); Console.WriteLine("Flush!!!"); for (int z = 0; z < 5; z++) // printing out the last 5 cards { Console.WriteLine(myDeck.GetCard(i * 5 + j - z).ToString()); } return; // exit out of the method } } } catch (IndexOutOfRangeException ioe) { Console.WriteLine(ioe.Message); } } if (isFlush == false) // if no flush in this shuffle, show this msg { Console.WriteLine("No Flush"); } }
public void dispatchCards() { Deck deck = new Deck(); deck.Shuffle(); for (int i = 0; i < 3; i++) { for (int j = 0; j < players.Count; j++) { int index = i * players.Count + j; players[j].RoundInfo.addCard(deck.GetCard(index)); } } }
static void Main(string[] args) { Deck myDeck = new Deck(); myDeck.Shuffle(); for(int i = 0; i < 52; i++) { Card tempCard = myDeck.GetCard(i); Console.Write(tempCard.ToString()); if (i != 51) Console.Write(", "); else Console.WriteLine(); } Console.ReadKey(); }