public static void Engage(Villager woman, Villager man) { if (woman.Gender == man.Gender) { throw new InvalidOperationException("these villagers have the same gender"); } Debug.Assert(woman.StatusInFamily == Status.SINGLE, "the woman is not single"); Debug.Assert(man.StatusInFamily == Status.SINGLE, "the man is not single"); woman.SetFiance(man); man.SetFiance(woman); woman.StatusInFamily = Status.ENGAGED; man.StatusInFamily = Status.ENGAGED; }
public void Engage(Villager villager) { if(villager.Gender == _gender) { throw new InvalidOperationException("these villagers have the same gender"); } if (villager.StatusInFamily != Status.SINGLE || _statusInFamily.Current != Status.SINGLE) { throw new InvalidOperationException("villager is not single(Engage)"); } SetFiance(villager); villager.SetFiance(this); _statusInFamily.Current = Status.ENGAGED; villager.StatusInFamily = Status.ENGAGED; Villager man; if(_gender==Genders.MALE){man=this;} else{man=villager;} if (Game.SingleMen.Contains(man)) { Game.RemoveSingleMan(man); } }