Exemplo n.º 1
0
        public void Color(IEgg egg, IBunny bunny)
        {
            if (bunny.Energy > 0)
            {
                bool isThereADyes  = bunny.Dyes.Any(x => x.Power > 0);
                bool isEggFinished = false;

                if (isThereADyes)
                {
                    foreach (var item in bunny.Dyes.Where(x => x.Power > 0))
                    {
                        while (item.Power > 0 && !isEggFinished)
                        {
                            item.Use();
                            bunny.Work();
                            egg.GetColored();
                            isEggFinished = egg.IsDone();
                            if (isEggFinished)
                            {
                                break;
                            }
                        }
                        if (isEggFinished)
                        {
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public IEgg collectEgg()
        {
            IEgg returned = eggs.First();

            eggs.RemoveAt(0);
            return(returned);
        }
Exemplo n.º 3
0
        public string ColorEgg(string eggName)
        {
            List <IBunny> readyToDye = bunnies.Models.Where(x => x.Energy >= 50).ToList();
            IEgg          egg        = eggs.FindByName(eggName);

            if (readyToDye.Count == 0)
            {
                throw new InvalidOperationException("There is no bunny ready to start coloring!");
            }

            foreach (var b in readyToDye)
            {
                ws.Color(egg, b);

                if (b.Energy <= 0)
                {
                    bunnies.Remove(b);
                }

                if (egg.IsDone())
                {
                    break;
                }
            }

            string result = egg.IsDone() ? "done" : "not done";

            return($"Egg {eggName} is {result}.");
        }
Exemplo n.º 4
0
        public string ColorEgg(string eggName)
        {
            IEgg egg       = eggs.FindByName(eggName);
            bool isEggDone = false;

            if (bunnies.Models.Any(x => x.Energy > 0))
            {
                List <IBunny> orderedBunnies = bunnies.Models.Where(x => x.Energy >= 50).ToList();
                orderedBunnies = orderedBunnies.OrderByDescending(x => x.Energy).ToList();

                foreach (var item in orderedBunnies)
                {
                    workshop.Color(egg, item);
                    if (item.Energy == 0)
                    {
                        bunnies.Remove(item);
                    }
                    if (egg.IsDone())
                    {
                        isEggDone = true;
                        break;
                    }
                }
            }
            else
            {
                throw new InvalidOperationException(ExceptionMessages.BunniesNotReady);
            }

            return($"Egg {eggName} is {(isEggDone ? "done" : "not done")}.");
        }
Exemplo n.º 5
0
        public void Color(IEgg egg, IBunny bunny)
        {
            var dyes = bunny.Dyes;

            foreach (var dye in dyes)
            {
                while (!egg.IsDone())
                {
                    if (bunny.Energy > 0 && !dye.IsFinished())
                    {
                        dye.Use();
                        bunny.Work();
                        egg.GetColored();
                    }
                    else
                    {
                        break;
                    }
                }

                if (egg.IsDone() || bunny.Energy <= 0)
                {
                    break;
                }
            }
        }
Exemplo n.º 6
0
        static void Main(String[] args)
        {
            Factory.Instance.Chicken().Create(out IEgg egg_1);
            Console.WriteLine($"Created {egg_1.GetType().Name} ({nameof(egg_1)})");

            ICreature creature_1 = egg_1.Hatch();

            Console.WriteLine($"{egg_1.GetType().Name} has hatched a {creature_1.GetType().Name} ({nameof(creature_1)}))");

            creature_1.Factory = Factory.Instance.Ostrich();
            Console.WriteLine($"Injected egg factory into {creature_1.GetType().Name}");

            IEgg egg_2 = creature_1.Lay();

            Console.WriteLine($"{creature_1.GetType().Name} has layed a {egg_2.GetType().Name} ({nameof(egg_2)})");

            ICreature creature_2 = egg_2.Hatch();

            Console.WriteLine($"{egg_2.GetType().Name} has hatched a {creature_2.GetType().Name} ({nameof(creature_2)})");

            IEgg egg_3 = creature_2.Lay();

            Console.WriteLine($"{creature_2.GetType().Name} has layed a {egg_3.GetType().Name} ({nameof(egg_3)})");

            egg_3.Factory = Factory.Instance.TRex();
            Console.WriteLine($"Injected creature factory into {egg_3.GetType().Name}");

            ICreature creature_3 = egg_3.Hatch();

            Console.WriteLine($"{egg_3.GetType().Name} has hatched a {creature_3.GetType().Name} ({nameof(creature_3)})");
        }
Exemplo n.º 7
0
        public void Color(IEgg egg, IBunny bunny)
        {
            if (bunny.Energy > 0 && bunny.Dyes.Any(d => d.Power > 0))
            {
                while (!egg.IsDone())
                {
                    var usedDye = bunny.Dyes.FirstOrDefault(d => d.Power > 0);
                    if (usedDye != null)
                    {
                        usedDye.Use();
                        egg.GetColored();
                    }
                    else
                    {
                        var HasNewDay = bunny.Dyes.Any(d => d.Power > 0);
                        if (HasNewDay)
                        {
                            var newDay = bunny.Dyes.First(d => d.Power > 0);
                            newDay.Use();
                            egg.GetColored();
                        }
                        else
                        {
                            bunny.Dyes.Remove(usedDye);
                            break;
                        }
                    }

                    if (bunny.Energy < 0 || bunny.Dyes.All(d => d.Power == 0))
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 8
0
        public string ColorEgg(string eggName)
        {
            IEgg          eggToColor      = eggs.FindByName(eggName);
            List <IBunny> orderderBunnies = bunnies.Models.OrderByDescending(x => x.Energy).Where(y => y.Energy >= 50).ToList();

            if (orderderBunnies.Count() == 0)
            {
                throw new InvalidOperationException(ExceptionMessages.BunniesNotReady);
            }
            for (int i = 0; i < orderderBunnies.Count(); i++)
            {
                IBunny currentBunny = orderderBunnies[i];
                worshop.Color(eggToColor, currentBunny);
                if (eggToColor.IsDone())
                {
                    break;
                }
                if (currentBunny.Energy <= 0)
                {
                    orderderBunnies.Remove(currentBunny);
                    bunnies.Remove(currentBunny);
                    i--;
                }
            }
            if (eggToColor.IsDone())
            {
                return(String.Format(OutputMessages.EggIsDone, eggName));
            }
            else
            {
                //return OutputMessages.EggIsNotDone
                return(String.Format(OutputMessages.EggIsNotDone, eggName));
            }
        }
Exemplo n.º 9
0
        public void Color(IEgg egg, IBunny bunny)
        {
            IDye dye = null;

            while (!egg.IsDone())
            {
                if (dye == null || dye.IsFinished())
                {
                    dye = bunny.Dyes.FirstOrDefault(d => d.Power > 0);

                    if (dye == null)
                    {
                        break;
                    }
                }
                dye.Use();
                bunny.Work();
                egg.GetColored();

                if (bunny.Energy == 0)
                {
                    break;
                }
            }
        }
        public void Color(IEgg egg, IBunny bunny)
        {
            foreach (var dye in bunny.Dyes)
            {
                while (!dye.IsFinished())
                {
                    if (bunny.Energy == 0)
                    {
                        break;
                    }

                    egg.GetColored();
                    bunny.Work();
                    dye.Use();

                    if (egg.IsDone())
                    {
                        break;
                    }
                }

                if (egg.IsDone())
                {
                    break;
                }
            }
        }
        public void Color(IEgg egg, IBunny bunny)
        {
            while (bunny.Energy > 0 && bunny.Dyes.Any())
            {
                var dye = bunny.Dyes.FirstOrDefault(x => !x.IsFinished());

                while (!dye.IsFinished() && !egg.IsDone())
                {
                    bunny.Work();
                    dye.Use();
                    egg.GetColored();

                    if (bunny.Energy == 0)
                    {
                        break;
                    }
                }

                if (dye.IsFinished())
                {
                    bunny.Dyes.Remove(dye);
                }

                if (egg.IsDone())
                {
                    break;
                }
            }
        }
Exemplo n.º 12
0
        public string ColorEgg(string eggName)
        {
            List <IBunny> bunniesToUse = bunnies.Models.Where(x => x.Energy >= 50).OrderByDescending(x => x.Energy).ToList();
            IEgg          egg          = eggs.FindByName(eggName);
            Workshop      workshop     = new Workshop();

            if (!bunniesToUse.Any())
            {
                throw new InvalidOperationException("There is no bunny ready to start coloring!");
            }

            foreach (var bunny in bunniesToUse)
            {
                workshop.Color(egg, bunny);

                if (bunny.Energy <= 0)
                {
                    bunnies.Remove(bunny);
                }

                if (egg.IsDone())
                {
                    break;
                }
            }

            return($"Egg {eggName} is {(egg.IsDone() ? "done" : "not done")}.");
        }
Exemplo n.º 13
0
        public void Color(IEgg egg, IBunny bunny)
        {
            bool finishColoring = false;

            while (!egg.IsDone() &&
                   bunny.Energy > 0 &&
                   bunny.Dyes.Any(d => !d.IsFinished()))
            {
                foreach (IDye dye in bunny.Dyes.Where(d => !d.IsFinished()))
                {
                    if (finishColoring)
                    {
                        break;
                    }

                    while (true)
                    {
                        egg.GetColored();
                        dye.Use();
                        bunny.Work();

                        if (egg.IsDone() || bunny.Energy == 0)
                        {
                            finishColoring = true;
                            break;
                        }

                        if (dye.IsFinished())
                        {
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 14
0
        public string ColorEgg(string eggName)
        {
            var suitableBunnies = this.bunnies.Models.Where(b => b.Energy >= 50).OrderByDescending(b => b.Energy).ToList();

            if (!suitableBunnies.Any())
            {
                throw new InvalidOperationException("There is no bunny ready to start coloring!");
            }

            IEgg egg = this.eggs.FindByName(eggName);

            foreach (IBunny bunny in suitableBunnies)
            {
                this.workshop.Color(egg, bunny);

                if (bunny.Energy == 0)
                {
                    this.bunnies.Remove(bunny);
                }

                if (egg.IsDone())
                {
                    this.countColoredEggs++;
                    break;
                }
            }

            return(egg.IsDone() ? $"Egg {egg.Name} is done" : $"Egg {egg.Name} is not done.");
        }
Exemplo n.º 15
0
        public string ColorEgg(string eggName)
        {
            IEgg egg = eggs.FindByName(eggName);

            List <IBunny> orderedBunnies = bunnies.Models.Where(x => x.Energy >= 50).ToList();

            if (orderedBunnies.Count == 0)
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.BunniesNotReady));
            }

            foreach (var bunny in orderedBunnies)
            {
                workshop.Color(egg, bunny);
                if (bunny.Energy == 0)
                {
                    bunnies.Remove(bunny);
                    if (orderedBunnies.Count == 0)
                    {
                        break;
                    }
                }
                if (egg.IsDone() == true)
                {
                    break;
                }
            }


            if (egg.IsDone() == false)
            {
                return($"Egg {eggName} is not done.");
            }
            return($"Egg {eggName} is done.");
        }
Exemplo n.º 16
0
        public void Color(IEgg egg, IBunny bunny)   ///problemmm
        {
            while (egg.IsDone() == false && bunny.Energy > 0 && bunny.Dyes.Any(x => x.IsFinished() == false))
            {
                egg.GetColored();

                bunny.Work();
                IDye dye = bunny.Dyes.FirstOrDefault(x => x.IsFinished() == false);

                dye.Use();
            }
        }
Exemplo n.º 17
0
        public void Color(IEgg egg, IBunny bunny)
        {
            while (true)
            {
                if (bunny.Energy == 0)
                {
                    break;
                }

                if (bunny.Dyes.All(x => x.IsFinished()))
                {
                    break;
                }

                egg.GetColored();
                bunny.Work();

                while (bunny.Dyes.Any())
                {
                    if (bunny.Dyes.First().IsFinished() == false)
                    {
                        bunny.Dyes.First().Use();
                        break;
                    }

                    bunny.Dyes.Remove(bunny.Dyes.First());
                }
                if (egg.IsDone())
                {
                    break;
                }
            }

/*
 *          while (!egg.IsDone())
 *          {
 *              if (bunny.Energy == 0)
 *              {
 *                  break;
 *              }
 *
 *              if (bunny.Dyes.All(x => x.IsFinished()))
 *              {
 *                  break;
 *              }
 *
 *              egg.GetColored();
 *              bunny.Work(); ;
 *          }
 *
 */
        }
Exemplo n.º 18
0
        public void Color(IEgg egg, IBunny bunny)
        {
            while (bunny.Energy > 0 &&
                   bunny.Dyes.Any(d => !d.IsFinished()) &&
                   !egg.IsDone())
            {
                var dye = bunny.Dyes.FirstOrDefault(d => !d.IsFinished());

                dye.Use();
                bunny.Work();
                egg.GetColored();
            }
        }
Exemplo n.º 19
0
        public string ColorEgg(string eggName)
        {
            IEgg egg = eggs.FindByName(eggName);

            IWorkshop workshop = new Workshop();

            var sortedBunnies = bunnies.Models
                                .Where(b => b.Energy >= 50)
                                .OrderByDescending(b => b.Energy)
                                .ToList();

            if (sortedBunnies.Count == 0)
            {
                throw new InvalidOperationException(ExceptionMessages.BunniesNotReady);
            }

            while (sortedBunnies.Any())
            {
                IBunny bunny = sortedBunnies.First();

                while (true)
                {
                    if (bunny.Energy == 0 || bunny.Dyes.All(d => d.IsFinished()))
                    {
                        sortedBunnies.Remove(bunny);
                        break;
                    }

                    workshop.Color(egg, bunny);

                    if (egg.IsDone())
                    {
                        break;
                    }
                }

                if (egg.IsDone())
                {
                    break;
                }
            }

            if (egg.IsDone())
            {
                return(string.Format(OutputMessages.EggIsDone, eggName));
            }
            else
            {
                return(string.Format(OutputMessages.EggIsNotDone, eggName));
            }
        }
        public string ColorEgg(string eggName)
        {
            IEgg egg = eggs.FindByName(eggName);

            List <IBunny> bunniesReadyToColor = bunnies.Models
                                                .Where(e => e.Energy >= 50)
                                                .OrderByDescending(e => e.Energy)
                                                .ToList();

            if (bunniesReadyToColor.Count == 0)
            {
                throw new InvalidOperationException(ExceptionMessages.BunniesNotReady);
            }

            StringBuilder sb = new StringBuilder();

            foreach (var bunny in bunniesReadyToColor)
            {
                workshop.Color(egg, bunny);

                if (egg.IsDone())
                {
                    break;
                }
            }

            sb.Append($"Egg {egg.Name} is ");

            if (egg.IsDone())
            {
                sb.Append("done.");
            }
            else
            {
                sb.Append("not done.");
            }

            //RemoveBunnies(bunniesReadyToColor);

            foreach (var bunny in bunniesReadyToColor)
            {
                if (bunny.Energy == 0)
                {
                    bunnies.Remove(bunny);
                }
            }

            return(sb.ToString().TrimEnd());
        }
Exemplo n.º 21
0
        public void Color(IEgg egg, IBunny bunny)
        {
            while (bunny.Energy > 0 && bunny.Dyes.Any(d => d.Power > 0))
            {
                if (egg.IsDone())
                {
                    break;
                }

                IDye d = bunny.Dyes.FirstOrDefault(x => x.Power > 0);
                d.Use();
                bunny.Work();
                egg.GetColored();
            }
        }
Exemplo n.º 22
0
        public void Color(IEgg egg, IBunny bunny)
        {
            var dyeForColoring = bunny.Dyes.FirstOrDefault(dye => dye.Power > 0);

            while ((bunny.Energy > 0 && bunny.Dyes.Any(dye => dye.Power > 0)) || !egg.IsDone())
            {
                dyeForColoring.Use();
                if (dyeForColoring.Power == 0)
                {
                    dyeForColoring = bunny.Dyes.FirstOrDefault(dye => dye.Power > 0);
                }
                bunny.Work();

                egg.GetColored();
            }
        }
Exemplo n.º 23
0
        public void Color(IEgg egg, IBunny bunny)
        {
            while (!egg.IsDone())
            {
                if (bunny.Energy == 0)
                {
                    break;
                }

                if (bunny.Dyes.All(x => x.IsFinished()))
                {
                    break;
                }

                egg.GetColored();
                bunny.Work();
            }
        }
Exemplo n.º 24
0
        public void Color(IEgg egg, IBunny bunny)
        {
            while (bunny.Energy > 0 && bunny.Dyes.Count > 0)
            {
                var dye = bunny.Dyes.First();
                egg.GetColored();
                dye.Use();
                bunny.Work();

                if (dye.IsFinished())
                {
                    bunny.Dyes.Remove(dye);
                }

                if (egg.IsDone())
                {
                    break;
                }
            }
        }
Exemplo n.º 25
0
        public void Color(IEgg egg, IBunny bunny)
        {
            while (egg.IsDone() == false)
            {
                if (bunny.Energy == 0 || bunny.Dyes.All(x => x.IsFinished()))
                {
                    break;
                }

                IDye dye = (IDye)bunny.Dyes.First();
                dye.Use();
                egg.GetColored();
                bunny.Work();

                if (dye.IsFinished())
                {
                    bunny.Dyes.Remove(dye);
                }
            }
        }
Exemplo n.º 26
0
        public string ColorEgg(string eggName)
        {
            IEgg egg = eggs.FindByName(eggName);

            IWorkshop workshop = new Workshop();

            List <IBunny> suitableBunnies = bunnies.Models.Where(x => x.Energy >= 50).OrderByDescending(x => x.Energy).ToList();

            if (suitableBunnies.Any() == false)
            {
                throw new InvalidOperationException(ExceptionMessages.BunniesNotReady);
            }

            while (suitableBunnies.Any())
            {
                IBunny currentBunny = suitableBunnies.First();

                while (true)
                {
                    if (currentBunny.Energy == 0 || currentBunny.Dyes.All(x => x.IsFinished()))
                    {
                        suitableBunnies.Remove(currentBunny);
                        break;
                    }

                    workshop.Color(egg, currentBunny);

                    if (egg.IsDone())
                    {
                        break;
                    }
                }

                if (egg.IsDone())
                {
                    break;
                }
            }

            return($"Egg {eggName} is {(egg.IsDone() ? "done" : "not done")}.");
        }
Exemplo n.º 27
0
        public string ColorEgg(string eggName)
        {
            IEgg egg = eggs.FindByName(eggName);

            List <IBunny> currBuunies = bunnies.Models.ToList();
            //currBuunies = (List<IBunny>)currBuunies.Where(b => b.Energy >= 50 );

            IBunny currbunny = null;

            foreach (var bunny in currBuunies.OrderByDescending(b => b.Energy))
            {
                if (currBuunies.Count == 0)
                {
                    throw new InvalidOperationException(Utilities.Messages.ExceptionMessages.BunniesNotReady);
                }

                IWorkshop work = new Workshop();
                if (bunny.Energy >= 50)
                {
                    currbunny = bunny;
                    //IWorkshop work = new Workshop();
                    work.Color(egg, currbunny);

                    if (currbunny.Energy == 0)
                    {
                        bunnies.Remove(currbunny);
                    }
                }
            }

            if (egg.IsDone())
            {
                return(string.Format(Utilities.Messages.OutputMessages.EggIsDone, eggName));
            }

            return(string.Format(Utilities.Messages.OutputMessages.EggIsNotDone, eggName));
        }
Exemplo n.º 28
0
 public void Color(IEgg egg, IBunny bunny)
 {
     while (true)
     {
         if (bunny.Energy == 0)
         {
             break;
         }
         if (bunny.Dyes.All(x => x.IsFinished() == true))
         {
             break;
         }
         IDye currentDye = bunny.Dyes.FirstOrDefault(x => x.IsFinished() == false);
         while (true)
         {
             if (currentDye.IsFinished())
             {
                 break;
             }
             currentDye.Use();
             bunny.Work();
             egg.GetColored();
             if (egg.IsDone())
             {
                 break;
             }
         }
         //currentDye.Use();
         //bunny.Work();
         //egg.GetColored();
         if (egg.IsDone())
         {
             break;
         }
     }
 }
Exemplo n.º 29
0
        public void Color(IEgg egg, IBunny bunny)
        {
            while (bunny.Energy > 0 && bunny.Dyes.Any())
            {
                IDye currentEgg = bunny.Dyes.First();

                while (!egg.IsDone() && bunny.Energy > 0 && !currentEgg.IsFinished())
                {
                    egg.GetColored();
                    bunny.Work();
                    currentEgg.Use();
                }

                if (currentEgg.IsFinished())
                {
                    bunny.Dyes.Remove(currentEgg);
                }

                if (egg.IsDone())
                {
                    break;
                }
            }
        }
Exemplo n.º 30
0
 public void Create(out IEgg obj) => obj = new OstrichEgg();