private void InitСitizen() { sex = rnd.Next(0, 2); age = rnd.Next(0, 4320); isAlive = true; couple = null; weekWithoutChildrens = 0; calculateChildrenDateInThisWeek = false; work = null; mony = 0.0; }
private void UpdateCitizens() { // Прединициализация параметров на итерацию foreach (Сitizen citizen in citizens) { citizen.SetCalculateChildrenDateInThisWeek(false); } // Основной UPDATE for (int i = 0; i < citizens.Count; i++) { ((Сitizen)citizens[i]).LiveWeek(citizens, products); } // Убираем трупы ArrayList boofer = new ArrayList(); for (int i = 0; i < citizens.Count; i++) { if (((Сitizen)citizens[i]).IsAlive() == false) { Сitizen couple = ((Сitizen)citizens[i]).GetCouple(); if (couple != null) { couple.SetCouple(null); } boofer.Add(citizens[i]); } } foreach (Object citizen in boofer) { citizens.Remove(citizen); } // Убираем израсходованные продукты ArrayList boofer1 = new ArrayList(); for (int i = 0; i < products.Count; i++) { if (((Product)products[i]).GetQuantity() <= 0.0) { boofer1.Add(products[i]); } } foreach (Object product in boofer1) { products.Remove(product); } }
public void LiveWeek(ArrayList citizens, ArrayList products) { if (!isAlive) { return; } age++; // Проверяем, не погиб ли житель if ((age >= 2880) & (age <= 4320)) { int deth = rnd.Next(0, 6); if ((deth > 2) || (age == 4320)) { isAlive = false; return; } } // Пытаемся покушать =) int countEat = rnd.Next(21, 57);// Кол-во еды которое съедим за неделю // Пытаемся получить еду for (int i = 0; i < products.Count; i++) { if (((Product)products[i]).GetTypeProduct() == 0) { int quProduct = ((Product)products[i]).GetQuantity(); int bayPr = countEat; if (quProduct < countEat) { bayPr = quProduct; } if ((bayPr * ((Product)products[i]).GetCost()) <= mony) // Если хватает денег { countEat -= bayPr; mony -= ((Product)products[i]).BayProduct(bayPr); if (countEat == 0) { break; } } } } // Мало еды if (countEat > 0) { isAlive = false; return; } //^ Пытаемся покушать =) // Пытаемся создать семью // Если в возрастном диапазоне, то ищем пару if ((age >= 720) & (age <= 1680) & (couple == null)) { foreach (Сitizen citizen in citizens) { if ((citizen.GetAge() >= 720) & (citizen.GetAge() <= 1680) & (citizen.GetCouple() == null) & (this != citizen)) { couple = citizen; weekWithoutChildrens = 0; citizen.SetCouple(this); citizen.SetWeekWithoutChildrens(0); break; } } } // Добавляем неделю паре сколько не рожали if (couple != null) { if ((calculateChildrenDateInThisWeek == false) & (couple.IsAlive())) { weekWithoutChildrens++; calculateChildrenDateInThisWeek = true; couple.SetWeekWithoutChildrens(weekWithoutChildrens); couple.SetCalculateChildrenDateInThisWeek(true); } } // Пытаемся выдать потомство, if (couple != null) { if ((couple.IsAlive()) & (weekWithoutChildrens >= 48) & (weekWithoutChildrens <= 240)) { int child = rnd.Next(0, 6); if ((child > 2) || (weekWithoutChildrens == 240)) { weekWithoutChildrens = 0; calculateChildrenDateInThisWeek = true; couple.SetWeekWithoutChildrens(0); couple.SetCalculateChildrenDateInThisWeek(true); citizens.Add(new Сitizen(rnd, true)); } } } }
public void SetCouple(Сitizen couple) { this.couple = couple; }