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")}."); }
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)); } }
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> 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."); }
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 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")}."); }
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()); }
public string ColorEgg(string eggName) { IWorkshop workshop = new Workshop(); var egg = this.eggs.FindByName(eggName); var workingBunnies = this.bunnies.Models .Where(b => b.Energy >= 50) .OrderByDescending(b => b.Energy) .ToList(); if (workingBunnies.Count == 0) { throw new InvalidOperationException(ExceptionMessages.BunniesNotReady); } while (workingBunnies.Any()) { var currBunny = workingBunnies.First(); workshop.Color(egg, currBunny); if (currBunny.Energy == 0) { this.bunnies.Remove(currBunny); } if (currBunny.Dyes.Count == 0) { workingBunnies.Remove(currBunny); } if (egg.IsDone()) { break; } } var message = egg.IsDone() ? OutputMessages.EggIsDone : OutputMessages.EggIsNotDone; var result = String.Format(message, eggName); return(result); }
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")}."); }
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)); }