zoukankan      html  css  js  c++  java
  • 练习聊天程序员

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    //2014.3.13

    namespace 练习聊天机器人

    {

        class Program

        {

            static void Main(string[] args)

            {

                机器人 r1 = new 机器人();

                r1.Name = "T300";

                r1.Eat(6);

                机器人 r2 = new 机器人();

                r2.Name = "G500";

                r2.Eat(8);

                Console.WriteLine("请选择机器人,1-T300,2-G500");

                机器人 r;

                string s=Console.ReadLine();

                if (s == "1")

                {

                    r = r1;

                }

                else if (s == "2")

                {

                    r = r2;

                }

                else

                {

                    Console.WriteLine("输入错误");

                    Console.ReadKey();

                    return;

                }

                  r.SayHello();

                while (true)

                {

                    string str = Console.ReadLine();

                    r.Speak(str);

                }

            }

        }

        class 机器人

        {

            public string Name

            {

                get;

                set;

            }

            private int FullLevel//饥饿程度

            {

                get;

                set;

            }

            public void SayHello()

            {

                Console.WriteLine("我叫{0}",Name);

            }

            public void Eat(int foodCount)

            {

                if (FullLevel>100)

                {

                    return;

                }

                FullLevel = FullLevel + foodCount;

            }

            public void Speak(string str)

            {

                if (FullLevel <= 0)

                {

                    Console.WriteLine("饿死了,不说了");

                }

                else if (str.Contains("名字") || str.Contains("姓名"))

                {

                    this.SayHello();

                }

                else if (str.Contains("女朋友"))

                {

                    Console.WriteLine("年龄小,不考虑");

                }

                else

                {

                    Console.WriteLine("听不懂!");

                }

                FullLevel--;

            }

        }

    }

  • 相关阅读:
    2015年10月28日 json深切感受
    2015年10月27日 json数据小谈
    2015年10月26日 插件的使用
    2015/10/25 用bootstrap selectpicker实现带模糊查询的下拉列表
    2015年10月24号 哇,原来这JSP页面还可以用这东西!
    2015年10月23日 关于spring mvc的初认识
    2015年10月22日 杂感
    2015/10/21 http请求数据处理后显示
    2015/10/19总结:ajax传参、jquery.validate自定义日期校验
    记录一下----关于设计模式和面向对象设计原则
  • 原文地址:https://www.cnblogs.com/gyt-xtt/p/3639057.html
Copyright © 2011-2022 走看看