Esempio n. 1
0
 void GetSickInLightForm()
 {
     if (HeavyForm)
     {
         throw new DiseaseException("Already sick in heavyform!");
     }
     else
     {
         LightForm    = true;
         CurrentState = DiseaseForm.Light;
     }
 }
Esempio n. 2
0
 void GetSickInHeavyForm()
 {
     if (LightForm)
     {
         throw new DiseaseException("Already sick in lightform!");
     }
     else
     {
         HeavyForm    = true;
         CurrentState = DiseaseForm.Heavy;
     }
 }
Esempio n. 3
0
 public void GetWellForOneLevel()
 {
     if (HeavyForm)
     {
         HeavyForm    = false;
         LightForm    = true;
         CurrentState = DiseaseForm.Light;
     }
     else if (LightForm)
     {
         LightForm    = false;
         CurrentState = DiseaseForm.Healthy;
     }
     else
     {
         throw new DiseaseException("Already healthy!");
     }
 }
Esempio n. 4
0
 public Human()
 {
     CurrentState = DiseaseForm.Healthy;
     LightForm    = false;
     HeavyForm    = false;
 }
Esempio n. 5
0
        void ChangePeopleState(ref List <Human> wellPeople, ref List <Human> sickPeople, int count, DiseaseForm form, bool allSick = false)
        {
            var r = new Random();

            if (form != DiseaseForm.Healthy)
            {
                count += sickPeople.Count;

                while (sickPeople.Count != count && wellPeople.Count != 0)
                {
                    int index = r.Next(wellPeople.Count);

                    if (wellPeople[index].CurrentState == DiseaseForm.Healthy)
                    {
                        wellPeople[index].GetSickerForOneLevel();
                        if (wellPeople[index].CurrentState != form)
                        {
                            wellPeople[index].GetSickerForOneLevel();
                        }

                        sickPeople.Add(wellPeople[index]);

                        wellPeople.RemoveAt(index);
                    }
                    else if (allSick)
                    {
                        if (form == DiseaseForm.Heavy)
                        {
                            wellPeople[index].GetSickerForOneLevel();

                            sickPeople.Add(wellPeople[index]);

                            wellPeople.RemoveAt(index);
                        }
                        else
                        {
                            wellPeople[index].GetWellForOneLevel();

                            sickPeople.Add(wellPeople[index]);

                            wellPeople.RemoveAt(index);
                        }
                    }
                }
            }
            else
            {
                count += wellPeople.Count;

                while (wellPeople.Count != count && sickPeople.Count != 0)
                {
                    int index = r.Next(sickPeople.Count);

                    sickPeople[index].GetWellForOneLevel();
                    if (sickPeople[index].CurrentState != form)
                    {
                        sickPeople[index].GetWellForOneLevel();
                    }

                    wellPeople.Add(sickPeople[index]);

                    sickPeople.RemoveAt(index);
                }
            }
        }