Exemplo n.º 1
0
        public string ColorEgg(string eggName)
        {
            List <IBunny> bunnies = bunnyRepository.Models.Where(b => b.Energy >= 50).OrderByDescending(x => x.Energy).ToList();

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

            var egg      = this.eggRepository.FindByName(eggName);
            var workshop = new Workshop();

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

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

            if (egg.IsDone())
            {
                return(string.Format(OutputMessages.EggIsDone, eggName));
            }
            else
            {
                return(string.Format(OutputMessages.EggIsNotDone, eggName));
            }
        }
Exemplo n.º 2
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.º 3
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.º 4
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));
            }
        }
        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());
        }