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