Exemplo n.º 1
0
        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;
                }
            }
        }
Exemplo n.º 2
0
        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();
            }
        }
Exemplo n.º 3
0
        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;
                }

            }
        }
Exemplo n.º 4
0
        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;
                }
            }
        }
Exemplo n.º 5
0
 public void Craft(IPresent present, IDwarf dwarf)
 {
     while (!present.IsDone() && dwarf.Instruments.Any(x => !x.IsBroken()))
     {
         present.GetCrafted();
         dwarf.Instruments.FirstOrDefault(x => x.IsBroken() == false).Use();
     }
 }
Exemplo n.º 6
0
 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();
     }
 }
Exemplo n.º 7
0
 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();
     }
 }
Exemplo n.º 8
0
        //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();
                }
            }
        }
Exemplo n.º 9
0
 public void Craft(IPresent present, IDwarf dwarf)
 {
     while (true)
     {
         dwarf.Work();
         present.GetCrafted();
         if (present.IsDone)
         {
             break;
         }
     }
 }
Exemplo n.º 10
0
 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();
                }
            }
        }
Exemplo n.º 12
0
 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;
         }
     }
 }
Exemplo n.º 13
0
        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);
                }
            }
        }
Exemplo n.º 15
0
        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());
                    }
                }
            }
        }
Exemplo n.º 16
0
        //public IReadOnlyCollection<IInstrument> BrokenInstruments => brokenInstruments.AsReadOnly();
        //private readonly List<IInstrument> brokenInstruments;
        public void Craft(IPresent present, IDwarf dwarf)
        {
            while (dwarf.Energy > 0 || present.EnergyRequired > 0)
            {
                //var notBrokenInstruments = dwarf.Instruments.Where(x => x.IsBroken() == false);
                var currentInstrument = dwarf.Instruments.FirstOrDefault(x => x.IsBroken() == false);

                if (currentInstrument == null)
                {
                    break;
                }
                present.GetCrafted();
                currentInstrument.Use();
                //if (currentInstrument.IsBroken())
                //{
                //    brokenInstruments.Add(currentInstrument);
                //}
            }
        }
Exemplo n.º 17
0
        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());
                    }
                }
            }
        }
Exemplo n.º 18
0
        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;
                }
            }
        }
Exemplo n.º 19
0
 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;
         }
     }
 }
Exemplo n.º 20
0
        public string CraftPresent(string presentName)
        {
            var readyToWorkdwarfs = new List <IDwarf>();

            foreach (var dwarf in dwarfs.Models)
            {
                if (dwarf.Energy >= 50 && dwarf.Instruments.Any(x => x.IsBroken() == false))
                {
                    readyToWorkdwarfs.Add(dwarf);
                }
            }
            if (readyToWorkdwarfs == null)
            {
                throw new InvalidOperationException(ExceptionMessages.DwarfsNotReady);
            }
            present = presents.FindByName(presentName);
            foreach (var currentDwarf in readyToWorkdwarfs)
            {
                //readyToWorkdwarfs = dwarfs.Models.Where(x => x.Energy >= 50);
                currentDwarf.Work();
                var currentInstrument = currentDwarf.Instruments.FirstOrDefault(x => x.IsBroken() == false);
                //currentInstrument.Use();
                if (currentInstrument.IsBroken())
                {
                    brokenOnes++;
                }
                present.GetCrafted();
                workshop.Craft(present, currentDwarf);
                if (currentDwarf.Energy == 0)
                {
                    dwarfs.Remove(currentDwarf);
                }
                if (present.IsDone())
                {
                    countCraftedPresents++;
                    return(string.Format(OutputMessages.PresentIsDone, presentName));
                }
            }
            return(string.Format(OutputMessages.PresentIsNotDone, presentName));
        }
Exemplo n.º 21
0
        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);
            //    }
            //}
        }
Exemplo n.º 22
0
        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;
                    }
                }
            }
        }
Exemplo n.º 23
0
        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;
                }
            }
        }
Exemplo n.º 24
0
 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;
         }
     }
 }