15-07-06 小游戏-看名字测缘分

while (true)
            {
                Console.WriteLine("请输入你的姓名:");
                string name1 = Console.ReadLine();

                int seed1 = 0;
                if (name1.Length == 2)    //名字为两个字
                {
                    seed1 = (int)Convert.ToChar(name1.Substring(0, 1)) + (int)Convert.ToChar(name1.Substring(1, 1));
                }
                else    //名字为三个字
                {
                    seed1 = (int)Convert.ToChar(name1.Substring(0, 1)) + (int)Convert.ToChar(name1.Substring(1, 1)) + (int)Convert.ToChar(name1.Substring(2, 1));
                }

                Random rand1 = new Random(seed1);
                int yf1 = rand1.Next(10);    //随机生成一个10以内的数字

                Console.WriteLine("请输入你的姓名:");
                string name2 = Console.ReadLine();

                int seed2 = 0;
                if (name2.Length == 2)    
                {
                    seed2 = (int)Convert.ToChar(name2.Substring(0, 1)) + (int)Convert.ToChar(name2.Substring(1, 1));
                }
                else    
                {
                    seed2 = (int)Convert.ToChar(name2.Substring(0, 1)) + (int)Convert.ToChar(name2.Substring(1, 1)) + (int)Convert.ToChar(name2.Substring(2, 1));
                }
                Random rand2 = new Random(seed2);
                int yf2 = rand2.Next(10);

                if (Math.Abs(yf1 - yf2)>=4)
                {
                    Console.WriteLine("你们很有缘分,好好珍惜吧!");
                }
                else
                {
                    Console.WriteLine("看来你们情深缘浅,好自为之吧");
                }


          }

 

posted @ 2015-07-07 22:53  嘿,我在!  阅读(195)  评论(0编辑  收藏  举报