| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
namespace 机器人对话程序 
{ 
    class Program 
    { 
        static void Main(string[] args) 
        { 
 
            Console.WriteLine("*****************************"); 
            Console.WriteLine("     机器人对话程序开始      "); 
            Console.WriteLine("*****************************"); 
            Console.WriteLine("按Y或y开始程序!!按n或N退出程序!!"); 
            string choose = Console.ReadLine(); 
            if (choose == "n" || choose == "N") 
            { 
                return; 
            } 
            Console.WriteLine("开始执行程序!!!!!"); 
            Console.Clear(); 
             
            Console.WriteLine("请输入机器人的代号:1或是2"); 
            int id; 
            try 
            { 
                string ID = Console.ReadLine(); 
                id = Convert.ToInt32(ID); 
            } 
            catch 
            { 
                Console.WriteLine("输入错误,请重新输入!!"); 
                return; 
            } 
            Console.Clear(); 
            robotName a1 = new robotName(); 
            switch (id) 
            { 
                case 1: 
                    { 
                        Console.WriteLine("您选择的为第一个机器人\n属性:\n性别:男  年龄:21  身高:175cm  爱好:聊天、数学、文学、篮球。"); 
                        break; 
                    } 
                case 2: { Console.WriteLine("您选择的为第二个机器人\n属性:\n性别:女  年龄:19  身高:168cm  爱好:聊天、看小说、韩剧、购物。"); break; } 
                     
            } 
            Console.WriteLine("是否要修改机器人的名字,是的话按y或Y,否则按n或N"); 
            string choose2 = Console.ReadLine(); 
            if (choose2 == "y" || choose2 == "Y") 
            { 
                Console.Write("请输入名字:"); 
                if (id == 1) a1.Name1 = Console.ReadLine(); 
                if (id == 2) a1.Name2 = Console.ReadLine(); 
            } 
            string namerobot=""; 
            switch (id) 
            { 
                case 1:namerobot=a1.Name1;break; 
                case 2: namerobot = a1.Name2; break; 
            } 
            Console.WriteLine("开始和机器人{0}聊天",namerobot); 
            robot ROBOT = new robot(); 
            ROBOT.Eat=10; 
            Console.Clear(); 
            Console.WriteLine("请输入想问的问题:"); 
 
            while (true) 
            { 
                    Console.Write("我:"); 
                string str1 = Console.ReadLine(); 
                
                            Console.Write(namerobot+":"); 
               // Console.WriteLine("{0}:", namerobot);这种表达式也行。 
                if (str1.Contains("姓名")) 
                { 
                    Console.WriteLine("{0}。", namerobot); 
                
                } 
                if (str1.Contains("恋爱")) 
                { 
                    Console.WriteLine("你多少岁了"); 
                    string str2 = Console.ReadLine(); 
                    if (Convert.ToInt32(str2) > 20) 
                    { 
                        Console.WriteLine("甜蜜的事"); 
                    } 
                    else Console.WriteLine("少儿不宜!!"); 
                } 
                else Console.WriteLine("听不懂"); 
                ROBOT.Eat--; 
                while (ROBOT.Eat < 0) 
                { Console.WriteLine("饿死了!!!主人不给啊!!"); 
                Console.WriteLine("即将退出程序!"); 
                    return; } 
                Console.WriteLine("还剩" + ROBOT.Eat + "点食物!"); 
                ROBOT.xunwen(); 
            } 
            
        } 
        class robotName//名字 
        { 
            public string Name1 = "机器猫"; 
            public string Name2 = "叮当猫"; 
            public string this[int index] 
            { 
                set 
                { 
                    if (index == 1) 
                    { 
                        Name1 = value; 
                    } 
                    if (index == 2) 
                    { 
                        Name2 = value; 
                    } 
                } 
                get 
                { 
                    if (index == 1) 
                        return Name1; 
                    if (index == 2) 
                        return Name2; 
                    else throw new Exception("输入的数字错误,请输入1或2!"); 
                } 
 
            } 
        } 
           class robot//喂食 
           {public int Eat{set;get;} 
          
            
               public void xunwen() 
               { 
                   Console.WriteLine("是否喂食??是的话请按y或Y"); 
                   if (Console.ReadLine()=="y"||Console.ReadLine()=="Y") 
                   { 
                       Random p = new Random(); 
                       int t = p.Next(3,10); 
                       if (t > 5) Console.WriteLine("踩到狗屎了,你得到食物{0}点", t); 
                       Eat = Eat + t; 
                   } 
               } 
                    } 
        } 
 |   
 
评分
- 
查看全部评分
 
 
 
 
 
 |