public List <Card> ReadCardsOfFile(string fileName) { System.IO.StreamReader reader = null; string pattern = @"(\w*)\s*-\s(\w*|\d*)\s*-\s(\w*)"; List <Card> cards = new List <Card>(); try { reader = new System.IO.StreamReader(fileName); string line = reader.ReadToEnd(); string[] lines = line.Split('\n'); foreach (var item in lines) { if (!String.IsNullOrEmpty(item)) { foreach (Match m in Regex.Matches(item, pattern)) { Card.names name = (Card.names)Enum.Parse(typeof(Card.names), m.Groups[2].Value); Card.suits suit = (Card.suits)Enum.Parse(typeof(Card.suits), m.Groups[1].Value); cards.Add(new Card(suit, name, m.Groups[3].Value)); } } } } catch (Exception) { Console.WriteLine("Error reader file"); throw; } finally { reader.Close(); } return(cards); }
public Card(Card.suits _suit, Card.names _value, string _color) { this.suit = _suit; this.name = _value; this.color = _color; }