Example #1
0
        public string[] restockStore()
        {
            // We have to keep track of money this time
            double moneyToSpend = f.getMoney();

            string[] productsAndCosts = new string[50]; // Only buy up to 25 things at once

            for (int index = 0; index < 50; index += 2)
            {
                // Make a product of the least common category
                Product thing = cf.factoryMethod(i.getLeastCommonCategory());

                // If we can afford it...
                if (thing.getPrice() < moneyToSpend)
                {
                    // Buy the product and add it to the list
                    products.Add(thing);
                    f.buy(thing.getPrice());
                    moneyToSpend -= thing.getPrice();
                    i.addProduct(thing.getID());

                    // And document it
                    productsAndCosts[index]     = thing.getDescription();
                    productsAndCosts[index + 1] = thing.getSalePrice().ToString();

                    // Then wait so the random number generator will come up with a new product next time
                    Thread.Sleep(15);
                }
                else
                {
                    break;  // If we're broke, break
                }
            }
            return(productsAndCosts);
        }