วันพฤหัสบดีที่ 18 กันยายน พ.ศ. 2557

การบ้านครั้งที่ 2 (no CD)

Program

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Character kumkhim = new Character("KumKhim");
            kumkhim.kumkhim();
            kumkhim.skill();
            kumkhim.level(25);
            kumkhim.kumkhim();

            Console.ReadLine();
        }
    }
}

Character

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
    class Character
    {   private int sk = 0;
        private string name = "No Name";
        private int hp = 0;
        private int mp = 0;
        private int max_hp = 999;
        private int max_mp = 999;
        public int lv = 0;
        private int dm = 0;
        private int df = 0;
        private int sp = 0;
        public Character()
        {
            life(133);
            mana(118);
            level(25);
            damage(42);
            defent(48);
            speed(335);
            
        }
        public Character(string name)
            : this()
        {
            this.name = name;
        }
        //-----------------------
        public void level(int lv)
        {
            this.lv = lv;
        }
        public int getlv()
        {
            return this.lv;
        }
        //------------------------------
        public void life()
        {
            hp = max_hp;
        }
        public void life(int hp)
        {
            this.hp = hp;
        }
        public int gethp()
        {
            return this.hp;
        }
        //-------------------------
        public void mana()
        {
            mp = max_mp;
        }
        public void mana(int mp)
        {
            this.mp = mp;
        }
       
        public int getmp()
        {
            return this.mp;
        }
        //----------------------------------
        public void damage(int dm)
        {
            this.dm = dm;
        }
        public int getdm()
        {
            return this.dm;
        }
        //----------------------------------
        public void defent(int df)
        {
            this.df = df;
        }
        public int getdf()
        {
            return this.df;
        }
        //----------------------------------
        public void speed(int sp)
        {
            this.sp = sp;
        }
        public int getsp()
        {
            return this.sp;
        }
        //-------------------------------
        public string getname()
        {
            return this.name;
        }
        public void kumkhim(){ 
            Console.WriteLine("Hero : " + getname());
            Console.WriteLine("HP : " + gethp());
            Console.WriteLine("MP : " + getmp());
            Console.WriteLine("LV : " + getlv());
            Console.WriteLine("------------------------------------");
            Console.WriteLine("Damage : " + getdm());
            Console.WriteLine("Defent : " + getdf());
            Console.WriteLine("Speed : " + getsp());
            Console.WriteLine("------------------------------------");
            Console.WriteLine("Skill List");
         
            if (lv >= 1)
            {
                Console.WriteLine("1.Arcane Shift");
            }
            if (lv >= 5)
            {
                if (sk == 0)
                {
                    Console.WriteLine("2.Blink Stike");
                }
                else if(sk == 1)
                {
                    Console.WriteLine("2.Charm");
                }
            }
            if (lv >= 10)
            {
                if (sk == 0)
                {
                    Console.WriteLine("3.I'm not slow");
                }
                else if(sk == 1)
                {
                    Console.WriteLine("3.I'm don't have Mana");
                }
            }
            if (lv >= 15)
            {
                if (sk == 0)
                {
                    Console.WriteLine("4.Disguise");
                }
                else if (sk == 1)
                {
                    Console.WriteLine("4.Arcanic Shackles");
                }
            }
            Console.WriteLine("------------------------------------");

         }
       
        public void skill() {

            if (sk == 0) {
                sk = 1;
            }
            else if (sk == 1)
            {
                sk = 0;
            }

        
        }
    }
}