private void Form1_Load(object sender, EventArgs e) { // Заполнение массива Lisboxов for (int i = 2; i < 22; i++) { string str = "listBox" + i; Panel a = this.Controls["panel1"] as Panel; ListBox lb = a.Controls["listBox" + i] as ListBox; lb.Items.Clear(); displays.Add(lb); } listBox1.Items.Add("Creation Started"); // Создание живонтых в зоопарке for (int i = 0; i < displays.Count; i++) { int q = new Random().Next(4); Builder builder = new MammalCreatureBuilder(); // Начало создания животных if (q == 0) { builder = new MammalCreatureBuilder(); //Билдер } if (q == 1) { builder = new BirdCreatureBuilder(); //Билдер } if (q == 2) { builder = new FishCreatureBuilder(); //Билдер } if (q == 3) { builder = new ReptileCreatureBuilder(); //Билдер } Director director = new Director(builder); // Директор director.ConstructRandomCreature(); Creature crt = builder.GetCreature(); // Добавление наблюдателей crt.Attach(new FoodObserver(crt, new Worker())); crt.Attach(new HealthObserver(crt, doctor)); Aviary a = new Aviary(crt, displays[i], i); aviaries.Add(a); a.GetInfo(); // Добавление наблюдателей a.Attach(new UpdateObserver(a)); a.Attach(new ControlTemperatureSystemObserver(a, new Worker())); a.Attach(new MessObserver(a, new Worker())); } listBox1.Items.Add("Creation Successful"); // Начало отсчета времени CurrentTime.Start(); timer1.Start(); }
// попытка почистить вольер public void TryToCleanAviary(Aviary host) { if (!host.state.CheckFields()[0]) { Random rng = new Random(); int a = rng.Next(5); if (a > 3) { host.state.RemoveProblem("Dirty"); host.state.UpdateState(true); } } }
// попытка починить системы обогрева вольера public void TryToRepair(Aviary host) { if (!host.state.CheckFields()[1]) { Random rng = new Random(); int a = rng.Next(5); if (a > 3) { host.state.RemoveProblem("Temperature"); host.state.UpdateState(true); } } }
public PerfectState(Aviary _aviary) : base(_aviary) { IsClear = true; IsTemperatureNormaliserWorking = true; }
public bool IsTemperatureNormaliserWorking; // Функционирование системы контроля температуры public AviaryState(Aviary _aviary) { aviary = _aviary; }
public ProblemState(Aviary _aviary, bool _isClear, bool _IsTemperatureNormaliserWorking) : base(_aviary) { IsClear = _isClear; IsTemperatureNormaliserWorking = _IsTemperatureNormaliserWorking; }
public MessObserver(Aviary _host, Worker a) { aviary = _host; aviary.Attach(this); worker = a; }
public ControlTemperatureSystemObserver(Aviary _host, Worker a) { aviary = _host; aviary.Attach(this); worker = a; }
public UpdateObserver(Aviary _host) { aviary = _host; aviary.Attach(this); }