티스토리 뷰

IT Skills/Programming

C# -- 동물농장

E-yarn 2013. 4. 29. 16:40

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

namespace WindowsFormsApplication2
{
   

    public class Animal
    {
        protected string Name;
        private int Level;
        private int maxLevel = 100;
        private int minLevel = 1;

        public string UpLevel()
        {
            string message;
            if (this.Level < this.maxLevel)
                message = (Level++).ToString;
            else
                message = "레벨을 증가시킬수없당";
            return message;
        }


        public string UpLevel(int Level)
        {
            string message;
            if (this.Level < this.maxLevel)
            {
                this.Level += Level;
                message = this.Level.ToString();
            }
            else
                message = "레벨을 증가시킬수없당";
            return message;
         }

        public string GetName()
        {
            return Name;
        }
        public int GetLevel()
        {
            return Level;
        }

 

        public Animal()
        { }
        public Animal(int Level):this()
        {
            if (Level < this.minLevel)
                this.Level = this.minLevel;
            else if (Level > this.maxLevel)
                this.Level = this.maxLevel;
            else
                this.Level = Level;
        }
        public Animal(int Level, string Name): this(Level)
        { this.Name = Name; }
        }


    public class Cat : Animal
    {
        public Cat() { }
        public Cat(int Level)
            : base(Level)
        { }
        public Cat(int Level, string Name)
            : this(Level)
        {
            base.Name = Name;
        }
    }

 

    public class Dog : Animal
    {
        public Dog() { }
        public Dog(int Level)
            : base(Level)
        { }
        public Dog(int Level, string Name)
            : this(Level)
        {
            base.Name = Name;
        }

    }


}


-----------------------------------------------------------------------------

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        Animal[] animals;
        int maxNo;
        int currentNo;

        public Form1()
        {
            InitializeComponent();
            maxNo=10;
            animals=new Animal[maxNo];
            currentNo = 0;
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void making_Click(object sender, EventArgs e)
        {
         if(comboBox1.SelectedIndex == 0)
         { animals[currentNo] = new Dog(int.Parse(textBox2.Text),textBox1.Text);}
         else if (comboBox1.SelectedIndex == 1)
         { animals[currentNo] = new Cat(int.Parse(textBox2.Text),textBox1.Text); }
         else
            return;

         listbox1.Items.Clear();
         for (int i = 0; i < currentNo; i++)
         {
             listbox1.Items.Add(animals[i].GetName());
         }
        }
    }
}

 

 

 

 

 

'IT Skills > Programming' 카테고리의 다른 글

C# 인터페이스  (0) 2013.05.06
JAVA 전쟁 프로젝트  (0) 2013.05.06
C# - 동물농장 참고자료#2  (0) 2013.04.22
C# - 시험참고자료#`  (0) 2013.04.22
java 계산기  (0) 2013.04.15
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
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
글 보관함