Esempio n. 1
0
        public void AddCouple(string nationality, Couple couple)
        {
            if (Couples == null)
            {
                Couples = new Dictionary <string, List <Couple> >();
            }

            if (!Couples.ContainsKey(nationality))
            {
                Couples.Add(nationality, new List <Couple>());
            }

            Couples[nationality].Add(couple);
        }
Esempio n. 2
0
        // TODO only marry characters if they are inhabitants of the same city.
        private void MarryCharacters()
        {
            foreach (Continent continent in World.Continents)
            {
                foreach (KeyValuePair <string, List <Character> > nationalityCharacters in continent.LiveCharacters)
                {
                    string           nationality = nationalityCharacters.Key;
                    List <Character> characters  = nationalityCharacters.Value;

                    if (characters.Count > 1)
                    {
                        for (int attempt = 0; attempt < Configuration.MARRIAGE_ATTEMPTS_PER_YEAR; attempt++)
                        {
                            int index1 = theRandom.Next(1, characters.Count);
                            int index2 = theRandom.Next(1, characters.Count);

                            if (index1 != index2)
                            {
                                Character candidate1 = characters[index1];
                                Character candidate2 = characters[index2];

                                bool canMarry = CanCandidatesMarry(candidate1, candidate2);

                                if (canMarry)
                                {
                                    candidate1.MarryTo(candidate2);
                                    candidate2.MarryTo(candidate1);
                                    Couple couple;
                                    if (candidate1.Male)
                                    {
                                        couple = new Couple(candidate1, candidate2);
                                    }
                                    else
                                    {
                                        couple = new Couple(candidate2, candidate1);
                                    }
                                    continent.AddCouple(nationality, couple);
                                    TotalMarriages++;
                                    YearlyMarriages++;
                                }
                            }
                        }
                    }
                }
            }
        }