A console program that simulates robot conversations

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.