public static ICookie BakeCookie()
        {
            ICookie cookie = new BaseCookie(Bakery.NextCookieId);

            var random    = new Random();
            var randomNum = random.Next(0, 4);

            switch (randomNum)
            {
            case 1:
                cookie = new VanillaDecorator(cookie);
                break;

            case 2:
                cookie = new ChocolateDecorator(cookie);
                break;

            case 3:
                cookie = new VanillaDecorator(new ChocolateDecorator(cookie));
                break;
            }

            Bakery.NextCookieId++;
            return(cookie);
        }
Example #2
0
        public void BakeCookies()
        {
            Running = true;
            var dailyQuota    = 25;
            var cookieCounter = new List <int>()
            {
                0, 0, 0, 0
            };
            var time = new Stopwatch();

            time.Start();
            while (cookieCounter.Sum() < dailyQuota)
            {
                var     rand = new Random();
                var     type = rand.Next(cookieCounter.Count);
                ICookie c;

                if (type == 0)
                {
                    c = new BaseCookie(cookieCounter[0]++);
                }
                else if (type == 1)
                {
                    c = new ChoclateChip(new BaseCookie(cookieCounter[1]++));
                }
                else if (type == 2)
                {
                    c = new Vanilla(new BaseCookie(cookieCounter[2]++));
                }
                else
                {
                    c = new NutsAndRaisins(new BaseCookie(cookieCounter[3]++));
                }

                _cookies.Add(c);
                Console.WriteLine(c.GetBakery() + " made " + c.GetName() + " #" + (c.GetNumber() + 1));
                while (time.ElapsedMilliseconds < 667)
                {
                }
                time.Restart();
            }
            Running = false;
            Console.WriteLine("Daily quota of {0} cookies total met. Stopping cookie production :(", dailyQuota);
        }