usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Text.RegularExpressions;usingSystem.Threading.Tasks;namespacerobottest{classProgram {Static voidMain (string[] args) {Robot Robot=Newrobot (); Robot. Name="Little Ai"; Robot. Eat (5); Robot. SayHello (); while(true) { stringsub=Console.ReadLine (); Robot. Speak (QU); } console.readkey (); } } classRobot { Public stringName {Get;Set; } Private intFullleve {Get;Set; } Public voidSayHello () {Console.WriteLine ("Hello, I am {0}", This. Name); } Public voidEat (intFoods) { if(Fullleve > -) {Console.WriteLine ("I can't eat it! "); return; } Fullleve+=Foods; } intnum =0; Public voidSpeak (stringQuestion) { if(Fullleve <=0) { if(num = =0) {Console.WriteLine ("starve, hurry for me to eat, I can only eat the numbers ^-^"); num + +;return; } //var cusfood = Console.ReadLine (); intNumber =0; if(!int. TryParse (Question, outNumber) | | Question.indexof ("-") >=0) {Console.WriteLine ("I don't want to play this game, feed me something to eat, okay?"); Num++; return; } Else{Fullleve+=Convert.ToInt32 (Question); Console.WriteLine ("thanks a kiss, I'm full! Can continue to play happily! "); return; } } if(Question.contains ("name") || Question.contains ("name")) { This. SayHello (); } Else if(Question.contains ("girlfriend") {Console.WriteLine ("age is small, do not consider! "); } Else{Console.WriteLine ("I don't understand! "); } Fullleve--; } Public BOOLValidatenum (stringNO) {Regex RG=NewRegex ("^\\d+$");return true; //Match MT = RG. Matches (no); } }}
A console program that simulates robot conversations