Exemple #1
0
            public void Main()
            {
                var goods = GoodsFactory.Create(GoodsType.Character, 1);

                goods = GoodsFactory.Create(GoodsType.Box, 1);
                goods = GoodsFactory.Create(GoodsType.Weapon, 1, 2);
            }
Exemple #2
0
    /// <summary>
    /// 武神塔获得物品
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public static List <Goods> GetKungfuGodReward(uint id)
    {
        List <Goods>  goodsList        = new List <Goods>();
        List <string> data_secret_area = DBManager.Instance.QuerySqliteField <string>(GlobalConfig.DBFile, "data_secret_area", "id", id.ToString(), "goods");

        if (data_secret_area.Count == 0)
        {
            return(goodsList);
        }

        string raw = data_secret_area[0];

        raw = raw.Replace(" ", "");
        var matchs = Regex.Matches(raw, @"\{(\d+),(\d+)\}");

        foreach (Match _match in matchs)
        {
            if (_match.Success)
            {
                uint  goodsid  = DBTextResource.ParseUI(_match.Groups[1].Value);
                uint  goodsnum = DBTextResource.ParseUI(_match.Groups[2].Value);
                Goods goods    = GoodsFactory.Create(goodsid, null);
                if (goods != null)
                {
                    goods.num = goodsnum;
                    goodsList.Add(goods);
                }
            }
        }
        return(goodsList);
    }
        public void TownInitialize()
        {
            races = new List <RaceEntity>();
            races.Add(RaceFactory.Create("Race_01", RaceType.HUMAN));

            goods = new List <GoodsEntity>();
            goods.Add(GoodsFactory.Create(GoodsType.FLOUR, "小麦"));

            var building = new SimpleProducer("農場", new ProduceAbility(goods.First(), 10), 5);

            townEntity = TownFactory.Create(0, "town_01", TownType.INLAND, races.First());
            townEntity.Build(0, building);
        }
        public void Create_Returns_NonImportedGood_Given_Valid_GoodsInfo()
        {
            //Arrange
            string category = "general";
            int    quantity = 1;
            string name     = "music CD";
            double price    = 15.50;

            IGoodsFactory target = new GoodsFactory();

            //Act
            IGoods actual = target.Create(category, quantity, name, price);

            //Assert
            Assert.AreEqual(actual.Name, name);
            Assert.AreEqual(actual.Price, price);
            Assert.AreEqual(actual.Quantity, quantity);
            Assert.IsInstanceOf <Goods>(actual, typeof(Goods).ToString());
        }
        public void Create_Returns_TaxExemptGood_Given_Valid_TaxExemptGoodInfo()
        {
            //Arrange
            string category = "books";
            int    quantity = 1;
            string name     = "cook book";
            double price    = 12.15;

            IGoodsFactory target = new GoodsFactory();

            //Act
            IGoods actual = target.Create(category, quantity, name, price);

            //Assert
            Assert.AreEqual(actual.Name, name);
            Assert.AreEqual(actual.Price, price);
            Assert.AreEqual(actual.Quantity, quantity);
            Assert.IsInstanceOf <TaxExemptGood>(actual, typeof(TaxExemptGood).ToString());
        }
        public void Create_Returns_ImportedTaxExemptGood_Given_Valid_ImportedTaxExemptGoodInfo()
        {
            //Arrange
            string category = "food";
            int    quantity = 1;
            string name     = "imported chocolate";
            double price    = 10.50;

            IGoodsFactory target = new GoodsFactory();

            //Act
            IGoods actual = target.Create(category, quantity, name, price);

            //Assert
            Assert.AreEqual(actual.Name, name);
            Assert.AreEqual(actual.Price, price);
            Assert.AreEqual(actual.Quantity, quantity);
            Assert.AreEqual(actual.Imported, true);
            Assert.IsInstanceOf <TaxExemptGood>(actual, typeof(TaxExemptGood).ToString());
        }
        public List <List <IGoods> > CreateShoppingCart(string inputFilePath)
        {
            var factory = new GoodsFactory();
            List <List <IGoods> > shoppingCart   = new List <List <IGoods> >();
            List <string>         categoriesList = new List <string>()
            {
                "general", "books", "food", "medical"
            };
            List <IGoods> temp = new List <IGoods>();

            string[] inputText = null;
            while (inputText == null)
            {
                try
                {
                    inputText = File.ReadAllLines(@inputFilePath);
                }
                catch (Exception e)
                {
                    Console.Write("File was not found. Please enter the correct file path: ");
                    inputFilePath = Console.ReadLine();
                }
            }

            foreach (string input in inputText)
            {
                string entry = input.ToLower();
                if (entry.ToLower().Contains("input"))
                {
                    temp = new List <IGoods>();
                    continue;
                }
                if (entry.StartsWith(" "))
                {
                    shoppingCart.Add(temp);
                    continue;
                }
                try
                {
                    string separator        = "at";
                    int    split            = entry.LastIndexOf(separator);
                    string info             = entry.Substring(0, split);
                    string priceString      = entry.Substring(split).Remove(0, 3);
                    int    quantityPosition = info.IndexOf(' ') + 1;
                    string category         = info.Substring(0, quantityPosition - 1);
                    if (!categoriesList.Contains(category))
                    {
                        throw new InvalidCategoryException("Invalid Category, please refer to the categories provided and try again.");
                    }
                    int    quantity   = Int32.Parse(info.Substring(quantityPosition, 1));
                    string nameString = info.Substring(quantityPosition + 1).TrimStart();
                    double price      = Double.Parse(priceString);

                    temp.Add(factory.Create(category, quantity, nameString, price));
                }
                catch (Exception e)
                {
                    if (e is InvalidCategoryException)
                    {
                        Console.WriteLine(e.Message);
                    }
                    else
                    {
                        Console.WriteLine("Invalid Entry, please refer to the correct format above.");
                    }
                }
            }
            shoppingCart.Add(temp);
            return(shoppingCart);
        }