Exemple #1
0
        private void cBoxMaterial_SelectedIndexChanged(object sender, EventArgs e)
        {
            string material = cBoxMaterial.SelectedItem.ToString();
            double density;
            bool   canModified = false;

            switch (material)
            {
            case "鋁":
                _mType  = ShapeType.Material.Al;
                density = 2.7;
                break;

            case "鐵":
                _mType  = ShapeType.Material.Fe;
                density = 7.87;
                break;

            case "鉛":
                _mType  = ShapeType.Material.Pb;
                density = 11.3;
                break;

            default:
                _mType      = ShapeType.Material.UNKNOW;
                density     = 0;
                canModified = true;
                break;
            }
            txtDensity.Text = density.ToString();
            if (!canModified)
            {
                txtDensity.Enabled = false;
            }
        }
Exemple #2
0
 public Pyramid(double side, double height, ShapeType.Material mType) : base(mType)
 {
     _geo   = ShapeType.Geo.PYRAMID;
     Side   = side;
     Height = height;
     _amount++;
 }
Exemple #3
0
 public Cylinder(double radius, double height, ShapeType.Material mType) : base(mType)
 {
     _geoType = ShapeType.Geo.CYLINDER;
     Radius   = radius;
     Height   = height;
     _amount++;
 }
Exemple #4
0
        public static Shape3D Create(string name, ShapeType.Material mType, double arg1, double arg2)
        {
            Shape3D rv = null;

            switch (name)
            {
            case "球":
                rv = Ball.Create(arg1, mType);
                return(rv);

            case "立方體":
                rv = Cube.Create(arg1, mType);
                return(rv);

            case "圓柱體":
                rv = Cylinder.Create(arg1, arg2, mType);
                return(rv);

            case "金字塔":
                rv = Pyramid.Create(arg1, arg2, mType);
                return(rv);

            default:
                return(rv);
            }
        }
Exemple #5
0
 public static string Name(ShapeType.Material mType)
 {
     foreach (var e in elements)
     {
         if (e.MaterialType == mType)
         {
             return(e.Name);
         }
     }
     return("未知");
 }
Exemple #6
0
 public static Cube Create(double side, ShapeType.Material mType)
 {
     if (side <= 0)
     {
         throw new NegativeException("邊長不可小於或等於零!");
     }
     else
     {
         return(new Cube(side, mType));
     }
 }
Exemple #7
0
 public static double Density(ShapeType.Material mType)
 {
     foreach (var e in elements)
     {
         if (e.MaterialType == mType)
         {
             return(e.Density);
         }
     }
     return(0);
 }
Exemple #8
0
 // private static double _pi=3.1415926;  //可以使用 readonly 來修飾
 public static Ball Create(double radius, ShapeType.Material mType)
 {
     if (radius <= 0)
     {
         throw new NegativeException("半徑不可小於或等於零!");
     }
     else
     {
         return(new Ball(radius, mType));
     }
 }
Exemple #9
0
 //private static double _pi = 3.1415926;
 public static Cylinder Create(double radius, double height, ShapeType.Material mType)
 {
     if (radius <= 0)
     {
         throw new NegativeException("半徑不可小於或等於零!");
     }
     else if (height <= 0)
     {
         throw new NegativeException("高度不可小於或等於零!");
     }
     else
     {
         return(new Cylinder(radius, height, mType));
     }
 }
Exemple #10
0
 protected ShapeType.Material _materialType; //_material 與 _density 有相關性
 public Shape3D()
 {
     _materialType = ShapeType.Material.UNKNOWN;
     _amount++;
 }
Exemple #11
0
 public Ball(double radius, ShapeType.Material mType) : base(mType)
 {
     _geoType = ShapeType.Geo.BALL;
     Radius   = radius;
     _amount++;
 }
Exemple #12
0
 public Cube(double side, ShapeType.Material mType) : base(mType)
 {
     _geoType = ShapeType.Geo.CUBE;
     Side     = side;
     _amount++;
 }
Exemple #13
0
 public Shape3D(ShapeType.Material mType)
 {
     //Density = density;
     _material = mType;
     _amount++;
 }
Exemple #14
0
 public Shape3D()
 {
     //_density = 0;
     _material = ShapeType.Material.UNKNOW;
     _amount++;
 }
Exemple #15
0
 private void setMaterialProperties(object sender, SetMaterialEventArgs e)
 {
     _mType           = e.MType;
     txtMaterial.Text = MaterialTable.Name(e.MType);
     txtDensity.Text  = MaterialTable.Density(e.MType).ToString();
 }
Exemple #16
0
 public void MaterialFunc(object sender, MaterialEventArgs e)
 {
     _mType           = e.MaterialType;
     txtMaterial.Text = e.MaterialName;
     txtDensity.Text  = MaterialTable.Density(e.MaterialType).ToString();
 }
Exemple #17
0
 public Shape3D(ShapeType.Material mType)
 {
     _materialType = mType;
     _amount++;
 }
Exemple #18
0
 public Element(ShapeType.Material mType, string name, double density)
 {
     MaterialType = mType;
     Name         = name;
     Density      = density;
 }