面向对象的聊天机器人

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 聊天机器人_面向对象
{
    class Program
    {
        static void Main(string[] args)
        {
            person p = new person();
            p.Name = "bobi";
            p.Eat(5);
            p.live = true;
            p.SayHello ();

            while (true)
            {
                string str = Console.ReadLine();
                p.Speak(str);
                if (p.live ==false)
                {
                    Console.WriteLine("机器人停止聊天。。");
                    Console.ReadKey();
                    return;
                }
            }
            
        }
    }


    class person
    {
        public string Name { get; set; }

        public int Age{get;set;}

        public int FullLevel { get; set; }//饥饿度

        public bool live { get; set; }//判断机器人是否死亡

        public void SayHello()
        {
            Console.WriteLine("你好~~我是机器人:{0},", Name);
        }

        public void Eat(int foodCount)
        {
            if (FullLevel > 100)
            {
                Console.WriteLine("吃的撑死了,886");
                this.live = false;
                return;
            }
            FullLevel = FullLevel + foodCount;
        }

        public void Speak(string str)
        {
            if (FullLevel <= 0)
            {
                Console.WriteLine("我饿了,不说了。喂我吃点东西吧~~(请输入数字)");
                string food = Console.ReadLine();
                try
                {
                    int Intfood = Convert.ToInt32(food);
                    if (Intfood < 0)
                    {
                        Console.WriteLine("你耍我呀。。我不跟你说话了。。");
                        this.live = false ;
                        return;
                    }
                    this.Eat(Intfood);
                    Console.WriteLine("我吃了{0}个香蕉,饱了,又可以聊天了。", Intfood);
                    return;
                }
                catch
                {
                    Console.WriteLine("你喂我吃的都不是食物@@,我恨你@@");
                    this.live = false;
                    return;
                }
                
            }
            if(str.Contains ("姓名")||str.Contains ("名字"))
            {
                this .SayHello();
            }
            else if (str.Contains("女朋友"))
            {
                Console.WriteLine("年级太小,没有女朋友");
            }
            else if (str.Contains("几岁") || str.Contains("年龄"))
            {
                Console.WriteLine("我今年{0}岁了。", this.Age);
            }
            else if (str.Contains("天气"))
            {
                Console.WriteLine("今天天气很好,适合郊游!!");
            }
            else if (str.Contains("心情"))
            {
                Console.WriteLine("今天心情很好,我们来玩星际吧!");
            }
            else if(str.Contains ("88")||str.Contains ("再见"))
            {
                Console.WriteLine("886");
                this.live = false;
            }
            else
            {
                Console.WriteLine("你火星来的???听不懂你在说什么!@");
            }

            FullLevel--;
        }
    }
}

转载于:https://www.cnblogs.com/bobobibi/archive/2011/04/06/2007258.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值