3. C # object-oriented basic chatbot

Source: Internet
Author: User

You can add your own chatbot library based on the simple version of the console.

The source code is as follows:

Using system; using system. collections. generic; using system. text; namespace object-oriented chatbot 1.0 {class program {static void main (string [] ARGs) {robot R1 = new robot (); r1.name = "I "; r1.eat (5); r1.sayhello (); While (true) {string STR = console. readline (); r1.speak (STR) ;}} class robot {public string name {Get; set;} private int fullevel {Get; set ;} // you know the degree of hunger, so it should be set as a private property. Public void sayhello () // you can speak {console. writeline ("\ t [robot] Hello, my name is {0}. Glad to meet you! ", Name);} public void eat (INT foodcount) {If (fullevel> 100) {return;} fullevel = fullevel + foodcount;} public void speak (string Str) {If (fullevel <= 0) {console. writeline ("\ t [robot] starved to death. Don't ask. I won't say it! "); Return;} If (Str. contains ("name") | Str. contains ("name") | Str. contains ("who") | Str. contains ("hello") {This. sayhello (); // method of the class to call another method of the same type} else if (Str. contains ("girlfriend") {console. writeline ("\ t [robot] younger, not considered! ");} Else if (Str. Contains (" CREATE ") {console. writeline (" \ t [Robot description] is created by the nebula. ");} Else if (Str. contains ("Tease ratio") {console. writeline ("\ t [robot] You are a copeat. Your family is copeat! ");} Else if (Str. contains ("Haha") {console. writeline ("\ t [robot] ");} else if (Str. contains ("... ") {Console. writeline (" \ t [robot ].... ");} Else if (Str. Contains (" wipe ") {console. writeline (" \ t [robot] What do you want to wipe? ");} Else {console. writeline (" \ t [robot] does not understand! ") ;}Fullevel --;}}}

Run:

 

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.