2014年6月25日 星期三
2014年5月5日 星期一
[Code Review] Team 05 - Homework 07
執行檔的連結
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HW7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//因形狀不同而改變出現的參數
private void cbox_shape_SelectedIndexChanged(object sender, EventArgs e)
{
switch (cbox_shape.SelectedIndex)
{
case 0:
lbl_para1.Text = "半徑";
txt_para2.Visible = false;
lbl_para2.Visible = false;
break;
case 1:
lbl_para1.Text = "邊長";
txt_para2.Visible = false;
lbl_para2.Visible = false;
break;
case 2:
lbl_para1.Text = "半徑";
txt_para2.Visible = true;
lbl_para2.Visible = true;
break;
case 3:
lbl_para1.Text = "邊長";
txt_para2.Visible = true;
lbl_para2.Visible = true;
break;
default:
break;
}
}
static double[] densityarr={2.7,7.87,11.3};
//用Shape3D與IRollable兩個不同參考的泛型來存取
List shapeArr = new List();
List rollArr = new List();
//加入物件
private void btn_import_Click(object sender, EventArgs e)
{
if (CheckChoise())
{
double density = densityarr[cbox_material.SelectedIndex];
switch (cbox_shape.SelectedIndex)
{
case 0:
Ball ball = new Ball(double.Parse(txt_para1.Text), density);
shapeArr.Add(ball);
break;
case 1:
Cube cube = new Cube(double.Parse(txt_para1.Text), density);
shapeArr.Add(cube);
break;
case 2:
Cylinder cylinder = new Cylinder(double.Parse(txt_para1.Text), double.Parse(txt_para2.Text), density);
shapeArr.Add(cylinder);
break;
case 3:
Pyramid pyramid = new Pyramid(double.Parse(txt_para1.Text), double.Parse(txt_para2.Text), density);
shapeArr.Add(pyramid);
break;
default:
break;
}
txt_amount.Text = Convert.ToString(Shape3D.Amount);
txt_objdata.AppendText(shapeArr[shapeArr.Count - 1].material() + '\n');
}
}
//計算體積
private void btn_calculateV_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i < shapeArr.Count; i++)
txt_showVolume.AppendText(shapeArr[i].datadisplay());
}
//計算滑動距離
private void btn_calculateScroll_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i = 2 && txt_para2.Text == "")
{
MessageBox.Show("仍有參數未輸入,請輸入完畢!!");
return false;
}
else
return true;
}
}
}
Shape3D.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW7
{
abstract class Shape3D
{
//Fields
protected double density;
protected static int amount = 0;
//Contructor
public Shape3D()
{
Density = 0;
}
public Shape3D(double density)
{
Density = density;
amount++;
}
//Atributes
public double Density
{
get { return density;}
set { density =value;}
}
//readonly Atributes
public static int Amount
{
get { return amount; }
}
//abstract method
public abstract double volume();
public abstract string material();
//method
public double weight()
{
return volume()*Density;
}
public string datadisplay()
{
string str=null;
str += material();
str += '\t';
str += String.Format("{0:F2}",weight());
str += '\n';
return str;
}
}
}
Ball.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW7
{
class Ball:Shape3D,IRollable
{
//Fields
private static double pi = 3.1415926;
private double radius;
private string shapename = "Ball";
//contructor
public Ball(double radius, double density)
: base(density)
{
Radius = radius;
}
//Atributes
public double Radius
{
get{return radius;}
set{radius=value;}
}
//override method
public override double volume()
{
return 4.0 / 3 * pi * Math.Pow(Radius, 3);
}
public override string material()
{
string str = null;
str += shapename;
str += '\t';
str += Convert.ToString(Radius);
str += '\t';
str += '\t';
str += String.Format("{0:F2}", Density);
return str;
}
public double Rolldistance()
{
return Radius * Radius;
}
public string ShowRolldistance()
{
return material() + '\t' + String.Format("{0:F2}", Rolldistance()) + '\n';
}
}
}
Cube.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW7
{
class Cube : Shape3D
{
//Fields
private double side;
private string shapename = "Cube";
//contructor
public Cube(double side, double density)
: base(density)
{
Side = side;
}
//Atributes
public double Side
{
get { return side; }
set { side = value; }
}
//override method
public override double volume()
{
return Math.Pow(Side, 3);
}
public override string material()
{
string str = null;
str += shapename;
str += '\t';
str += Convert.ToString(Side);
str += '\t';
str += '\t';
str += String.Format("{0:F2}", Density);
return str;
}
}
}
Cylinder.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW7
{
class Cylinder : Shape3D,IRollable
{
//Fields
private static double pi = 3.1415926;
private double radius;
private double height;
private string shapename = "Cylinder";
//contructor
public Cylinder(double radius, double height, double density)
: base(density)
{
Radius = radius;
Height = height;
}
//Atributes
public double Radius
{
get{return radius;}
set{radius=value;}
}
public double Height
{
get { return height; }
set { height = value; }
}
//override method
public override double volume()
{
return Height * pi * Math.Pow(Radius, 2);
}
public override string material()
{
string str = null;
str += shapename;
str += '\t';
str += Convert.ToString(Radius);
str += '\t';
str += Convert.ToString(Height);
str += '\t';
str += String.Format("{0:F2}", Density);
return str;
}
public double Rolldistance()
{
return Radius*5;
}
public string ShowRolldistance()
{
return material()+'\t' + String.Format("{0:F2}", Rolldistance())+'\n';
}
}
}
Pyramid.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW7
{
class Pyramid : Shape3D
{
//Fields
private double side;
private double height;
private string shapename = "Pyramid";
//contructor
public Pyramid(double side, double height, double density)
: base(density)
{
Side = side;
Height = height;
}
//Atributes
public double Side
{
get { return side; }
set { side = value; }
}
public double Height
{
get { return height; }
set { height = value; }
}
//override method
public override double volume()
{
return 1.0 / 3 * Math.Pow(Side, 2) * Height;
}
public override string material()
{
string str = null;
str += shapename;
str += '\t';
str += Convert.ToString(Side);
str += '\t';
str += Convert.ToString(Height);
str += '\t';
str += String.Format("{0:F2}", Density);
return str;
}
}
}
IRollable.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW7
{
interface IRollable
{
double Rolldistance();
string ShowRolldistance();
}
}
[Code Review] Team 05 - Hw08
執行檔的連結
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HW8
{
public partial class Form1 : Form
{
//顯示方塊的欄位
private static string strImform1 = "編號" + '\t' + "形狀" + '\t' + "邊長/半徑" + '\t' + "高" + '\t' + "密度" + '\n';
private static string strImform2 = "編號" + '\t' + "形狀" + '\t' + "邊長/半徑" + '\t' + "高" + '\t' + "密度" + '\t' + "體積" + '\t' + "重量" + '\n';
private static string strImform3 = "編號" + '\t' + "形狀" + '\t' + "邊長/半徑" + '\t' + "高" + '\t' + "密度" + '\t' + "滾動距離"+ '\n';
public Form1()
{
InitializeComponent();
txt_objdata.AppendText(strImform1);
txt_showVolume.AppendText(strImform2);
txt_showScoll.AppendText(strImform3);
}
//因形狀不同而改變出現的參數
private void cbox_shape_SelectedIndexChanged(object sender, EventArgs e)
{
switch (cbox_shape.SelectedIndex)
{
case 0:
lbl_para1.Text = "半徑";
txt_para2.Visible = false;
lbl_para2.Visible = false;
break;
case 1:
lbl_para1.Text = "邊長";
txt_para2.Visible = false;
lbl_para2.Visible = false;
break;
case 2:
lbl_para1.Text = "半徑";
txt_para2.Visible = true;
lbl_para2.Visible = true;
break;
case 3:
lbl_para1.Text = "邊長";
txt_para2.Visible = true;
lbl_para2.Visible = true;
break;
default:
break;
}
}
static double[] densityarr={2.7,7.87,11.3};
List shapeArr = new List();
//加入物件
private void btn_import_Click(object sender, EventArgs e)
{
if (CheckChoise())
{
double density = densityarr[cbox_material.SelectedIndex];
switch (cbox_shape.SelectedIndex)
{
case 0:
Ball ball = new Ball(double.Parse(txt_para1.Text), density);
shapeArr.Add(ball);
break;
case 1:
Cube cube = new Cube(double.Parse(txt_para1.Text), density);
shapeArr.Add(cube);
break;
case 2:
Cylinder cylinder = new Cylinder(double.Parse(txt_para1.Text), double.Parse(txt_para2.Text), density);
shapeArr.Add(cylinder);
break;
case 3:
Pyramid pyramid = new Pyramid(double.Parse(txt_para1.Text), double.Parse(txt_para2.Text), density);
shapeArr.Add(pyramid);
break;
default:
break;
}
//存入編號
shapeArr[shapeArr.Count - 1].Order = shapeArr.Count - 1;
//顯示各形狀的數量
ShapeNum();
//將物件加入清單
txt_objdata.AppendText(shapeArr[shapeArr.Count - 1].material() + '\n');
}
}
//刪除物件
private void btn_delete_Click(object sender, EventArgs e)
{
shapeArr[int.Parse(txt_deletenum.Text)] = null;
GC.Collect();
GC.WaitForPendingFinalizers();
shapeArr.RemoveAt(int.Parse(txt_deletenum.Text));
//顯示各形狀的數量
ShapeNum();
txt_objdata.Text = strImform1;
foreach (var shape3D in shapeArr)
{
txt_objdata.AppendText(shape3D.material() + '\n');
}
}
//計算體積
private void btn_calculateV_Click(object sender, EventArgs e)
{
switch (cbox_sortmethod.SelectedIndex)
{
case 0:
shapeArr.Sort(CompareByOrder);
break;
case 1:
shapeArr.Sort(CompareByShape);
break;
case 2:
shapeArr.Sort(CompareByMaterial);
break;
case 3:
shapeArr.Sort(CompareByVolume);
break;
case 4:
shapeArr.Sort(CompareByWeight);
break;
default:
MessageBox.Show("未選擇排序方法,請重新選擇!!");
break;
}
//重新清空顯示欄,並重新讀取shapeArr
txt_showVolume.Text = strImform2;
foreach (var shape3D in shapeArr)
{
txt_showVolume.AppendText(shape3D.datadisplay());
}
}
//計算滑動距離
private void btn_calculateScroll_Click(object sender, EventArgs e)
{
txt_showScoll.Text = strImform3;
foreach (var shape3D in shapeArr)
{
IRollable rollable = shape3D as IRollable;
if (rollable != null)
txt_showScoll.AppendText(rollable.ShowRolldistance());
}
}
//不同的比較方法
private int CompareByOrder(Shape3D a, Shape3D b)
{
if (a.Order > b.Order)
return 1;
else
return -1;
}
private int CompareByShape(Shape3D a, Shape3D b)
{
if (a.Shapetype > b.Shapetype)
return 1;
else
return -1;
}
private int CompareByMaterial(Shape3D a, Shape3D b)
{
if (a.Density > b.Density)
return 1;
else
return -1;
}
private int CompareByVolume(Shape3D a, Shape3D b)
{
if (a.volume() > b.volume())
return 1;
else
return -1;
}
private int CompareByWeight(Shape3D a, Shape3D b)
{
if (a.weight() > b.weight())
return 1;
else
return -1;
}
//刪除物件後重新編號
private void btn_ReSortNum_Click(object sender, EventArgs e)
{
for (int i = 0; i < shapeArr.Count; i++)
{
shapeArr[i].Order = i;
}
txt_objdata.Text = null;
foreach (var shape3D in shapeArr)
{
txt_objdata.AppendText(shape3D.material() + '\n');
}
}
//檢查是否有任何方法或參數沒有被設定
private bool CheckChoise()
{
if (cbox_material.SelectedIndex < 0)
{
MessageBox.Show("未選擇任何材質,請重新選擇!!");
return false;
}
else if (cbox_shape.SelectedIndex < 0)
{
MessageBox.Show("未選擇任何形狀,請重新選擇!!");
return false;
}
else if (txt_para1.Text=="")
{
MessageBox.Show("未輸入任何參數,請重新輸入!!");
return false;
}
else if (cbox_shape.SelectedIndex >= 2 && txt_para2.Text=="")
{
MessageBox.Show("仍有參數未輸入,請輸入完畢!!");
return false;
}
else
return true;
}
private void ShapeNum()
{
txt_amount.Text = Convert.ToString(shapeArr.Count);
txt_ballnum.Text = Convert.ToString(Ball.Amount);
txt_cubenum.Text = Convert.ToString(Cube.Amount);
txt_cylindernum.Text = Convert.ToString(Cylinder.Amount);
txt_pyramidnum.Text = Convert.ToString(Pyramid.Amount);
}
}
}
Shape3D.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW8
{
abstract class Shape3D
{
//Fields
protected double density;
protected int order;
protected ShapeType.Type shapetype;
//Contructor
public Shape3D()
{
Density = 0;
}
public Shape3D(double density)
{
Density = density;
}
//Atributes
public double Density
{
get { return density;}
set
{
if (value <= 0)
density = 0;
else
density =value;
}
}
public int Order
{
get { return order; }
set { order = value; }
}
public int Shapetype
{
get { return (int)shapetype; }
}
//abstract method
public abstract double volume();
public abstract string material();
//method
public double weight()
{
return volume()*Density;
}
public string datadisplay()
{
string str=null;
str += material();
str += '\t';
str += String.Format("{0:F2}", volume());
str += '\t';
str += String.Format("{0:F2}",weight());
str += '\n';
return str;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW8
{
class Ball:Shape3D,IRollable
{
//Fields
private double radius;
private string shapename = "Ball";
private static int amount = 0;
//contructor
public Ball(double radius, double density)
: base(density)
{
Radius = radius;
shapetype = ShapeType.Type.Ball;
amount++;
}
//destructor
~Ball()
{
amount--;
}
//Atributes
public double Radius
{
get{return radius;}
set{radius=value;}
}
public static int Amount
{
get { return amount; }
}
//override method
public override double volume()
{
return 4.0 / 3 * GeoConstant.pi * Math.Pow(Radius, 3);
}
public override string material()
{
string str = null;
str += Convert.ToString(Order);
str += '\t';
str += shapename;
str += '\t';
str += Convert.ToString(Radius);
str += '\t';
str += '\t';
str += '\t';
str += String.Format("{0:F2}", Density);
return str;
}
public double Rolldistance()
{
return Radius * Radius;
}
public string ShowRolldistance()
{
return material() + '\t' + String.Format("{0:F2}", Rolldistance()) + '\n';
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW8
{
class Cube : Shape3D
{
//Fields
private double side;
private string shapename = "Cube";
private static int amount = 0;
//contructor
public Cube(double side, double density)
: base(density)
{
Side = side;
shapetype = ShapeType.Type.Cube;
amount++;
}
//destructor
~Cube()
{
amount--;
}
//Atributes
public double Side
{
get { return side; }
set { side = value; }
}
public static int Amount
{
get { return amount; }
}
//override method
public override double volume()
{
return Math.Pow(Side, 3);
}
public override string material()
{
string str = null;
str += Convert.ToString(Order);
str += '\t';
str += shapename;
str += '\t';
str += Convert.ToString(Side);
str += '\t';
str += '\t';
str += '\t';
str += String.Format("{0:F2}", Density);
return str;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW8
{
class Cylinder : Shape3D,IRollable
{
//Fields
private double radius;
private double height;
private string shapename = "Cylinder";
private static int amount = 0;
//contructor
public Cylinder(double radius, double height, double density)
: base(density)
{
Radius = radius;
Height = height;
shapetype = ShapeType.Type.Cylinder;
amount++;
}
//destructor
~Cylinder()
{
amount--;
}
//Atributes
public double Radius
{
get{return radius;}
set{radius=value;}
}
public double Height
{
get { return height; }
set { height = value; }
}
public static int Amount
{
get { return amount; }
}
//override method
public override double volume()
{
return Height * GeoConstant.pi * Math.Pow(Radius, 2);
}
public override string material()
{
string str = null;
str += Convert.ToString(Order);
str += '\t';
str += shapename;
str += '\t';
str += Convert.ToString(Radius);
str += '\t';
str += '\t';
str += Convert.ToString(Height);
str += '\t';
str += String.Format("{0:F2}", Density);
return str;
}
public double Rolldistance()
{
return Radius*5;
}
public string ShowRolldistance()
{
return material()+'\t' + String.Format("{0:F2}", Rolldistance())+'\n';
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW8
{
class Pyramid : Shape3D
{
//Fields
private double side;
private double height;
private string shapename = "Pyramid";
private static int amount = 0;
//contructor
public Pyramid(double side, double height, double density)
: base(density)
{
Side = side;
Height = height;
shapetype = ShapeType.Type.Pyramid;
amount++;
}
//destructor
~Pyramid()
{
amount--;
}
//Atributes
public double Side
{
get { return side; }
set { side = value; }
}
public double Height
{
get { return height; }
set { height = value; }
}
public static int Amount
{
get { return amount; }
}
//override method
public override double volume()
{
return 1.0 / 3 * Math.Pow(Side, 2) * Height;
}
public override string material()
{
string str = null;
str += Convert.ToString(Order);
str += '\t';
str += shapename;
str += '\t';
str += Convert.ToString(Side);
str += '\t';
str += '\t';
str += Convert.ToString(Height);
str += '\t';
str += String.Format("{0:F2}", Density);
return str;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW8
{
interface IRollable
{
double Rolldistance();
string ShowRolldistance();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW8
{
static class ShapeType
{
public enum Type { Unknown = 0, Ball, Cube, Cylinder, Pyramid };
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW8
{
class GeoConstant
{
public static double pi = 3.1415926;
}
}
2014年4月13日 星期日
2014年4月4日 星期五
[Code Review] Team 05 - Hw05
Form1.cs
PokerCard.cs
按我顯示
執行檔
public partial class Form1 : Form
{
CompleteCard PokerCardWeUse=new CompleteCard();
int player1, player2;
public Form1()
{
InitializeComponent();
PokerCardWeUse.startgame();
PokerCardWeUse.shuff();
}
private void button1_Click(object sender, EventArgs e)
{
switch(comboBox1.SelectedIndex)
{
case 0:
MessageBox.Show(PokerCardWeUse.putCard5());
break;
case 1:
player1 = PokerCardWeUse.studHi();
MessageBox.Show("玩家1\n"+PokerCardWeUse.putCard5());
player2 = PokerCardWeUse.studHi();
MessageBox.Show("玩家2\n"+PokerCardWeUse.putCard5());
if (player1 > player2)
MessageBox.Show("玩家1獲勝");
else if (player1 < player2)
MessageBox.Show("玩家2獲勝");
else
MessageBox.Show("雙方和局");
break;
case 2:
MessageBox.Show(PokerCardWeUse.chooseCard());
break;
}
}
}
class PokerCard
{
private int suit;
private int number;
private static string[] suitUse=new string[4]{"\u2660","\u2663","\u2665","\u2666"};
private static string[] numbUse = new string[13] { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
public PokerCard()
{
this.suit = 0;
this.number = 0;
}
public PokerCard(int num)//0-51張牌
{
this.suit = num / 13;
this.number = num % 13;
}
public string name
{
get { return " " + suitUse[suit] + numbUse[number]; }
}
public int Suit
{
get { return suit; }
}
public int Number
{
get { return number; }
}
}
class CompleteCard
{
private PokerCard[] Card = new PokerCard[52];
public int CardNum=0;
private static string[] level = new string[10] { "無對", "一對", "兩對", "三條", "順子", "同花", "胡", "四條", "空", "同花順" };
public void startgame()
{
for(int i=0;i<52 data-blogger-escaped-5="" data-blogger-escaped-a="" data-blogger-escaped-ard="" data-blogger-escaped-ardnum="" data-blogger-escaped-b="" data-blogger-escaped-card="" data-blogger-escaped-cardnum="" data-blogger-escaped-change="" data-blogger-escaped-for="" data-blogger-escaped-i="" data-blogger-escaped-if="" data-blogger-escaped-int="" data-blogger-escaped-level="" data-blogger-escaped-m="" data-blogger-escaped-n="" data-blogger-escaped-name="" data-blogger-escaped-new="" data-blogger-escaped-pokercard="" data-blogger-escaped-public="" data-blogger-escaped-putcard5="" data-blogger-escaped-rand="new" data-blogger-escaped-random="" data-blogger-escaped-shuff="" data-blogger-escaped-string="" data-blogger-escaped-studhi="" data-blogger-escaped-sum="" data-blogger-escaped-void="" data-blogger-escaped-x="">52)
{
CardNum = 0;
shuff();
}
return sum;
}
public string chooseCard()
{
string sum = "";
double zilch=0;//0
double onePair = 0;//1
double twoPairs = 0;//2
double threeofakind = 0;//3
double straight = 0;//4
double flush = 0;//5
double fullhouse = 0;//6
double fourofaKind = 0;//7
double straightFlush = 0;//9
for(int k=0;k<500000 data-blogger-escaped-0:="" data-blogger-escaped-1:="" data-blogger-escaped-1="" data-blogger-escaped-2:="" data-blogger-escaped-3:="" data-blogger-escaped-4:="" data-blogger-escaped-5:="" data-blogger-escaped-5="" data-blogger-escaped-6:="" data-blogger-escaped-7:="" data-blogger-escaped-9:="" data-blogger-escaped-ardnum="" data-blogger-escaped-break="" data-blogger-escaped-cardnum="" data-blogger-escaped-case="" data-blogger-escaped-default:="" data-blogger-escaped-flush="" data-blogger-escaped-fourofakind="" data-blogger-escaped-fullhouse="" data-blogger-escaped-if="" data-blogger-escaped-k="" data-blogger-escaped-onepair="" data-blogger-escaped-straight="" data-blogger-escaped-straightflush="" data-blogger-escaped-studhi="" data-blogger-escaped-switch="" data-blogger-escaped-threeofakind="" data-blogger-escaped-twopairs="" data-blogger-escaped-zilch=""> 52)
{
CardNum = 0;
shuff();
}
}
sum += "同花順(Straight Flush)" + (straightFlush/5000).ToString()+"%\n";
sum +=" 四條(Four of a Kind)"+(fourofaKind/5000).ToString()+"%\n";
sum +=" 葫蘆(Fullhouse) "+(fullhouse/5000).ToString()+"%\n";
sum +=" 同花(Flush) "+(flush/5000).ToString()+"%\n";
sum +=" 順子(Straight) "+(straight/5000).ToString()+"%\n";
sum +=" 三條(Three of a kind)"+(threeofakind/5000).ToString()+"%\n";
sum +=" 兩對(Two Pairs) "+(twoPairs/5000).ToString()+"%\n";
sum +=" 一對(One Pair) "+(onePair/5000).ToString()+"%\n";
sum +=" 無對(Zilch) " + (zilch/5000).ToString() + "%\n";
return sum;
}
public int studHi()
{
bubbleCard();
int num=0 ;
for(int i=CardNum+1;iCard[j+1].Number)
{
change(j, j + 1);
}
if(Card[j].Number==Card[j+1].Number&&Card[j].Suit>Card[j+1].Suit)
{
change(j, j + 1);
}
}
}
}
}
2014年3月24日 星期一
[Code Review] Team 05 - Hw04
//Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HW4
{
public partial class Form1 : Form
{
CardDeck mydeck = new CardDeck();
public Form1()
{
InitializeComponent();
mydeck.CreateDeck();
mydeck.ResetDeck();
}
private void btn_combobox_Click(object sender, EventArgs e)
{
switch (CBox_select.SelectedIndex)
{
case 0:
mydeck.ResetDeck();
txt_display.AppendText("combobox按花色牌列已被選定"+'\n');
messageshow();
break;
case 1:
mydeck.Shuffle();
txt_display.AppendText("combobox亂數洗牌已被選定" + '\n');
messageshow();
break;
case 2:
mydeck.resetbyrank();
txt_display.AppendText("combobox按點數大小排列已被選定" + '\n');
messageshow();
break;
default:
txt_display.AppendText("未選擇方法!!" + '\n');
break;
}
}
private void btn_checkbox_Click(object sender, EventArgs e)
{
if (checkBox_select1.Checked)
{
mydeck.ResetDeck();
txt_display.AppendText("checkBox按花色牌列已被選定" + '\n');
messageshow();
}
if (checkBox_select2.Checked)
{
mydeck.Shuffle();
txt_display.AppendText("checkBox亂數洗牌已被選定" + '\n');
messageshow();
}
if (checkBox_select3.Checked)
{
mydeck.resetbyrank();
txt_display.AppendText("checkBox按點數大小排列已被選定" + '\n');
messageshow();
}
}
private void messageshow()
{
string str=null;
for (int i=0; i < 52; i++)
{
str += mydeck.Cards[i].SuitToUni();
str += mydeck.Cards[i].RankToStr();
str += " ";
if (i % 13 == 12)
str += '\n';
}
MessageBox.Show(str);
}
}
}
//CardDeck.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW4
{
class CardDeck
{
public PokerCard[] Cards = new PokerCard[52];
public void CreateDeck()
{
int i;
for (i = 0; i < 52; i++)
Cards[i] = new PokerCard();
}
public void ResetDeck() //牌堆回復原始狀態
{
int i ;
for (i = 0; i < 52; i++)
{
Cards[i].Suit = i/13+3;
Cards[i].Rank = i%13+1;
}
}
public void Shuffle() //洗牌
{
Random rand = new Random();
for (int i = 0; i < 52; i++)
{
int n1 = rand.Next(52);
PokerCard temp = Cards[i];
Cards[i] = Cards[n1];
Cards[n1] = temp;
}
}
public void resetbyrank()
{
int i;
for (i = 0; i < 52; i++)
{
Cards[i].Suit = i % 4 + 3;
Cards[i].Rank = i / 4 + 1;
}
}
}
}
//PokerCard.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 char SuitToAscii()
{
return Convert.ToChar(Suit);
}
public string SuitToUni()
{
switch (Suit)
{
case 3:
return "\u2665";
case 4:
return "\u2666";
case 5:
return "\u2663";
case 6:
return "\u2660";
default:
return " ";
}
}
}
}
訂閱:
文章 (Atom)

