码迷,mamicode.com
首页 > Windows程序 > 详细

小马和小黑 c# 面向对象

时间:2015-04-28 15:32:56      阅读:218      评论:0      收藏:0      [点我收藏+]

标签:

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

namespace xx
{
    class Dog
    {
        private string _Name;

        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }
        private Ren _Owner;

        internal Ren Owner
        {
            get { return _Owner; }
            set { _Owner = value; }
        }
        private int _Jed = 10;

        protected int Jed
        {
            get { return _Jed; }
        }
        public Dog()
        {
        }
        /// <summary>
        /// 参数 主人
        /// </summary>
        /// <param name="owner"></param>
        public Dog(Ren owner)
        {
            _Owner = owner;
        }
        /// <summary>
        /// 参数 主人,名字
        /// </summary>
        /// <param name="owner"></param>
        /// <param name="name"></param>
        public Dog( Ren owner,string name):this(owner)
        {
            _Name = name;
        }
        /// <summary>
        /// 参数为喂的数量和东西
        /// </summary>
        /// <param name="num"></param>
        /// <param name="ss"></param>
        public void eat(string ss,int num)
        {
            Console.WriteLine(_Owner+""+_Name+num+""+ss+"吃。");
            _Jed += num;
        }
        public void a()
        {
            if (_Jed <= 0)
            {
                Console.WriteLine(_Name + "已魂归汪星……");
            }
            else if (_Jed == 1)
            {
                Console.WriteLine(_Name + ":主人,我饿死了!"); _Jed--;
            }
            else if (_Jed <= 5)
            {
               
                Console.WriteLine(_Name+":主人,我饿扁了!"); _Jed--;
            }
            else  if (_Jed > 5)
            {
               
                Console.WriteLine("汪汪……"); _Jed--; _Jed--;
            }
            
        }
    }
    class Ren
    {
        private string _Name;

        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }
        private int _Age;

        protected int Age
        {
            get { return _Age; }
            set { _Age = value; }
        }
        private DateTime _Bir;

        protected DateTime Bir
        {
            get { return _Bir; }
            set { _Bir = value; }
        }
        private int _Money = 100;

        protected int Money
        {
            get { return _Money; }
        }
        private Dog _Gou;

        internal Dog Gou
        {
            get { return _Gou; }
            set { _Gou = value; }
        }
        private int _Jed = 100;

        protected int Jed
        {
            get { return _Jed; }
        }
        private bool je()
        {
            bool je = true;
            if (_Jed <= 1)
            {
                Console.WriteLine(_Name+"饥渴劳累至死!");
                je = false;
            }
            else if (_Jed <= 10)
            {
                Console.WriteLine(_Name+":饿扁了!");
            }
            else if (_Jed <20)
            {
                Console.WriteLine(_Name + ":有点饿");
            }
            return je;
        }
        private void yq(int m)
        {
            if (m< 10)
            { Console.WriteLine("快没钱了,想着工作挣钱呦!");}
            if (m < 0)
            { Console.WriteLine("钱不够了,挣钱去!"); }
        }
        public Ren()
        { 
            
        }
        /// <summary>
        /// 名字
        /// </summary>
        /// <param name="name"></param>
        public Ren(string name)
        {
            _Name = name;
        }
        /// <summary>
        /// 名字,年龄
        /// </summary>
        /// <param name="name"></param>
        /// <param name="age"></param>
        public Ren(string name, int age):this(name)
        {
            _Age = age;
        }
        /// <summary>
        /// 名字,年龄,生日
        /// </summary>
        /// <param name="name"></param>
        /// <param name="age"></param>
        /// <param name="bir"></param>
        public Ren(string name, int age, DateTime bir):this(name,age)
        {
            _Bir = bir;
        }
        /// <summary>
        /// 名字,生日
        /// </summary>
        /// <param name="name"></param>
        /// <param name="bir"></param>
        public Ren(string name, DateTime bir):this(name)
        {
            _Bir = bir;
        }

        /// <summary>
        /// 名字,狗(得有狗)
        /// </summary>
        /// <param name="name"></param>
        public Ren(string name,Dog gou):this(name)
        {
            _Gou = gou;
        }
        /// <summary>
        /// 名字,年龄,狗(得有狗)
        /// </summary>
        /// <param name="name"></param>
        /// <param name="age"></param>
        public Ren(string name, int age, Dog gou):this(name,age)
        {
            _Gou = gou;
        }
        /// <summary>
        /// 名字,年龄,生日,狗(得有狗)
        /// </summary>
        /// <param name="name"></param>
        /// <param name="age"></param>
        /// <param name="bir"></param>
        public Ren(string name, int age, DateTime bir, Dog gou) : this(name, age,bir)
        {
            _Gou = gou;
        }
        /// <summary>
        /// 名字,生日,狗(得有狗)
        /// </summary>
        /// <param name="name"></param>
        /// <param name="bir"></param>
        public Ren(string name, DateTime bir, Dog gou):this(name,bir)
        {
            _Gou = gou;
        }
        /// <summary>
        /// 工资,工作时间
        /// </summary>
        /// <param name="gz"></param>
        /// <param name="h"></param>
        public void work(int gz,int h)
        {
            _Jed -= 20;
            if (je())
            {
                _Money += gz * h;
                int money = gz * h;
                Console.WriteLine(_Name + "辛苦工作" + h + "小时,赚了" + money + "块。");
            }
        }
        private bool spend(int num)
        {
            int m=_Money -num;
            yq(m);
            if (m > 0)
            {
                _Money = m;
                return true;
            }
            else
            {
                return false;
            }

        }
        /// <summary>
        ///喂狗,喂啥,喂多少,单价
        /// </summary>
        public void feed(Dog gou, string s,int num,int dj)
        {
            int money = num * dj;
            if (spend(money))
                {
                gou.eat(s,num);
                Console.WriteLine(_Name + "带着他的狗" + gou.Name + "吃了" + num + "" + s + "花了" + money + "块。");
                }
        }
        /// <summary>
        /// 吃啥,吃多少,单价
        /// </summary>
        public void eat(string s, int num, int dj)
        {
            int money=num*dj;
            if (spend(money))
            {
                _Jed += money;
                Console.WriteLine(_Name + "吃了" + num + "" + s + "花了" + money + "块。");
            }
        }
        public void liugou(Dog gou)
        {
            _Jed -= 5;
            if (je())
            {
                Console.WriteLine(_Name + "带着他的狗" + gou.Name + "遛弯呢……");
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            
            DateTime bir = new DateTime(19930425);
            Ren a = new Ren("小马",24,bir);
            Dog g = new Dog(a,"小黑");
            a.liugou(g);
            g.a();
            a.work(12,3);
            a.eat("火烧",5,3);
            a.work(12, 3);
            a.work(12, 3);
            a.work(12, 3);
            a.eat("烧饼",3,10);
            a.liugou(g);
            a.liugou(g);
            for (int i = 0; i < 15; i++)
            {
                 g.a();
            }
           
            a.liugou(g);
            a.liugou(g);
            a.liugou(g);
            a.work(12, 3);
            a.work(12, 3);
            Console.ReadKey();
        }
    }
}

 

小马和小黑 c# 面向对象

标签:

原文地址:http://www.cnblogs.com/lovesy2413/p/4462809.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!