顯示具有 [2014][Code Review]Team 03 標籤的文章。 顯示所有文章
顯示具有 [2014][Code Review]Team 03 標籤的文章。 顯示所有文章

2014年5月12日 星期一

[Code Review] Team 03 - Hw08

執行檔
Form1
Shape3D
Ball
Cube
Cylinder
Pyrmaid
IRollable

2014年4月13日 星期日

[Code Review] Team 03 - Hw06

執行檔 Form1.cs 按我顯示
Shape
class Shape
    {
        protected double L1, L2;
        protected double density;
        protected double pi = 3.1415926;
        protected static int amount = 0;
        public static int Amount
        {
            get { return amount; }
        }

        public Shape(double L1, double density)
        {
            this.L1 = L1;
            this.density = density;
            amount++;
        }
        public Shape(double L1, double L2, double density)
        {
            this.L1 = L1;
            this.L2 = L2;
            this.density = density;
            amount++;
        }
        public virtual double CalVolume() { return 0; }
        public virtual string GetName() { return ""; }
        public double CalQuality() { return CalVolume() * density; }
        public string Show()
        {
            string str="";
            str += GetName()+"\t";
            str += L1 + "\t" + L2 + "\t";
            str += density + "\t";
            str += CalVolume() + "\t";
            str += CalQuality() + "\n";
            return str;
        }
    }
Ball
class Ball : Shape
    {
        
        public Ball(double L1, double density) : base(L1, density) { }
        public static Ball Create(double L1,  double density)
        {
            Ball ball = null;
            if (L1 <= 0 )
            {
                return ball;
            }
            else
            {
                ball = new Ball(L1, density);
                return ball;
            }
        }
        public override double CalVolume()
        {
            return pi * L1 * L1 * L1 * 4 / 3;
        }
        public override string GetName()
        {
            return "Ball";
        }
    }
Cube
class Cube : Shape
    {
        public Cube(double L1, double density) : base(L1, density) { }
        public static Cube Create(double L1, double density)
        {
            Cube cube = null;
            if (L1 <= 0 )
            {
                return cube;
            }
            else
            {
                cube = new Cube(L1, density);
                return cube;
            }
        }
        public override double CalVolume()
        {
            return L1 * L1 * L1 ;
        }
        public override string GetName()
        {
            return "Cube";
        }
    }
Cylinder
class Cylinder : Shape
    {
        public Cylinder(double L1, double L2, double density) : base(L1, L2, density) { }
        public static Cylinder Create(double L1, double L2, double density)
        {
            Cylinder cylinder = null;
            if (L1 <= 0 || L2 <= 0)
            {
                return cylinder;
            }
            else
            {
                cylinder = new Cylinder(L1, L2, density);
                return cylinder;
            }
        }
        public override double CalVolume()
        {
            return pi * L1 * L1 * L2;
        }
        public override string GetName()
        {
            return "Cylinder";
        }

    }
Pyramid
class Pyramid : Shape
    {
         public Pyramid(double L1, double L2, double density) : base(L1, L2, density) { }
         public static Pyramid Create(double L1, double L2, double density)
         {
             Pyramid pyramid = null;
             if (L1 <= 0 || L2 <= 0)
             {
                 return pyramid;
             }
             else
             {
                 pyramid = new Pyramid(L1, L2, density);
                 return pyramid;
             }
         }
         public override double CalVolume()
         {
             return (L1 * L1 * L2) / 3;
         }
         public override string GetName()
         {
             return "Pyramid";
         }
 

    }

2014年4月6日 星期日

[Code Review] Team 03 - Hw05

執行檔 Form1.cs 按我顯示
CardDeck 按我顯示
PokerCard 按我顯示
HandCard 按我顯示

2014年3月24日 星期一

[Code Review] Team 03 - Hw04

Form1.cs
namespace Hw4
{
    public partial class Form1 : Form
    {

        CardDeck Card = new CardDeck();
        public Form1()
        {
            InitializeComponent();
            Card.CreateDeck();
        }        
        private void btnchk_Click(object sender, EventArgs e)
        {
            if (chknormal.Checked)
            {
                txt_Print.AppendText("CheckBox按花色排列 已選定" + "\n");
                Card.ResetDeck();
                print_message();
            }
            if (chkrand.Checked)
            {
                txt_Print.AppendText("CheckBox亂數洗牌 已選定" + "\n");
                Card.ResetDeck();
                Card.Shuffle();
                print_message();
            }
            if (chkarrange.Checked)
            {
                txt_Print.AppendText("CheckBox按點數大小排列 已選定" + "\n");
                Card.Arrange();
                print_message();
            }
        }

        private void btncombo_Click(object sender, EventArgs e)
        {
            switch (cbox_3.SelectedIndex)
            {
                case 0:
                    txt_Print.AppendText("ComboBox按花色排列 已選定"+"\n");
                    Card.ResetDeck();
                    print_message();
                    break;
                case 1:
                    txt_Print.AppendText("ComboBox亂數洗牌 已選定" + "\n");
                     Card.ResetDeck();
                    Card.Shuffle();
                    print_message();
                    break;
                case 2:
                    txt_Print.AppendText("ComboBox按點數大小排列 已選定" + "\n");
                    Card.Arrange();
                    print_message();
                    break;
            }
        }

        private void print_message()
        {
            string message = "";
            for (int i=0; i <= 51; i++)
            {
                message += Card.Cards[i].SuitToUni() + Card.Cards[i].RankToStr() + "  ";
                if (((i + 1) % 13) == 0)
                {
                    message += "\n";
                }
            }
            MessageBox.Show(message);
        }      
    }
}
CardDeck.cs
namespace Hw4
{
    class CardDeck
    {
        public PokerCard[] Cards = new PokerCard[52];
        Random rand = new Random();

        public void CreateDeck()
        {
            for (int i = 0; i <= 51; i++)
            {
                Cards[i] = new PokerCard();
            }
        }//產生出52個PokerCard的物件

        public void ResetDeck()
        {
            for (int i = 0; i <= 51; i++)
            {
                Cards[i].Rank = (i % 13) + 1;
                Cards[i].Suit = (i / 13) + 3;
            }
        } //牌堆回復原始狀態


        public void Shuffle()
        {
            PokerCard Change = new PokerCard();
            for (int i = 0; i <= 51; i++)
            {    
                Change = Cards[i];
                int position = rand.Next(52);
                Cards[i] = Cards[position];
                Cards[position] = Change;
            }

        }//洗牌
        public void Arrange()
        { 
            for (int i = 0; i <= 51; i++)
            {
                Cards[i].Suit = (i%4) + 3;
                Cards[i].Rank = (i / 4) + 1;
            }
        }
    }
}
PokerCard.cs
namespace Hw4
{
    class PokerCard
    {
        public int Suit;  //花色
        public int Rank;  //點數
        public string RankToStr()
        {
            switch (Rank)
            {
                case 1:
                    return "A";                                   
                case 11:
                    return "J";
                case 12:
                    return "Q";
                case 13:
                    return "K";
                default:
                    return Convert.ToString(Rank);
            }
        }
        public string SuitToUni()
        {
            string Str_Suit;
            switch (Suit)
            {
                case 3:
                    Str_Suit = "\u2665";
                    break;
                case 4:
                    Str_Suit = "\u2666";
                    break;
                case 5:
                    Str_Suit = "\u2663";
                    break;
                default:
                    Str_Suit = "\u2660";
                    break;                    
            }
            return Str_Suit;
            
        }
    }
}