using System;-----------------------抽象类作业----------------
namespace Interface
{
public abstract class Shape
{
public abstract double GetArea();
public abstract double GetCircumference();
}
public class Circle : Shape
{
private float radius;
public Circle(float radius)
{
this.radius = radius;
}
public override double GetArea()
{
return Math.PI * radius * radius;
}
public override double GetCircumference()
{
return Math.PI * 2 * radius;
}
}
public class Rectangle : Shape
{
private float length;
private float width;
public Rectangle(float length, float width)
{
this.length = length;
this.width = width;
}
public override double GetArea()
{
return length * width;
}
public override double GetCircumference()
{
return 2 * (width + length);
}
}
public class aHW
{
public static void GetShapeArea(Shape shape)
{
double area = shape.GetArea();
Console.WriteLine($"{shape}面积为{area}");
}
public static void GetShapeCircumference(Shape shape)
{
double circumference = shape.GetCircumference();
Console.WriteLine($"{shape}周长为{circumference}");
}
}
}
using System;--------------------静态类作业--------------------------
namespace Interface
{
public enum GoodsType
{
Comsumabel,
Equipment,
Weapon
}
abstract class Goods
{
private string name;
private GoodsType goodsType;
private float buyPrice;
private float salePrice;
protected Goods(string name, GoodsType goodsType, float buyPrice, float salePrice)
{
this.name = name;
this.goodsType = goodsType;
this.buyPrice = buyPrice;
this.salePrice = salePrice;
}
public string Name
{
get => name;
set => name = value;
}
public GoodsType GoodsType
{
get => goodsType;
set => goodsType = value;
}
public float BuyPrice
{
get => buyPrice;
set => buyPrice = value;
}
public float SalePrice
{
get => salePrice;
set => salePrice = value;
}
/// <summary>
/// 描述
/// </summary>
public abstract void Description();
}
class Comsumabel:Goods
{
private float hpAdd;
private float mpAdd;
public float HpAdd
{
get => hpAdd;
set => hpAdd = value;
}
public float MpAdd
{
get => mpAdd;
set => mpAdd = value;
}
public Comsumabel(string name, GoodsType goodsType, float buyPrice, float salePrice, float hpAdd, float mpAdd) : base(name, goodsType, buyPrice, salePrice)
{
this.hpAdd = hpAdd;
this.mpAdd = mpAdd;
}
public Comsumabel(string name, GoodsType goodsType, float buyPrice, float salePrice) : base(name, goodsType, buyPrice, salePrice)
{
}
public override void Description()
{
if (mpAdd==0)
{
Console.WriteLine($"{Name}是一个消耗品,加血{hpAdd}点");
}
else
{
Console.WriteLine($"{Name}是一个消耗品,加血{mpAdd}点");
}
}
}
class Weapon:Goods
{
private float attack;
public float Attack
{
get => attack;
set => attack = value;
}
public Weapon(string name, GoodsType goodsType, float buyPrice, float salePrice, float attack) : base(name, goodsType, buyPrice, salePrice)
{
this.attack = attack;
}
public override void Description()
{
Console.WriteLine($"{Name}是一个武器,攻击力{attack}点");
}
}
class Equipment:Goods
{
private float propertyAdd;
public float PropertyAdd
{
get => propertyAdd;
set => propertyAdd = value;
}
public Equipment(string name, GoodsType goodsType, float buyPrice, float salePrice, float propertyAdd) : base(name, goodsType, buyPrice, salePrice)
{
this.propertyAdd = propertyAdd;
}
public override void Description()
{
Console.WriteLine($"{Name}是一个装备,成长属性加成{propertyAdd}点");
}
}
public static class GoodsStore
{
private static Comsumabel[] _comsumabels;
private static Equipment[] _equipments;
private static Weapon[] _weapons;
static GoodsStore()
{
_comsumabels=new Comsumabel[3];
_equipments=new Equipment[3];
_weapons=new Weapon[3];
Initstore();
}
private static void Initstore()
{
_comsumabels[0]=new Comsumabel("小血瓶",GoodsType.Comsumabel,
30,10,30,0);
_comsumabels[1] = new Comsumabel("大血瓶",GoodsType.Comsumabel,
50,20,50,0);
_comsumabels[2] = new Comsumabel("大蓝瓶",GoodsType.Comsumabel,
100,50,0,200);
_equipments[0] = new Equipment("日炎斗篷",GoodsType.Equipment,
3000,2000,80);
_equipments[1] = new Equipment("狂徒铠甲",GoodsType.Equipment,
4000,2500,120);
_weapons[0] = new Weapon("饮血剑",GoodsType.Weapon,
2000,1000,80);
_weapons[1] = new Weapon("无尽之刃",GoodsType.Weapon,
3000,1500,120);
}
public static void ShowGoods(GoodsType goodsType)
{
switch (goodsType)
{
case GoodsType.Comsumabel :
for (int i = 0; i < _comsumabels.Length; i++)
{
_comsumabels[i]?.Description();
}
break;
case GoodsType.Equipment:
for (int i = 0; i < _equipments.Length; i++)
{
_equipments[i]?.Description();
}
break;
case GoodsType.Weapon:
for (int i = 0; i < _weapons.Length; i++)
{
_weapons[i]?.Description();
}
break;
}
}
}
using System;
namespace Interface
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Shape rec=new Rectangle(4,5);
Shape circle=new Circle(3);
aHW.GetShapeArea(circle);
aHW.GetShapeArea(rec);
aHW.GetShapeCircumference(circle);
aHW.GetShapeCircumference(rec);
GoodsStore.ShowGoods(GoodsType.Equipment);
GoodsStore.ShowGoods(GoodsType.Comsumabel);
GoodsStore.ShowGoods(GoodsType.Weapon);
ComputerMouse mouse=new ComputerMouse();
IUSB usb=new ComputerMouse();
}
}
}