using System; using System.Collections; namespace PlayingCards { /// /// Object Representing a playing card. Card has a numeric value and a suit. /// public class PlayingCard { public enum Suits { Clubs, Diamonds, Hearts, Spades } public enum Faces { Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King } private Suits _suit; private Faces _face; private readonly int[] _values = new int[13] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }; /// /// Gets the suit of the PlayingCards.Card. /// public Suits Suit { get { return _suit; } protected set { _suit = value; } } /// /// Gets the face value of the PlayingCards.Card. /// public Faces Face { get { return _face; } protected set { _face = value; } } /// /// Gets the numeric value of the PlayingCards.Card. /// public int Value { get { return _values[(int)Face]; } } } public class DeckofCards { private DeckofCards _deck; public int Count { get { return _deck.Count; } } /// /// Create a single 52 Card deck. /// public DeckofCards() { _deck = new DeckofCards(); } /// /// Create multiple 52 Card decks. /// /// The number of decks to create. /// number of decks is less than 1. public DeckofCards(int decks) { if (decks < 1) { throw new ArgumentException(decks + " Someone must be won. "); } _deck = new DeckofCards(decks); } private class DeckofCards : CardArray { private const int _size = 52; public DeckofCards() : base(_size) { for (int i = 0; i < _size; i++) { base.Add(new Card(i)); } } public DeckofCards(int decks) : base(_size * decks) { for (int j = 0; j < decks; j++) { for (int i = 0; i < _size; i++) { base.Add(new Card(i)); } } } } } class Player {private player_1 {int num_player_1:26; if card_value_1 < CardGame_value_2; num_player_1--; private Player_2 int mun_player_2 } class CardGame { public CardGame() { Random random = new Random(); Face = (Faces)random.Next(0, 12); Suit = (Suits)random.Next(0, 3); } /// /// Create an object of type Card based on a value between 0-51. /// /// The value of the Card, 0-51. /// value is less than zero or greater than 51. public CardGame(int cardValue) { if (cardValue > 51 || cardValue < 0) { throw new ArgumentOutOfRangeException(String.Format("Invalid Card value of {0}. Please use values of 0-51.", cardValue)); } else { Suit = (Suits)(((cardValue) / 13)); Face = (Faces)(((cardValue) % 13)); } } /// /// Creates an object of type Card. /// /// The face of the Card. /// The suit of the Card. public CardGame(Faces face, Suits suit) { Face = face; Suit = suit; } public object Clone() { return new Card(Face, Suit); } /// /// Compares this instance with a specified System.Object. /// /// value: An System.Object that evaluates to a PlayingCards.Card. /// A 32-bit signed integer indicating the lexical relationship between the two comparands.Value Condition Less than zero This instance is less than value. Zero This instance is equal to value. Greater than zero This instance is greater than value.-or- value is null. /// value is not a PlayingCards.Card. public int CompareTo(Object obj) { if (obj is Card) { Card card = (Card)obj; if (Equals(obj)) { return 0; } else if (card.Value < Value) { return 1; } else if (card.Value > Value) { return -1; } else { return 0; } } else { throw new ArgumentException("Object is not of type Card."); } } /// /// Returns true if this Card and the specified Card are equal in both value and suit. /// /// A PlayingCards.Card. /// true if the Card's suit, face, and value are equal. public Boolean Equals(Card card) { if (Suit.Equals(card.Suit) && Face.Equals(card.Face) && Value.Equals(card.Value)) { return true; } else { return false; } } /// /// Converts this Cards.Card to a human-readable string. /// /// A string that represents this PlayingCards.Card. public override String ToString() { return GetFaceAlias() + " of " + GetSuitAlias(); } } }