public City(int column, int row, int citizens, int police, int thieves) { TheCity = new char[row, column]; for (row = 0; row <= TheCity.GetUpperBound(0); row++) { for (column = 0; column <= TheCity.GetUpperBound(1); column++) { TheCity[row, column] = ' '; } } Person person; for (int i = 1; i <= citizens; i++) { person = new Citizen(this, ThePersonList, false); ThePersonList.Add(person); } for (int i = 1; i <= police; i++) { person = new Police(this, ThePersonList); ThePersonList.Add(person); } for (int i = 1; i <= thieves; i++) { person = new Thief(this, ThePersonList); ThePersonList.Add(person); } PlacePersons(); }
public void MovePersons() { foreach (Person person in ThePersonList) { (int column, int row) = person.GetPosition(); TheCity[row, column] = ' '; person.NewPosition(TheCity, false); } List <List <Person> > maybeCollidedPersonsLists = new List <List <Person> >(); List <Person> maybeCollidedPersons = new List <Person>(); while (ThePersonList.Count > 1) { maybeCollidedPersons = ThePersonList.FindAll(x => x.GetPosition() == ThePersonList[0].GetPosition()); ThePersonList.RemoveAll(x => x.GetPosition() == maybeCollidedPersons[0].GetPosition()); maybeCollidedPersonsLists.Add(maybeCollidedPersons); } PersonInteractions(maybeCollidedPersonsLists); List <Person> reversedPersons = new List <Person>(); foreach (List <Person> personList in maybeCollidedPersonsLists) { if (personList.Count > 1) { foreach (Person person in personList) { person.NewPosition(TheCity, true); reversedPersons.Add(person); } } else { ThePersonList.Add(personList[0]); } } maybeCollidedPersonsLists.Clear(); maybeCollidedPersons.Clear(); List <Person> collidedPersons = new List <Person>(); while (true) { foreach (Person person in reversedPersons) { Person collidedPerson = ThePersonList.Find(x => x.GetPosition() == person.GetPosition()); if (collidedPerson != null) { collidedPerson.NewPosition(TheCity, true); collidedPersons.Add(collidedPerson); ThePersonList.Remove(collidedPerson); } } ThePersonList.AddRange(reversedPersons); reversedPersons.Clear(); if (collidedPersons.Count == 0) { break; } else { reversedPersons.AddRange(collidedPersons); collidedPersons.Clear(); } } PlacePersons(); }