/// <summary> /// Loads the cards from the database. /// </summary> /// <param name="filename">The filename of the XML Card Database.</param> /// <returns>A List of every card in the database</returns> private List<Card> LoadCardsFromDatabase(string filename) { var _cards = new List<Card>(); var xml = XDocument.Load(filename); // Load the cards var xmlCardList = from c in xml.Descendants("cards").Elements("card") orderby (string)c.Element("name") select new { Name = (string)c.Element("name"), Set = (string)c.Element("set"), ImageUri = (string)c.Element("set").Attribute("picURL"), Color = (string)c.Element("color"), ManaCost = (string)c.Element("manacost"), Type = (string)c.Element("type"), PT = (string)c.Element("pt"), Text = (string)c.Element("text") }; foreach(var card in xmlCardList) { int power = 0; int toughness = 0; if(card.PT != null) { string[] ptParts = card.PT.Split('/'); try { power = int.Parse(ptParts[0]); toughness = int.Parse(ptParts[1]); } catch(System.FormatException) { power = 0; toughness = 0; } } var cardEntry = new Card { Name = card.Name, Set = card.Set, ImageUri = card.ImageUri, Color = card.Color, ManaCost = card.ManaCost, Type = card.Type, Power = power, Toughness = toughness, Text = card.Text }; _cards.Add(cardEntry); } return _cards; }
/// <summary> /// Checks if the card meets certain filter conditions. /// </summary> /// <param name="card">The card to check the conditions of.</param> /// <param name="setFilter">A comma-separated list of sets to include.</param> /// <param name="colorFilter">A comma-separated list of colors to include</param> /// <returns>true if the conditions are met, false otherwise.</returns> private bool CheckFilterConditions(Card card, string setFilter, string colorFilter) { bool passesSetFilter = false; bool passesColorFilter = false; if(setFilter != string.Empty) { string[] sets = setFilter.Split(','); foreach(var set in sets) { if(card.Set.ToLower() == set.ToLower()) { passesSetFilter = true; break; } } } else { passesSetFilter = true; } if(colorFilter != string.Empty) { string[] colors = colorFilter.Split(','); foreach(var color in colors) { if((card.Color != null ? card.Color : "X").ToLower() == color.ToLower()) { passesColorFilter = true; break; } } } else { passesColorFilter = true; } return (passesSetFilter && passesColorFilter); }