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());
day 07 c# 装备商店
猜你喜欢
转载自blog.csdn.net/qq_43119892/article/details/104507313
今日推荐
周排行