public Image GetImage(Card card) { Image ret = null; lock(this) { m_indexMap.TryGetValue(card, out ret); } return ret; }
public void LoadImages(Card[] cards) { lock(this) { foreach (Card card in cards) { Image image = Image.FromFile(card.ImagePath); m_images.Add(image); m_indexMap.Add(card, image); } } }
/// <summary> /// ѡ���Ƶ�������ӿڣ���ӡ /// </summary> /// <param name="cards">ѡ�õ��ƣ���Card���鴫��</param> public void PrintCards(Card[] cards) { }
public void GetFromWeb(IGetFromWebNotify notifier) { Directory.CreateDirectory(Config.ImagePath); if (notifier != null) notifier.Notity(String.Format("���� {0}", Config.Uri), 0.0f); WebClient webClient = new WebClient(); webClient.Encoding = Encoding.UTF8; String strHtml = webClient.DownloadString(Config.Uri); if (notifier != null) notifier.Notity("����html�ĵ�", 0.0f); Lexer lexer = new Lexer(strHtml); Parser parser = new Parser(lexer); AndFilter andFilter = new AndFilter(new NodeClassFilter(typeof(TableRow)), new OrFilter(new HasAttributeFilter("class", "even"), new HasAttributeFilter("class", "odd"))); NodeList htmlNodes = parser.ExtractAllNodesThatMatch(andFilter); lock (this) { m_Cards = new List<Card>(); foreach (INode node in htmlNodes.ToNodeArray()) { int iFiledIndex = 0; Card card = new Card(); foreach (INode subNode in node.Children.ToNodeArray()) { if (subNode is TextNode) { continue; } switch (iFiledIndex) { case 0: card.ID = Convert.ToInt32(subNode.FirstChild.GetText()); card.ImagePath = Path.Combine(Config.ImagePath, card.ID.ToString() + ".jpg"); break; case 1: card.Name = subNode.FirstChild.FirstChild.GetText(); break; case 2: StringHelper.FillCardLongInfo(subNode.FirstChild.GetText(), card); break; case 3: if (subNode.FirstChild != null) { card.ManaCost = subNode.FirstChild.GetText(); } else { card.ManaCost = String.Empty; } break; case 4: card.Rare = subNode.FirstChild.GetText(); break; } iFiledIndex++; } m_Cards.Add(card); } } XmlSerializer s = new XmlSerializer(typeof(List<Card>)); FileStream fstream = new FileStream(Config.CardsXml, FileMode.CreateNew); s.Serialize(fstream, m_Cards); fstream.Close(); foreach (Card card in m_Cards) { if (notifier != null) notifier.Notity(String.Format("��ȡ��Ƭ\"{0}\"��Ϣ", card.Name), 1.0f / m_Cards.Count); webClient.DownloadFile(Path.Combine(Config.BaseImageUri, card.ID.ToString() + ".jpg"), card.ImagePath); } }
public static void FillCardLongInfo(String strText, Card card) { String[] strTmp = strText.Split(new char[2] { '��', ' ' }); card.Type = strTmp[0]; if (strTmp.Length == 4) { card.Loyalty = Convert.ToInt32(strTmp[3].TrimEnd(')')); } else if (strTmp.Length == 3) { card.Jobs.AddRange(strTmp[1].Split('��')); if (strTmp[2].Contains("*")) { card.Attack = -1; card.Defend = -1; } else { int iOffSet = strTmp[2].IndexOf('/'); card.Attack = Convert.ToInt32(strTmp[2].Substring(0, iOffSet)); card.Defend = Convert.ToInt32(strTmp[2].Substring(iOffSet + 1)); } } }
public CardIndexHelper(Card[] cards) { m_cards = cards; }