C#简易聊天机器人(控制台程序)

来源:互联网 发布:虚拟数据库 编辑:程序博客网 时间:2024/04/30 14:27
/*作 者:清风小陈     完成日期: 2017 年 03 月 23 日     */using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{    class Program    {        static void Main(string[] args)        {            机器人 r1 = new 机器人();            r1.Name = "小陈";            r1.Ful_level = 10;            r1.SayHello();            while (true)            {                string str = Console.ReadLine();                r1.Speak(str);            }        }    }    class 机器人    {        public string Name;        public int Ful_level;        public void SayHello()        {            Console.WriteLine("你好,我叫{0},很高兴认识你!", Name);        }        public void Speak(String str)        {                        if (Ful_level > 10)            {                Console.WriteLine("撑死了,不吃了"); Ful_level--;                            }              else if (str.Contains("吃"))            {                Ful_level++;                if (Ful_level > 10)                {                    Console.WriteLine("撑死了,不吃了"); Ful_level--;                }            }               else if (Ful_level == 0)            {                Console.WriteLine("饿死了,不说了");                          }            else if ( str.Contains("名字"))            {                this.SayHello(); Ful_level--;            }            else if (str.Contains("女朋友"))            {                Console.WriteLine("年龄小,不考虑"); Ful_level--;            }              else if (str.Contains(""))              {                  Console.WriteLine("说话啊"); Ful_level--;              }              else              {                  Console.WriteLine("听不懂"); Ful_level--;              }         }        }    }

0 0
原创粉丝点击