C # - simulated poker dealer
1. User class: Players
public class User { private List<PaperCard> listCard = new List<PaperCard>(); public string Name { get; set; } public User(string strName) { this.Name = strName; } public void Add(PaperCard p) { listCard.Add(p); } public void Reset() { listCard.Clear(); } public void Introduce() { string strCards = ""; for (int i = 0; i < listCard.Count; i++) { if (i == 0) { strCards += listCard[i].Name; } else { strCards += ", " + listCard[i].Name; } } Console.WriteLine("\r\n--------------------------------------------"); Console.Write(" I {0}, " , the Name); Console.Write ( " I have a poker hand sheets {0}: \ R & lt \ {n-}. 1 \ R & lt \ n- ' , listCard.Count, strCards); } }
2. PaperCard categories: Solitaire
public class PaperCard { public string Type { get; set; } public string Number { get; set; } public PaperCard(string strType, string strNumber) { this.Type = strType; this.Number = strNumber; } public string Name { get { return string.Format("{0}{1}", this.Type, this.Number); } private set { } } }
3. Analog licensing process
public void TestPlay () { // generate the playing card Console.WriteLine ( " Generating cards ... " ); List <PaperCard> = myCards new new List <PaperCard> (); String [] = {strType " hearts " , " spades " , " plum " , " block " }; String [] strNumber = { " A " , " 2 " , " . 3 ", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" }; PaperCard[] OtherCard = { new PaperCard("大王", ""), new PaperCard("" ","Wang) }; for (int i = 0; i < strNumber.Length; i++) { for (int j = 0; j < strType.Length; j++) { PaperCard p = new PaperCard(strType[j], strNumber[i]); myCards.Add(p); } } for (int j = 0; j < OtherCard.Length; j++) { myCards.Add(OtherCard[j]); } //洗牌 Console.WriteLine("正在洗牌..."); Stack<PaperCard> stackCard = new Stack<PaperCard>(); Random r = new Random(); while (myCards.Count>0) { int iIndex = r.Next(0, myCards.Count); stackCard.Push(myCards[iIndex]); myCards.RemoveAt(iIndex); } //发牌 Console.WriteLine("开始发牌..."); List<User> listUser = new List<User>() { new User("大师兄"), New new the User ( " two brothers " ), new new the User ( " three Young " ) }; the while (stackCard.Count> 0 ) { for ( int S = 0 ; S <listUser.Count; S ++ ) { LISTUSER [S] .add (stackCard.Pop ()); } } Console.WriteLine ( " licensing is completed! " ); // read the cards foreach ( var Item in LISTUSER) { item.Introduce(); } }
test: