using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Text.RegularExpressions;using System.Threading.Tasks;namespace RobotTest{ class Program { static void Main(string[] args) { 机器人 robot = new 机器人(); robot.Name = "小艾"; robot.Eat(5); robot.SayHello(); while(true) { string qu = Console.ReadLine(); robot.Speak(qu); } Console.ReadKey(); } } class 机器人 { public string Name { get; set; } private int FullLeve { get; set; } public void SayHello() { Console.WriteLine("您好,我是{0}",this.Name); } public void Eat(int foods) { if (FullLeve > 100 ) { Console.WriteLine("撑死了,不能吃了!"); return; } FullLeve += foods; } int num = 0; public void Speak(string Question) { if (FullLeve <= 0) { if (num == 0) { Console.WriteLine("饿死了,赶紧为我点吃的吧,我只能吃数字^-^"); num ++;return; } // var Cusfood = Console.ReadLine(); int number = 0; if (!int.TryParse(Question, out number) || Question.IndexOf("-") >= 0) { Console.WriteLine("不带这么玩的,喂我点能吃的东西行吗,亲"); num++; return; } else { FullLeve += Convert.ToInt32(Question); Console.WriteLine("谢谢亲,我吃饱了!可以继续愉快的玩耍了!"); return; } } if (Question.Contains("姓名") || Question.Contains("名字")) { this.SayHello(); } else if (Question.Contains("女朋友")) { Console.WriteLine("年龄小,不考虑!"); } else { Console.WriteLine("听不懂!"); } FullLeve--; } public bool ValidateNum(string no) { Regex rg = new Regex("^\\d+$"); return true; // Match mt = rg.Matches(no); } }}