public void Craft(IPresent present, IDwarf dwarf) { while (dwarf.Energy > DwarfMinEnergy && dwarf.Instruments.Any()) { var currentInstrument = dwarf.Instruments.First(); while (!present.IsDone() && dwarf.Energy > DwarfMinEnergy && !currentInstrument.IsBroken()) { dwarf.Work(); present.GetCrafted(); currentInstrument.Use(); } if (currentInstrument.IsBroken()) { dwarf.Instruments.Remove(currentInstrument); } if (present.IsDone()) { break; } } }
public void Craft(IPresent present, IDwarf dwarf) { while (dwarf.Energy > 0 && dwarf.Instruments.Any()) // итерираме между инструментите { IInstrument currInstrument = dwarf.Instruments.First(); while (!present.IsDone() && dwarf.Energy > 0 && !currInstrument.IsBroken()) // правим подаръка { dwarf.Work(); // намаляме енергията present.GetCrafted(); // намаляме необходимото за правенето на подаръка currInstrument.Use(); // намаляме здравето на инструмента } if (currInstrument.IsBroken()) //ако заедно с направата на подарък се е счупил и инструмента !!!! { dwarf.Instruments.Remove(currInstrument); } if (present.IsDone()) //подаръка е готов и излизаме { break; } } }
public void Craft(IPresent present, IDwarf dwarf) { var instruments = dwarf.Instruments.ToList(); while (true) { if (dwarf.Energy <= 0 || present.IsDone()) { break; } if (instruments[0].IsBroken()) { dwarf.Instruments.Remove(instruments[0]); instruments.RemoveAt(0); if (instruments.Count > 0) { continue; } else { break; } } instruments[0].Use(); dwarf.Work(); present.GetCrafted(); } }
public void Craft(IPresent present, IDwarf dwarf) { IInstrument instrument = null; while (dwarf.Energy > 0 && dwarf.Instruments.Any(x => x.Power > 0)) { instrument = dwarf.Instruments.FirstOrDefault(x => x.Power > 0); while (!present.IsDone() && dwarf.Energy > 0 && !instrument.IsBroken()) { dwarf.Work(); instrument.Use(); present.GetCrafted(); } if (instrument.IsBroken()) { dwarf.Instruments.Remove(instrument); } if (present.IsDone()) { break; } } }
public void Craft(IPresent present, IDwarf dwarf) { while (dwarf.Energy > 0 && dwarf.Instruments.Sum(el => el.Power) > 0 && !present.IsDone()) { dwarf.Work(); dwarf.Instruments.First(el => !el.IsBroken()).Use(); present.GetCrafted(); } }
public void Craft(IPresent present, IDwarf dwarf) { while (dwarf.Energy >= 0 && dwarf.Instruments.Any(x => x.IsBroken() == false) && (present.IsDone() == false)) { var instrument = dwarf.Instruments.First(x => x.IsBroken() == false); instrument.Use(); dwarf.Work(); present.GetCrafted(); } }
//The dwarf starts crafting the present.This is only possible, //if the dwarf has energy and an instrument that isn't broken. //At the same time the present is getting crafted, so call the GetCrafted() method for the present. //Keep working until the present is done or the dwarf has energy and instruments to use. //If at some point the power of the current instrument reaches or drops below 0, //meaning it is broken, then the dwarf should take the next instrument from its collection, if it has any left. public void Craft(IPresent present, IDwarf dwarf) { if (dwarf.Energy > 0 && dwarf.Instruments.Any(i => i.Power > 0)) { while ((dwarf.Energy > 0 && dwarf.Instruments.Any(i => i.Power > 0)) || !present.IsDone()) { dwarf.Work(); present.GetCrafted(); } } }
public void Craft(IPresent present, IDwarf dwarf) { while (true) { dwarf.Work(); present.GetCrafted(); if (present.IsDone) { break; } } }
public void Craft(IPresent present, IDwarf dwarf) { while (dwarf.Energy > 0 || !present.IsDone() || dwarf.Instruments.Any(x => !x.IsBroken())) { foreach (var instrument in dwarf.Instruments) { while (!instrument.IsBroken()) { instrument.Use(); dwarf.Work(); present.GetCrafted(); } } } }
public void Craft(IPresent present, IDwarf dwarf) { if (dwarf.Energy > 0 && dwarf.Instruments.Any(i => i.IsBroken() == false)) { while (true) { if (present.IsDone() || dwarf.Energy <= 0 || dwarf.Instruments.All(i => i.IsBroken())) { break; } present.GetCrafted(); dwarf.Work(); } } }
public void Craft(IPresent present, IDwarf dwarf) { while (!present.IsDone() && dwarf.Energy != 0) { var currInstrument = dwarf.Instruments.FirstOrDefault(x => !(x.IsBroken())); if (currInstrument != null && !currInstrument.IsBroken()) { dwarf.Work(); currInstrument.Use(); present.GetCrafted(); } else { break; } } }
public void Craft(IPresent present, IDwarf dwarf) { var instrument = dwarf.Instruments.FirstOrDefault(x => x.IsBroken() == false); while (present.IsDone() == false && dwarf.Energy > 0 && instrument != null) { present.GetCrafted(); instrument.Use(); dwarf.Work(); if (instrument.IsBroken()) { instrument = dwarf.Instruments.FirstOrDefault(x => x.IsBroken() == false); } } }
public void Craft(IPresent present, IDwarf dwarf) { while (true) { var currentInstrument = dwarf.Instruments.FirstOrDefault(); while (dwarf.Energy > 0 && currentInstrument.IsBroken() == false && present.IsDone() == false) { dwarf.Work(); present.GetCrafted(); } if (currentInstrument.IsBroken()) { dwarf.Instruments.Remove(currentInstrument); } } }
public void Craft(IPresent present, IDwarf dwarf) { var currentInstrument = dwarf.Instruments.FirstOrDefault(x => !x.IsBroken()); if (dwarf.Energy > 0 && currentInstrument != null) { while (present.EnergyRequired > 0 && currentInstrument != null && dwarf.Energy > 0 && !currentInstrument.IsBroken()) { dwarf.Work(); present.GetCrafted(); currentInstrument.Use(); if (currentInstrument.IsBroken()) { currentInstrument = dwarf.Instruments.FirstOrDefault(x => !x.IsBroken()); } } } }
public void Craft(IPresent present, IDwarf dwarf) { var instrument = dwarf.Instruments.FirstOrDefault(i => !i.IsBroken()); if (dwarf.Energy > 0 && instrument != null) { while (present.EnergyRequired > 0 && dwarf.Energy > 0 && instrument != null && !instrument.IsBroken()) { present.GetCrafted(); dwarf.Work(); instrument.Use(); if (instrument.IsBroken()) { instrument = dwarf.Instruments.FirstOrDefault(i => !i.IsBroken()); } } } }
public void Craft(IPresent present, IDwarf dwarf) { var currentInstrument = dwarf.Instruments.FirstOrDefault(x => x.Power > 0); while (dwarf.Energy > 0 && dwarf.Instruments.Any(x => x.Power > 0)) { dwarf.Work(); currentInstrument.Use(); present.GetCrafted(); if (currentInstrument.IsBroken()) { currentInstrument = dwarf.Instruments.FirstOrDefault(x => x.Power > 0); } if (present.IsDone()) { break; } } }
public void Craft(IPresent present, IDwarf dwarf) { while (dwarf.Energy > 0 && dwarf.Instruments.Count != 0) { IInstrument currentInstrument = dwarf.Instruments.First(i => !i.IsBroken()); while (dwarf.Energy > 0 && currentInstrument.IsBroken() == false && present.IsDone() == false) { dwarf.Work(); present.GetCrafted(); currentInstrument.Use(); } if (currentInstrument.IsBroken()) { dwarf.Instruments.Remove(currentInstrument); } if (present.IsDone()) { break; } } }
public void Craft(IPresent present, IDwarf dwarf) { while (dwarf.Energy > 0 && dwarf.Instruments.Any()) { IInstrument currInstrument = dwarf.Instruments.First(); while (!present.IsDone() && dwarf.Energy > 0 && !currInstrument.IsBroken()) { dwarf.Work(); present.GetCrafted(); currInstrument.Use(); } if (currInstrument.IsBroken()) { dwarf.Instruments.Remove(currInstrument); } if (present.IsDone()) { break; } } //public void Craft(IPresent present, IDwarf dwarf) //{ // var currInstrument = dwarf.Instruments.FirstOrDefault(i => !(i.IsBroken())); // if (dwarf.Energy > 0 && currInstrument != null) // { // dwarf.Work(); // present.GetCrafted(); // currInstrument.Use(); // } // if (!present.IsDone() && dwarf.Energy > 0 && dwarf.Instruments.Any()) // { // this.Craft(present, dwarf); // } //} }
public void Craft(IPresent present, IDwarf dwarf) { if (dwarf.Instruments.Count == 0 || dwarf.Energy == 0) { return; } while (true) { present.GetCrafted(); dwarf.Work(); var instrument = dwarf.Instruments.FirstOrDefault(); instrument.Use(); if (present.IsDone()) { break; } if (dwarf.Energy == 0) { break; } if (instrument.IsBroken()) { dwarf.Instruments.Remove(instrument); instrument = dwarf.Instruments.FirstOrDefault(); if (instrument == null) { break; } } } }
public void Craft(IPresent present, IDwarf dwarf) { while (true) { if (dwarf.Energy > 0 && dwarf.Instruments.Any(i => !i.IsBroken())) { var instrument = dwarf.Instruments.FirstOrDefault(x => !x.IsBroken()); instrument.Use(); dwarf.Work(); present.GetCrafted(); if (present.IsDone()) { return; } } else { return; } } }
public void Craft(IPresent present, IDwarf dwarf) { foreach (var instrument in dwarf.Instruments) { while (!instrument.IsBroken()) { if (dwarf.Energy == 0) { break; } present.GetCrafted(); dwarf.Work(); instrument.Use(); if (present.IsDone()) { break; } } if (present.IsDone()) { break; } } }