一个初学者C#的过程记录

来源:互联网 发布:计算机软件编程 编辑:程序博客网 时间:2024/05/22 01:45

由于大学没有学习正规的编程,在毕业之后吃过各种苦头,如今开始重新学习编程。
加油哦,首先我先学习的是C#基础课程,也就是看的是各种视频,详细视频内容,我相信,自学者在百度中都可以搜到,这里我就不打广告了,因为这确实没有这种义务,也不想那么讨人厌。。。。。
这是我一个很不完美的一个小程序吧 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace 聊天机器人
{
    class Program
    {
        static void Main(string[] args)
        {
            Robort r1=new Robort();
            Console.WriteLine("你想跟谁说话,请写出他/她的名字");
            r1.Name=Console.ReadLine();
            int foodcount = 0;
            Console.WriteLine("请投入金币");


            do
            {
                try
                {
                    foodcount = Convert.ToInt32(Console.ReadLine());
                    r1.Eat(foodcount);
                    //r1.SayHello();
                }
                catch
                {
                    Console.WriteLine("麻痹不知道金币是数字吗??!!!");


                }
            }while(foodcount>100&&foodcount<0);
            
            Console.WriteLine("主人请说话");
            while(true)
            {
                
                string str = Console.ReadLine();
                r1.Speak(str);
            }
            Console.ReadKey();
        }
    }
    class Robort
    {
        public string Name{set; get;}
        private int FullLevel { set; get; }
        public void SayHello()
        {
            Console.WriteLine("我叫{0}",Name);
        }
        public void Eat(int foodcount)
        {  
            FullLevel = +foodcount;


            if (FullLevel > 100)
            {               
                Console.WriteLine("我已经撑死了");
                 return;
            }
           // FullLevel = +foodcount;
        }
        public void Speak(string str)
        { 
            if(FullLevel<=0)
            {
                Console.WriteLine("我已经饿死了");
                return;
            }
            if (str.Contains("姓名") || str.Contains("名字") || str.Contains("叫") || str.Contains("什么"))
            {
                this.SayHello();
            }
            else if (str.Contains("女朋友") || str.Contains("老婆") || str.Contains("媳妇"))
            {
                Console.WriteLine("傻逼吗?!我才2岁啊");
            }
            else if (str.Contains("年龄") || (str.Contains("多大")))
            {
                Console.WriteLine("嘿嘿,我现在才两岁,想干啥子啊");
            }
            else if (str.Contains("麻痹") || str.Contains("操")||str.Contains("傻逼"))
                Console.WriteLine("人家还小嘛,不要骂我啦");
            else if (str.Contains("好"))
                Console.WriteLine("主人你是在表扬我吗?");
            else
            {
                Console.WriteLine("听不懂你在说什么");
            }
            FullLevel--;
        }


    }
}