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

            }

        }

    }

  • 相关阅读:
    jmeter-测试webservice接口
    Python
    Mysql:PDBC(Python操作数据库-mysql)
    Mysql: JDBC(Java 操作数据库-mysql)
    Mysql:事务、索引(了解)
    Mysql:DQL(Data Query Language
    Mysql:DML(Data Manipulation Language- 数据操作语言)
    Mysql:列类型,表类型,常用字段属性
    Mysql:DDL(Data Definition Language-数据定义语言)
    Mysql:Centos7安装Mysql5.6
  • 原文地址:https://www.cnblogs.com/gyt-xtt/p/3639057.html
Copyright © 2011-2022 走看看