• 练习聊天程序员


    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--;

            }

        }

    }

  • 相关阅读:
    osg模型部分节点旋转
    IFC数据模型构件控制
    自定义基于IFC数据的施工进度数据结构
    QDateTime QString
    Qt获取屏幕分辨率
    Qt自定义类重写 copy
    removeEntry
    initGanttView
    IfcAxis2Placement3D IFC构件的位置和方向
    致我最爱的你
  • 原文地址:https://www.cnblogs.com/gyt-xtt/p/3639057.html
Copyright © 2020-2023  润新知