//----------------------------------------------------------------------------- // TraditionalCard.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; namespace CardsFramework { /// /// Enum defining the various types of cards for a traditional-western card-set /// [Flags] public enum CardSuit { Heart = 0x01, Diamond = 0x02, Club = 0x04, Spade = 0x08, // Sets: AllSuits = Heart | Diamond | Club | Spade } /// /// Enum defining the various types of card values for a traditional-western card-set /// [Flags] public enum CardValue { Ace = 0x01, Two = 0x02, Three = 0x04, Four = 0x08, Five = 0x10, Six = 0x20, Seven = 0x40, Eight = 0x80, Nine = 0x100, Ten = 0x200, Jack = 0x400, Queen = 0x800, King = 0x1000, FirstJoker = 0x2000, SecondJoker = 0x4000, // Sets: AllNumbers = 0x3FF, NonJokers = 0x1FFF, Jokers = FirstJoker | SecondJoker, AllFigures = Jack | Queen | King, } /// /// Traditional-western card /// /// /// Each card has a defined Type and Value /// as well as the in which it is being held. /// A card may not be held in more than one . This is achived by enforcing any card transfer /// operation between s and s to be performed only from within the card's /// method only. This method accesses internal method and /// method accordingly to complete the card transfer operation. /// public class TraditionalCard { /// /// Factory method for deserialization, creates a card with no holding collection. /// public static TraditionalCard Create(CardSuit type, CardValue value) { return new TraditionalCard(type, value, null); } public CardSuit Type { get; set; } public CardValue Value { get; set; } public CardPacket HoldingCardCollection; /// /// Initializes a new instance of the class. /// /// The card suit. Supports only a single value. /// The card's value. Only single values are /// supported. /// The holding card collection. internal TraditionalCard(CardSuit type, CardValue value, CardPacket holdingCardCollection) { // Check for single type switch (type) { case CardSuit.Club: case CardSuit.Diamond: case CardSuit.Heart: case CardSuit.Spade: break; default: { throw new ArgumentException( "type must be single value", "type"); } } // Check for single value switch (value) { case CardValue.Ace: case CardValue.Two: case CardValue.Three: case CardValue.Four: case CardValue.Five: case CardValue.Six: case CardValue.Seven: case CardValue.Eight: case CardValue.Nine: case CardValue.Ten: case CardValue.Jack: case CardValue.Queen: case CardValue.King: case CardValue.FirstJoker: case CardValue.SecondJoker: break; default: { throw new ArgumentException( "value must be single value", "value"); } } Type = type; Value = value; HoldingCardCollection = holdingCardCollection; } /// /// Moves the card from its current to the specified . /// This method of operation prevents any one card instance from being held by more than one /// at the same time. /// /// The receiving hand. public void MoveToHand(Hand hand) { HoldingCardCollection.Remove(this); HoldingCardCollection = hand; hand.Add(this); } } }