day 07 c# 裝備商店

 public enum GoodsType
    {
        Weapom,
        Comsumabel,
        Equipment
    }
    public abstract class Goods
    {
        public string name;
        public int buyPrice;
        public int sellPrice;
        public GoodsType type;
        
        public Goods(string name, GoodsType type, int buyPrice, int sellPrice) { }
        public abstract void Description();
    }
    public class Weapon : Goods
    {
        public Weapon(string name, GoodsType type, int buyPrice, int sellPrice,int attack) : base(name, type, buyPrice, sellPrice)
        {
            this.name = name;
            this.type = type;
            this.buyPrice = buyPrice;
            this.sellPrice = sellPrice;
            this.attack = attack;
        }
        public int attack;
        public override void Description()
        {
            Console.WriteLine("武器名稱"+name);
            Console.WriteLine("武器的攻擊力爲:"+attack);
            Console.WriteLine("買入價格:"+buyPrice);
            Console.WriteLine("賣出價格" + sellPrice);
        }
    }
    public class Comsumabel : Goods
    {
        public int hpAdd;
        public int mpAdd;
        public Comsumabel(string name, GoodsType type, int buyPrice, int sellPrice, int hpAdd, int mpAdd) : base(name, type, buyPrice, sellPrice)
        {
            this.name = name;
            this.type = type;
            this.buyPrice = buyPrice;
            this.sellPrice = sellPrice;
            this.hpAdd = hpAdd;
            this.mpAdd = mpAdd;
        }
        public override void Description()
        {
            Console.WriteLine("道具名稱" + name);
            Console.WriteLine("hp加成:" + hpAdd);
            Console.WriteLine("mp加成:" + mpAdd );
            Console.WriteLine("買入價格:" + buyPrice);
            Console.WriteLine("賣出價格" + sellPrice);
        }
    }
    public class Equipment : Goods
    {
        public int propertyAdd;
        public Equipment(string name, GoodsType type, int buyPrice, int sellPrice, int propertyAdd) : base(name, type, buyPrice, sellPrice)
        {
            this.name = name;
            this.type = type;
            this.buyPrice = buyPrice;
            this.sellPrice = sellPrice;
            this.propertyAdd = propertyAdd;
        }
        public override void Description()
        {
            Console.WriteLine("裝備名稱" + name);
            Console.WriteLine("???:" + propertyAdd);
            Console.WriteLine("買入價格:" + buyPrice);
            Console.WriteLine("賣出價格" + sellPrice);
        }
    }
    static class GoodStore
    {
        static public Weapon[] weapons = new Weapon[5];
        static public Comsumabel[] Comsumabels = new Comsumabel[5];
        static public Equipment[] Equipments = new Equipment[5];
        static  public void NewGoodStore()
        {
            weapons[0] = new Weapon("sss", GoodsType.Weapom, 100, 50, 300);
            weapons[1] = new Weapon("ss", GoodsType.Weapom, 100, 50, 300);
            weapons[2] = new Weapon("s", GoodsType.Weapom, 100, 50, 300);
            weapons[3] = new Weapon("a", GoodsType.Weapom, 100, 50, 300);
            weapons[4] = new Weapon("b", GoodsType.Weapom, 100, 50, 300);
            Comsumabels[0] = new Comsumabel("sss", GoodsType.Comsumabel, 100, 50, 300,400);
            Comsumabels[1] = new Comsumabel("ss", GoodsType.Comsumabel, 100, 50, 300,300);
            Comsumabels[2] = new Comsumabel("s", GoodsType.Comsumabel, 100, 50, 300,200);
            Comsumabels[3] = new Comsumabel("a", GoodsType.Comsumabel, 100, 50, 300,100);
            Comsumabels[4] = new Comsumabel("b", GoodsType.Comsumabel, 100, 50, 300,0);
            Equipments[0] = new Equipment("sss", GoodsType.Equipment, 100, 50, 300);
            Equipments[1] = new Equipment("ss", GoodsType.Equipment, 100, 50, 300);
            Equipments[2] = new Equipment("s", GoodsType.Equipment, 100, 50, 300);
            Equipments[3] = new Equipment("a", GoodsType.Equipment, 100, 50, 300);
            Equipments[4] = new Equipment("b", GoodsType.Equipment, 100, 50, 300);
        }
        static public void printf(string type)
        {
            switch (type)
            {
                case "1":
                    foreach (var item in weapons)
                    {
                        item.Description();
                    }
                    break;
                case "2":
                    foreach (var item in Comsumabels)
                    {
                        item.Description();
                    }
                    break;
                case "3":
                    foreach (var item in Equipments)
                    {
                        item.Description();
                    }
                    break;
            }
    
            
        }
    }


/////主函數中寫以下三行
            GoodStore.NewGoodStore();
            Console.WriteLine("查看商品:1-武器,2-消耗品,3-裝備");
            GoodStore.printf(Console.ReadLine());

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章