} // Adam and Eve public Human(Human mother, Human father) { NumberOfPeopleAlive += 1; PersonNumber = GeneratePersonNumber(Birthdate); Friends = new List<Human>(); Father = father; Mother = mother; Children = new List<Human>(); Parents = new List<Human>(); }
public Human MakeBabyWithAnotherAdult(Human partner) { Human baby = null; if (this.Sex != partner.Sex) { baby = this.Sex == Sex.Female ? new Human(this, partner) : new Human(partner, this); } //Children.Add(baby); //partner.Children.Add(baby); return baby; }
public bool MarryAnotherAdult(Human partner) { if (this.Age > 18 && partner.Age > 18) { if (CheckIfConsious() && partner.CheckIfConsious()) { if (Partner == null && partner.Partner == null) { if (this != partner) { if (CheckIfRelatives(partner)) { _partner = partner; partner._partner = this; return true; } Console.WriteLine("Too related!!!"); } else Console.WriteLine($"{FirstName} can't marry themselves."); } else Console.WriteLine( $"Both parties ({FirstName} and {partner.FirstName}) must not be married no someone else."); } else Console.WriteLine( $"Both parties ({FirstName} and {partner.FirstName}) must both be consious."); } else Console.WriteLine( $"Both parties ({FirstName} and {partner.FirstName}) must both be over 18."); return false; }
protected Human(string firstName, string lastName, Human mother, Human father) : this(mother, father) { FirstName = firstName; LastName = lastName; }
public bool CheckIfFamilyTiesAreOkForMarriage(Human partner) { if (!(this.Mother == Partner.Mother && this.Father == partner.Father)) { if (!(this.Mother == partner || this.Father == partner)) return true; } return false; }
public bool CheckIfRelatives2(Human partner) { Human mother = Mother; Human father = Father; while (partner != father) { if (father.Children.Any(child => partner == child)) return false; if (father.Father == null) return true; father = father.Father; while (partner != mother) { if (mother.Children.Any(child => partner == child)) return false; if (mother.Father == null) return true; mother = mother.Mother; } } return false; }