Solution directory:
Suit.cs four kinds of suits
Namespace cards{ enum Suit {Clubs, Diamonds, Hearts, Spades}}
Value.cs 13 par value of poker
Namespace cards{ enum Value {A, three, four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace}}
Pack.cs Licensing Program Core class
namespace cards{using system;using system.collections;class pack{Public const int numsuits = 4;//color Public const int cardspersuit = 13;//points Private Hashtable cardpack;//stores an array of poker objects//private playingcard[,] cardpack; Private random randomcardselector = new Random ();//used to generate random numbers for random licensing///<summary>///construction Method Initialize Poker Array///</summary>public Pack () {cardpack = new Hashtable (); Generate an instance of a poker array//this.cardpack = new playingcard[numsuits, cardspersuit]; Instantiates each element in the poker array, pointing to a Poker object for (Suit Suit = suit.clubs; Suit <= suit.spades; suit++) { SortedList cardsinsuit = new SortedList (); SortedList () What is the role of this class? for (value value = value.two; value <= value.ace; value++) {Cardsinsuit.add (value, n EW Playingcard (suit, value)); this.cardpack[(int) suit, (int) value] = new PlAyingcard (suit, value); } this.cardPack.Add (Suit, cardsinsuit); }//The dual for loop assigns each element a value. }///<summary>/////</summary>///<returns></returns> Public Playingcard Dealcardfrompack () {Suit Suit = (Suit) randomcardselector.next (numsuits); Returns a non-negative random number that is less than numsuits. Because Numsuits is 4, it is less than 4. Randomly produces a suit//cycle in four suits determines whether the suit is empty while (this. Issuitempty (SUIT)) {//randomly produce one of the four suits suit = (suit) randomcardselector.next (Numsui TS); }//randomly generates a card value value = (value) randomcardselector.next (cardspersuit); Randomly generates a poker card, the value of which is not empty in the array. while (this. Iscardalreadydealt (suit, value)) {value = (value) randomcardselector.next (cardspersuit); } SortedList cardsinsuit = (SortedList) cardpack[Suit]; Playingcard card = (playingcard) cardsinsuit[value]; Cardsinsuit.remove (value); return card; }///<summary>//Determine if a randomly generated card already exists///</summary>//<param name= "Suit" >< ;/param>//<returns></returns> private bool Issuitempty (Suit Suit) {bool result = true; Judging each card with suit suit (2-a), if there is a chapter card is not NULL The result value is false, otherwise true; for (value value = value.two; value <= value.ace; value++) {if (! Iscardalreadydealt (suit, value)) {result = false; Break }} return result; }///<summary>///determine if the element with suit in the array of cards is null///</summary>//< ;p Aram Name= "Suit" ></param>//<param name= "value" ></param>//<returns></re Turns&gT private bool Iscardalreadydealt (Suit Suit, value value) {SortedList Cardsinsuit = (SortedList) this.card Pack[suit]; Return (!cardsinsuit.containskey (value)); }}}
PalyCard.cs
1 namespaceCards2 {3 classPlayingcard4 {5 Private ReadOnlySuit Suit;6 Private ReadOnlyvalue value;7 8 PublicPlayingcard (Suit s, Value v)9 {Ten This. Suit =s; One This. Value =v; A } - - Public Override stringToString () the { - stringresult =string. Format ("{0} of {1}", This. Value, This. Suit); - returnresult; - } + - PublicSuit cardsuit () + { A return This. Suit; at } - - PublicValue cardvalue () - { - return This. Value; - } in } -}View Code
The tenth chapter of the array and the collection of the program instance code