namespace 面向对象的机器人
{
class Program
{
class 机器人
{
public string Name { get; set; }
private int full = 10;
public void SayHello()//说话
{
Console.WriteLine("你好我是{0}", this.Name);
//int xyz = Full;
//Full = 100;
}
public void Eat()//吃饭
{
Console.WriteLine("喂我多少呢?");
string fulllere = Console.ReadLine();
int fu=Convert .ToInt32 (fulllere );
if (fu> 20)
{
return;
}
else
{
full = full + fu;
}
Console.WriteLine(" 那就继续聊吧!");
shuohua();
}
public void shuohua()
{
if (full <= 0)
{
Console.WriteLine("不说了饿死了,喂我点吃的吧");
Eat();
}
string str = Console.ReadLine();
if (str.Contains("你") && str.Contains("名字") || str.Contains("姓名"))
{
SayHello();
}
else if (str.Contains("你好"))
{
Console.WriteLine("你也好");
}
else if (str.Contains("女朋友") && str.Contains("吗"))
{
Console.WriteLine("年龄太小,不考虑");
}
else if (str.Contains("你是") && str.Contains("狗") || str.Contains("猪") || str.Contains("鸡"))
{
Console.WriteLine("你才是呢请注意素质");
}
else if (str.Contains("88") || str.Contains("再见"))
{
Console.WriteLine("886");
}
else
{
Console.WriteLine("听不懂");
}
full--;
}
}
static void Main(string[] args)
{
机器人 j1 = new 机器人();
j1.Name = "小飞";
机器人 j2 = new 机器人();
j2.Name = "小雪";
机器人 r;
Console.WriteLine("请选择机器人1->小飞;2->小雪");
string xuanze = Console.ReadLine();
if (xuanze == "1")
{
r = j1;
}
else
{
r = j2;
}
r.SayHello();
while (true)
{
r.shuohua();
}
}
}
}
机器人
最新推荐文章于 2019-01-08 15:49:41 发布