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;
                }
            }
        }
Пример #2
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.");
        }
Пример #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}.");
        }
        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;
                }
            }
        }
Пример #5
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.");
        }
Пример #6
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;
                }
            }
        }
Пример #7
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());
        }
Пример #9
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;
                        }
                    }
                }
            }
        }
Пример #10
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;
                }
            }
        }
Пример #11
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;
                    }
                }
            }
        }
Пример #12
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")}.");
        }
Пример #13
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();
            }
        }
Пример #14
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();
            }
        }
Пример #15
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();
            }
        }
Пример #16
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;
                }
            }
        }
Пример #17
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;
         }
     }
 }
Пример #18
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();
            }
        }
Пример #19
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);
                }
            }
        }
Пример #20
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;
                }
            }
        }
Пример #21
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));
        }