Пример #1
0
        static void Main()
        {
            if (DateTime.Now.DayOfWeek == DayOfWeek.Monday)
            {
                Environment.Exit(0);
            }

            StreamReader  streamReader = new StreamReader("D:\\STUDY\\C4\\NET\\L6\\L6\\men.txt");
            string        menline      = "";
            List <string> menlist      = new List <string>();

            while (menline != null)
            {
                menline = streamReader.ReadLine();
                if (menline != null)
                {
                    menlist.Add(menline);
                }
            }
            streamReader.Close();

            streamReader = new StreamReader("D:\\STUDY\\C4\\NET\\L6\\L6\\women.txt");
            string        womenline = "";
            List <string> womenlist = new List <string>();

            while (womenline != null)
            {
                womenline = streamReader.ReadLine();
                if (womenline != null)
                {
                    womenlist.Add(womenline);
                }
            }
            streamReader.Close();

            List <string> WomenClasses = new List <string>();

            WomenClasses.Add("Girl");
            WomenClasses.Add("SmartGirl");
            WomenClasses.Add("PrettyGirl");


            List <string> MenClasses = new List <string>();

            MenClasses.Add("Student");
            MenClasses.Add("Botan");

            foreach (string strMan in menlist)
            {
                foreach (string strWoman in womenlist)
                {
                    string[] strmanMas   = strMan.Split();
                    string[] strwomanMas = strWoman.Split();

                    Random rand    = new Random();
                    int    manRand = rand.Next(0, 2);

                    int womanRand = rand.Next(0, 3);


                    Type type = Type.GetType("L6." + MenClasses[manRand]);
                    var  Man  = Activator.CreateInstance(type);

                    System.Reflection.PropertyInfo propertyInfo;
                    type         = typeof(Human);
                    propertyInfo = type.GetProperty("Name");
                    propertyInfo.SetValue(Man, strmanMas[0]);

                    propertyInfo = type.GetProperty("Surname");
                    propertyInfo.SetValue(Man, strmanMas[1]);

                    propertyInfo = type.GetProperty("FathersName");
                    propertyInfo.SetValue(Man, strmanMas[2]);



                    type = Type.GetType("L6." + WomenClasses[womanRand]);
                    var Woman = Activator.CreateInstance(type);

                    type         = typeof(Human);
                    propertyInfo = type.GetProperty("Name");
                    propertyInfo.SetValue(Woman, strwomanMas[0]);

                    propertyInfo = type.GetProperty("Surname");
                    propertyInfo.SetValue(Woman, strwomanMas[1]);

                    propertyInfo = type.GetProperty("FathersName");
                    propertyInfo.SetValue(Woman, strwomanMas[2]);

                    Attraction attraction = Attraction.Couple((Human)Woman, (Human)Man);
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Woman: " + Woman.ToString());
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Man: " + Man.ToString());
                    Console.ForegroundColor = ConsoleColor.Blue

                    ;
                    Console.WriteLine(attraction.ToString() + "\n");
                    Console.BackgroundColor = ConsoleColor.Red;
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("Press Eny Button to continue (or Q|F10 to exit)\n");
                    ConsoleKey ckey = Console.ReadKey(true).Key;
                    if ((ckey == ConsoleKey.Q) || (ckey == ConsoleKey.F10))
                    {
                        Environment.Exit(0);
                    }
                    else
                    {
                        Console.ResetColor();
                        continue;
                    }
                }
            }
        }
Пример #2
0
        public static Attraction Couple(Human human1, Human human2)
        {
            Attraction attraction = new Attraction();
            string     child      = "";

            bool human1like = false;
            bool human2like = false;

            foreach (CoupleAttribute h1 in human1.CoupleTo())
            {
                foreach (CoupleAttribute h2 in human2.CoupleTo())
                {
                    if ((h1.Pair == human2.GetType().Name) && (h2.Pair == human1.GetType().Name))
                    {
                        if (h1.Probability >= 0.5)
                        {
                            human1like = true;
                            child      = h1.ChildType;
                        }

                        if (h2.Probability >= 0.5)
                        {
                            human2like = true;
                        }
                    }
                }
            }

            SortedSet <string> bookSet = new SortedSet <string>();

            bookSet.Add("Botan");
            bookSet.Add("SmartGirl");

            if (bookSet.Contains(human1.GetType().Name) && (bookSet.Contains(human2.GetType().Name)))
            {
                attraction.Name = "Book";
                attraction.Type = "Book";
                attraction.Like = false;

                return(attraction);
            }
            else
            {
                if ((human1like == true) && (human2like == true))
                {
                    System.Reflection.PropertyInfo propertyInfo;
                    Type type = typeof(Human);
                    propertyInfo = type.GetProperty("Name");
                    string name = (string)propertyInfo.GetValue(human2);

                    string ChildType = child;
                    type = System.Type.GetType("L6." + ChildType);
                    var obj = Activator.CreateInstance(type);


                    string GirlName = (string)propertyInfo.GetValue(human1);
                    propertyInfo = type.GetProperty("Name");
                    propertyInfo.SetValue(obj, GirlName);

                    SortedSet <string> male = new SortedSet <string>();
                    male.Add("Student");
                    male.Add("Botan");

                    string fathersName = "";
                    if (male.Contains(ChildType))
                    {
                        if (name[name.Length - 1] == 'o')
                        {
                            fathersName = name + "вич";
                        }
                        else
                        {
                            fathersName = name + "ович";
                        }
                    }


                    propertyInfo = type.GetProperty("Surname");
                    string fathersSurname = (string)propertyInfo.GetValue(human2);


                    if (!male.Contains(ChildType))
                    {
                        if (fathersSurname.Contains("ий"))
                        {
                            fathersSurname = fathersSurname.Remove(fathersSurname.Length - 2);
                            fathersSurname = fathersSurname + "a";
                        }
                    }

                    propertyInfo = type.GetProperty("Surname");
                    propertyInfo.SetValue(obj, fathersSurname);

                    propertyInfo = type.GetProperty("FathersName");
                    propertyInfo.SetValue(obj, fathersName);

                    attraction.Name = GirlName;
                    attraction.Type = ChildType;
                    attraction.Like = true;
                    return(attraction);
                }
                else
                {
                    child           = "";
                    attraction.Name = "Empty";
                    attraction.Type = "Empty";
                    attraction.Like = false;
                    return(attraction);
                }
            }
        }