コード例 #1
0
        public List <Item> ParseLinesToItems(List <string> lines)
        {
            List <Item> items = new List <Item>();

            foreach (string line in lines)
            {
                // Use regular expressions to extract the data
                Match itemNameMatch = Regex.Match(line, @"([a-zA-Z ])+");
                if (!itemNameMatch.Success)
                {
                    throw new InvalidOperationException();
                }

                Item item;
                // Need to remove trailing space
                switch (itemNameMatch.Value.Trim())
                {
                case "Normal Item":
                    item = new Item();
                    break;

                case "Aged Brie":
                    item = new AgedBrie();
                    break;

                case "Sulfuras":
                    item = new Sulfuras();
                    break;

                case "Backstage passes":
                    item = new BackstagePasses();
                    break;

                case "Conjured":
                    item = new ConjuredItem();
                    break;

                default:
                    item = new UnknownItem();
                    break;
                }

                // Match positive or negative digits
                Match sellInAndQualityMatch = Regex.Match(line, @"(-?\d+)");
                if (!itemNameMatch.Success)
                {
                    throw new InvalidOperationException();
                }

                // SellIn value comes first
                item.SellIn = Int32.Parse(sellInAndQualityMatch.Value);

                sellInAndQualityMatch = sellInAndQualityMatch.NextMatch();
                item.Quality          = Int32.Parse(sellInAndQualityMatch.Value);

                items.Add(item);
            }

            return(items);
        }
コード例 #2
0
        public void wow_Sulfuras()
        {
            var Items = new Sulfuras(10);

            Items.Update();
            Assert.AreEqual("Sulfuras, Hand of Ragnaros", Items.Name);
            Assert.AreEqual(10, Items.SellIn);
            Assert.AreEqual(80, Items.Quality);
        }
コード例 #3
0
 private static IItem GetSelectedObject(int selectedItem)
 {
     if (selectedItem == 0)
     {
         Console.WriteLine("What is this Items Name? ");
         string name = Console.ReadLine();
         Console.WriteLine("How many days does this have to sell? ");
         int sellIn = int.Parse(Console.ReadLine());
         Console.WriteLine("What is the starting quality of this item? ");
         int quality = int.Parse(Console.ReadLine());
         return(new NormalItem(name, sellIn, quality));
     }
     else if (selectedItem == 1)
     {
         const string NAME = "Aged Brie";
         Console.WriteLine("How many days does this have to sell? ");
         int sellIn = int.Parse(Console.ReadLine());
         Console.WriteLine("What is the starting quality of this item? ");
         int quality = int.Parse(Console.ReadLine());
         return(new AgedBrie(NAME, sellIn, quality));
     }
     else if (selectedItem == 2)
     {
         Console.WriteLine("What is this Items Name? ");
         string name = Console.ReadLine();
         Console.WriteLine("How many days does this have to sell? ");
         int sellIn = int.Parse(Console.ReadLine());
         Console.WriteLine("What is the starting quality of this item? ");
         int quality = int.Parse(Console.ReadLine());
         return(new ConjuredItem(name, sellIn, quality));
     }
     else if (selectedItem == 3)
     {
         Console.WriteLine("What show is this Backstage Pass for? ");
         string name = Console.ReadLine();
         Console.WriteLine("How many days does this have to sell? ");
         int sellIn = int.Parse(Console.ReadLine());
         Console.WriteLine("What is the starting quality of this item? ");
         int quality = int.Parse(Console.ReadLine());
         return(new BackStagePasses(name, sellIn, quality));
     }
     else if (selectedItem == 4)
     {
         Sulfuras sulfuras = new Sulfuras();
         sulfuras.Name = "Sulfuras";
         return(sulfuras);
     }
     else
     {
         return(new NormalItem());
     }
 }