티스토리 뷰


        private int maxLevel = 100 ;
        private int minLevel = 1;

        public void UpLevel()
        {
            if (this.Level < this.maxLevel)
                Level++;
            else
                Console.WriteLine("레벨을 증가할 수 없습니다.");
        }

        public void UpLevel(int Level)
        {
            if (this.Level < this.maxLevel)
                this.Level += Level;
            else
                Console.WriteLine("레벨을 증가할 수 없습니다.");
           
        }
        public Animal(int Level)
            : this()
        {
           
            if (Level < this.minLevel)
            {               
                this.Level = this.minLevel;
                Console.WriteLine("올바른 레벨이 입력되지 않아 최소 레벨로 조정하였습니다.");
            }
            else if (Level > this.maxLevel)
            {           
                this.Level = this.maxLevel;
                Console.WriteLine("올바른 레벨이 입력되지 않아 최대 레벨로 조정하였습니다.");
            }
            else
            {
                this.Level = Level;
            }               
        }

-----------------------------------------------
            Cat navi = new Cat(-2, "나비");
            navi.UpLevel();
            Console.WriteLine(navi.GetName()
                  + "의 레벨 " + navi.GetLevel());


            Cat nero = new Cat(13, "네로");
            nero.UpLevel(7);
            Console.WriteLine(nero.GetName()
                  + "의 레벨 " + nero.GetLevel());

            Dog dog = new Dog(103, "개");
            dog.UpLevel();
            dog.UpLevel(3);
            Console.WriteLine(dog.GetName()
                  + "의 레벨 " + dog.GetLevel());
------------------


        public virtual void Speak()
        {
            Console.WriteLine("울다");
        }

+++++++
        public void Meow()
        {
            Console.WriteLine("야옹");
        }
        public override void Speak()
        {
            //base.Speak();
            this.Meow();
        }
++++++++++++

        public void Bark()
        {
            Console.WriteLine("멍멍");
        }
        public override void Speak()
        {
            //base.Speak();
            this.Bark();
        }

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
글 보관함