Beispiel #1
0
        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);
        }
Beispiel #2
0
        public List <int> findNameCards(List <Card> cards, Card.names name)
        {
            List <int> outList = new List <int>();

            for (int i = 0; i < cards.Count; ++i)
            {
                if (cards[i].name == name)
                {
                    outList.Add(i);
                }
            }
            return(outList);
        }
Beispiel #3
0
 public Card(Card.suits _suit, Card.names _value, string _color)
 {
     this.suit  = _suit;
     this.name  = _value;
     this.color = _color;
 }