예제 #1
0
        /// <summary>
        /// Merges 1 or more Card Set(s) into this temporary Game Set.
        /// </summary>
        /// <param name="cardSetGuids">GUIDs for all the Card Sets to be added.</param>
        /// <exception cref="ArgumentNullException">Thrown if no Guid is provided.</exception>
        /// <exception cref="FileNotFoundException">Thrown if the card set cannot be found.</exception>
        /// <exception cref="XmlException">Thrown if the card set XML is corrupted.</exception>
        /// <exception cref="ApplicationException">Thrown if the card set is corrupted.</exception>
        public void Merge(List <string> cardSetGuids)
        {
            if (cardSetGuids == null)
            {
                throw new ArgumentNullException("cardSetGuids");
            }
            CardSetGuid = new Guid().ToString();
            Name        = "GameSet";
            Version     = "0.0";
            foreach (string guid in cardSetGuids)
            {
                string[] files = Directory.GetFiles(Program.CardSetPath, "*" + guid + ".cardset");
                if (files == null)
                {
                    throw new FileNotFoundException("Cannot find card set", Program.CardSetPath + guid + ".cardset");
                }
                XmlDocument cardSetDoc = new XmlDocument();
                cardSetDoc.Load(files[0]);
                XmlElement cardSetInfo             = (XmlElement)cardSetDoc.GetElementsByTagName("CardSet")[0];
                XmlElement xmlBlackCards           = (XmlElement)cardSetDoc.GetElementsByTagName("BlackCards")[0];
                XmlElement xmlWhiteCards           = (XmlElement)cardSetDoc.GetElementsByTagName("WhiteCards")[0];
                SHA256CryptoServiceProvider hasher = new SHA256CryptoServiceProvider();
                byte[] allCards = Encoding.Default.GetBytes(xmlBlackCards.InnerXml + xmlWhiteCards.InnerXml);
                byte[] hash     = hasher.ComputeHash(allCards);
                Hash = Convert.ToBase64String(hash);

                if (cardSetInfo.GetAttribute("Hash") == Hash)
                {
                }
                else
                {
                    throw new FormatException("Card Set " + Name + " Corrupt.");
                }

                XmlNodeList CardBlock = cardSetDoc.GetElementsByTagName("CardPack");
                CardBlock = cardSetDoc.GetElementsByTagName("BlackCards");
                XmlNodeList Cards = CardBlock[0].ChildNodes;
                foreach (XmlElement Card in Cards)
                {
                    string cardID = guid + "/" + Card.Attributes["ID"].Value;
                    BlackCards.Add(cardID, new Card(cardID, Card.InnerText, Convert.ToInt32(Card.Attributes["Needs"].Value)));
                    BlackCardCount++;
                    BlackCardIndex.Add(BlackCardCount, cardID);
                }

                CardBlock = cardSetDoc.GetElementsByTagName("WhiteCards");
                Cards     = CardBlock[0].ChildNodes;
                foreach (XmlElement Card in Cards)
                {
                    string cardID = guid + "/" + Card.Attributes["ID"].Value;
                    WhiteCards.Add(cardID, new Card(cardID, Card.InnerText));
                    WhiteCardCount++;
                    WhiteCardIndex.Add(WhiteCardCount, cardID);
                }
            }
            Dealer.ShuffleCards(BlackCardIndex);
            Dealer.ShuffleCards(WhiteCardIndex);
        }
예제 #2
0
        /// <summary>
        /// Adds card to the coresponding base if it's not empty or already in deck
        /// </summary>
        /// <param name="card">White/Black card to be added</param>
        public void AddCardToList(dynamic card)
        {
            switch (card)
            {
            case BlackCard blackCard:
                if (!(IsCardAlreadyInDeck(blackCard) || string.IsNullOrEmpty(blackCard.OriginalText)))
                {
                    BlackCards.Add(blackCard);
                }
                break;

            case WhiteCard whiteCard:
                if (!(IsCardAlreadyInDeck(whiteCard) || string.IsNullOrEmpty(whiteCard.OriginalText)))
                {
                    WhiteCards.Add(whiteCard);
                }
                break;

            default:
                break;
            }
        }
예제 #3
0
 public void AddWhiteCard(string text)
 {
     WhiteCards.Add(text);
 }