棒球.exe
2014年6月26日 星期四
2014年5月4日 星期日
[Code Review] Team 08 - Hw08
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 double[] dens = new double[] { 11.34, 8.9, 2.7 };//鉛銅鋁的密度陣列
List shapeArr = new List();
public Form1()
{
InitializeComponent();
//初始化版面,FrontPanel設定上ListView內容將View設定為"Details"
listView_temp.Columns.Add("形狀", 60, HorizontalAlignment.Center);
listView_temp.Columns.Add("材質", 60, HorizontalAlignment.Center);
listView_Output.Columns.Add("形狀", 60, HorizontalAlignment.Center);
listView_Output.Columns.Add("材質", 60, HorizontalAlignment.Center);
listView_Output.Columns.Add("體積", 80, HorizontalAlignment.Center);
listView_Output.Columns.Add("重量", 80, HorizontalAlignment.Center);
}
private void btn_Caculate_Click(object sender, EventArgs e)
{
Sort();
listView_Output.Items.Clear();
PrintAllData();
}
private void btn_Add_Click(object sender, EventArgs e)
{
if (!CheckData(cbox_shape.SelectedIndex)) //檢查是否有資料忘記填寫
return;
switch (cbox_shape.SelectedIndex)
{
//定義各形狀之建構子傳入參數為參數一,參數二,材料,密度
case 0: //圓球
Ball ball = new Ball(double.Parse(txtb_left.Text), dens[cbox_material.SelectedIndex], cbox_material.SelectedItem.ToString());
shapeArr.Add(ball);
ball.Order = shapeArr.Count;
txtb_BallNum.Text = Ball.Amount.ToString();
break;
case 1: //金字塔
Pyramid pyr = new Pyramid(double.Parse(txtb_left.Text), double.Parse(txtb_right.Text), dens[cbox_material.SelectedIndex], cbox_material.SelectedItem.ToString());
shapeArr.Add(pyr);
pyr.Order = shapeArr.Count;
txtb_PyrNum.Text = Pyramid.Amount.ToString();
break;
case 2: //圓柱
Cylinder cyl = new Cylinder(double.Parse(txtb_left.Text), double.Parse(txtb_right.Text), dens[cbox_material.SelectedIndex], cbox_material.SelectedItem.ToString());
shapeArr.Add(cyl);
cyl.Order = shapeArr.Count;
txtb_CylNum.Text = Cylinder.Amount.ToString();
break;
case 3:
Cube cub = new Cube(double.Parse(txtb_left.Text), dens[cbox_material.SelectedIndex], cbox_material.SelectedItem.ToString());
shapeArr.Add(cub);
cub.Order = shapeArr.Count;
txtb_CubNum.Text = Cube.Amount.ToString();
break;
}
txt_TolalNum.Text = Shape.Amount.ToString();
ListViewItem Data = new ListViewItem(shapeArr[Shape.Amount - 1].GetShapeName());
Data.SubItems.Add(shapeArr[Shape.Amount - 1].Material);
listView_temp.Items.Add(Data);
}
//形狀切換
private void cbox_shape_SelectedIndexChanged(object sender, EventArgs e)
{
switch (cbox_shape.SelectedIndex)
{
case 0:
lbl_left.Text = "半徑";
txtb_right.Visible = false;
lbl_right.Visible = false;
break;
case 1:
lbl_left.Text = "邊長";
lbl_right.Text = "高";
txtb_right.Visible = true;
lbl_right.Visible = true;
break;
case 2:
lbl_left.Text = "半徑";
lbl_right.Text = "高";
txtb_right.Visible = true;
lbl_right.Visible = true;
break;
case 3:
lbl_left.Text = "邊長";
txtb_right.Visible = false;
lbl_right.Visible = false;
break;
}
}
//將面板重置
private void ResetFrontPanel()
{
txtb_rollOut.Clear();
listView_temp.Items.Clear();
listView_Output.Items.Clear();
}
//列印所有資料
private void PrintAllData()
{
for (int i = 0; i < Shape.Amount; i++)
{
ListViewItem DataMamber = new ListViewItem(shapeArr[i].GetShapeName());
DataMamber.SubItems.Add(shapeArr[i].Material);
DataMamber.SubItems.Add(shapeArr[i].GetVolume().ToString("0.##"));
DataMamber.SubItems.Add(shapeArr[i].GetWeight().ToString("0.##"));
listView_Output.Items.Add(DataMamber);
}
}
private void PrintRollData()
{
foreach (var shape in shapeArr)
{
IRollable iroll = shape as IRollable;
if (iroll != null)
{
txtb_rollOut.AppendText(iroll.RollDist());
}
}
}
//檢查數字是否有輸入
private bool CheckData(int flag)
{
switch (flag)
{
case 0:
case 3:
if (txtb_left.Text == "")
{
MessageBox.Show("資料請輸入完整 !");
return false;
}
break;
case 1:
case 2:
if (txtb_left.Text == "" || txtb_right.Text == "")
{
MessageBox.Show("資料請輸入完整 !");
return false;
}
break;
}
if (cbox_material.Text == "請選擇" || cbox_shape.Text == "請選擇")
{
MessageBox.Show("請選擇形狀與材質 !");
return false;
}
return true;
}
private void btn_clear_Click(object sender, EventArgs e)
{
ResetFrontPanel();
shapeArr.Clear();
Shape.Amount = 0;
Ball.Amount = 0;
Pyramid.Amount = 0;
Cylinder.Amount = 0;
Cube.Amount = 0;
txtb_BallNum.Text = "0";
txtb_CylNum.Text = "0";
txtb_PyrNum.Text = "0";
txtb_CubNum.Text = "0";
txt_TolalNum.Text = "0";
txtb_left.Text = "";
txtb_right.Text = "";
cbox_material.Text = "請選擇";
cbox_shape.Text = "請選擇";
cbx_sort.Text = "請選擇";
}
private void btn_Roll_Click(object sender, EventArgs e)
{
txtb_rollOut.Clear();
PrintRollData();
}
private void btn_cancel_Click(object sender, EventArgs e)
{
int order = int.Parse(txtb_order.Text);
if (shapeArr.Count < order)
return;
shapeArr[order] = null;
GC.Collect();
GC.WaitForPendingFinalizers();
shapeArr.RemoveAt(order);
txtb_BallNum.Text = Ball.Amount.ToString();
txtb_PyrNum.Text = Pyramid.Amount.ToString();
txtb_CylNum.Text = Cylinder.Amount.ToString();
txtb_CubNum.Text = Cube.Amount.ToString();
txt_TolalNum.Text = Shape.Amount.ToString();
}
private void Sort()
{
switch(cbx_sort.SelectedIndex)
{
case 0:
shapeArr.Sort(CompareByOrder);
break;
case 1:
shapeArr.Sort(CompareByShape);
break;
case 2:
shapeArr.Sort(CompareByDensity);
break;
case 3:
shapeArr.Sort(CompareByVolume);
break;
case 4:
shapeArr.Sort(CompareByWeight);
break;
default:
break;
}
}
private int CompareByOrder(Shape a,Shape b)
{
if (a.Order > b.Order)
return 1;
else
return -1;
}
private int CompareByShape(Shape a,Shape b)
{
if (a.ShapeType > b.ShapeType)
return 1;
else
return -1;
}
private int CompareByDensity(Shape a,Shape b)
{
if (a.Density > b.Density)
return 1;
else
return -1;
}
private int CompareByVolume(Shape a,Shape b)
{
if (a.GetVolume() > b.GetVolume())
return 1;
else
return -1;
}
private int CompareByWeight(Shape a,Shape b)
{
if (a.GetWeight() > b.GetWeight())
return 1;
else
return -1;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW8
{
abstract class Shape
{
//****************成員*************
protected static double pi = 3.1415926;
private static int amount = 0; //用來紀錄全部共有幾個形狀
private string material = "";
private double density = 0;
protected int order;
protected ShapeTypes.Types shapetype;
//****************屬性*************
public double Density
{
set
{
if (value >= 0)
density = value;
else
density = 0;
}
get { return density; }
}
public string Material
{
set { material = value; }
get { return material; }
}
public static int Amount
{
set { amount = value; }
get { return amount; }
}
public int Order
{
set { order = value; }
get { return order; }
}
public int ShapeType
{
get { return (int)shapetype; }
}
//***************建構子************
public Shape()
{
amount++;
}
~Shape()
{
amount--;
}
//***************方法**************
abstract public double GetVolume();
abstract public double GetWeight();//抽象方法,可讓各子類別計算各自重量
abstract public string GetShapeName();//抽象方法,各子類別return形狀名稱
}
static class ShapeTypes
{
public enum Types { Unknown = 0, Ball, Cylinder, Pyramid,Cube };
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW8
{
class Cube:Shape
{
//*********成員**********
private static int amount = 0;
private static string ShapeName = "正方體";
private double side = 0;
//*********屬性**********
public double Side
{
set
{
if (value >= 0)
side = value;
else
side = 0;
}
get { return side; }
}
new public static int Amount
{
get { return amount; }
set { amount = value; }
}
//**********建構子********
public Cube(double s, double d, string m)
{
Material = m;
Side = s;
Density = d;
shapetype = ShapeTypes.Types.Cube;
amount++;
}
~Cube()
{
amount--;
}
//*********方法**********
public override double GetVolume()
{
return Side * Side * Side;
}//虛擬方法,可讓各子類別計算各自體積
public override string GetShapeName()
{
return ShapeName;
}
public override double GetWeight()
{
return GetVolume() * Density;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW8
{
class Ball : Shape,IRollable
{
//*********成員**********
private static int amount = 0;
private static string ShapeName = "圓球";
private double radius = 0;
//*********屬性**********
public double Radius
{
set
{
if (value >= 0)
radius = value;
else
radius = 0;
}
get { return radius; }
}
new public static int Amount
{
get { return amount; }
set { amount = value; }
}
//**********建構子********
public Ball(double r, double d, string m)
{
Material = m;
Radius = r;
Density = d;
shapetype = ShapeTypes.Types.Ball;
amount++;
}
~Ball()
{
amount--;
}
//*********方法**********
public override double GetVolume()
{
return 4.0 * pi * Radius * Radius * Radius / 3.0;
}//虛擬方法,可讓各子類別計算各自體積
public override string GetShapeName()
{
return ShapeName;
}
public override double GetWeight()
{
return GetVolume() * Density;
}
public string RollDist()
{
string str_Output = "";
str_Output += GetShapeName() + "\t" + Radius.ToString() + "\t" + "\t" + Density.ToString()
+ "\t" + (Radius * Radius).ToString("#.00") + "\n";
return str_Output;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW8
{
class Cylinder : Shape,IRollable
{
//*********成員**********
private static int amount = 0;
private static string ShapeName = "圓柱";
private double parameter = 0;
private double height = 0;
//**********屬性**********
public double Parameter
{
set
{
if (value >= 0)
parameter = value;
else
parameter = 0;
}
get { return parameter; }
}
public double Height
{
set
{
if (value >= 0)
height = value;
else
height = 0;
}
get { return height; }
}
new public static int Amount
{
get { return amount; }
set { amount = value; }
}
//**********建構子********
public Cylinder(double p, double h, double d, string m)
{
Material = m;
Parameter = p;
Height = h;
Density = d;
shapetype = ShapeTypes.Types.Cylinder;
amount++;
}
~Cylinder()
{
amount--;
}
//**********方法**********
public override double GetVolume()
{
return Parameter * Parameter * pi * Height;
}//虛擬方法,可讓各子類別計算各自體積
public override string GetShapeName()
{
return ShapeName;
}
public override double GetWeight()
{
return GetVolume() * Density;
}
public string RollDist()
{
string str_Output = "";
str_Output += GetShapeName() + "\t" +Parameter.ToString("#.##")+"\t"+Height.ToString("#.##")+"\t"+ Density.ToString("#.##") + "\t" + (Parameter * Parameter).ToString("#.##") + "\n";
return str_Output;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW8
{
class Pyramid : Shape
{
//*********成員**********
private static int amount = 0;
private static string ShapeName = "金字塔";
private double length = 0;
private double height = 0;
//***********屬性**************
public double Length
{
set
{
if (value >= 0)
length = value;
else
length = 0;
}
get { return length; }
}
public double Height
{
set
{
if (value >= 0)
height = value;
else
height = 0;
}
get { return height; }
}
new public static int Amount
{
get { return amount; }
set { amount = value; }
}
//**********建構子********
public Pyramid(double l, double h, double d, string m)
{
Material = m;
Length = l;
Height = h;
Density = d;
shapetype = ShapeTypes.Types.Pyramid;
amount++;
}
~Pyramid()
{
amount--;
}
//***********方法**************
public override double GetVolume()
{
return Length * Length * Height / 3.0;
}//虛擬方法,可讓各子類別計算各自體積
public override string GetShapeName()
{
return ShapeName;
}
public override double GetWeight()
{
return GetVolume() * Density;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HW8
{
interface IRollable
{
string RollDist();//介面方法,滾動距離
}
}
2014年4月12日 星期六
2014年4月7日 星期一
[Code Review] Team 08 - Hw05 (修改)
HandCard.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace homework5
{
class HandCard
{
public PokerCard[] hand = new PokerCard[5];
private int amount = 0;
private int maxRank = 0;
private int secRank = 0;
private int thrRank = 0;
private string cardtype = "";
private int cardtypenum = 0;
private enum eCardType {HighCard=0,OnePair,TwoPair,ThreeOfaKing,Straight,Flush,FullHouse,FourOfaKing,StraightFlush}
public HandCard()
{
for (int i = 0; i < 5; i++)
{
hand[i] = new PokerCard();
}
}
public void SortByRank()
{
//bubble sort
PokerCard ChangeCard;
for (int i = hand.GetUpperBound(0); i > 0; i--)
{
for (int j = 0; j < i; j++)
{
if (hand[j].Rank > hand[j + 1].Rank)
{
ChangeCard = hand[j];
hand[j] = hand[j+1];
hand[j+1] = ChangeCard;
}
}
}
}
public void GetCardType()
{
//同花順(Straight Flush)n = 8
//四條(Four of a Kind)n = 7
//葫蘆(Fullhouse) n = 6
//同花(Flush)n = 5
//順子(Straight)n = 4
//三條(Three of a kind)n = 3
//兩對(Two Pairs)n = 2
//一對(One Pair)n = 1
//無對(High Card) n = 0
SortByRank();
if (CheckStraight() == "Stragiht" && CheckFlush() == "Flush") // 同花順 8
{
GetMaxRank();
CardType = "Straight Flush";
CardTypeNum = (int)eCardType.StraightFlush;
return;
}
else if (CheckStraight() == null && CheckFlush() == "Flush") // 同花 5
{
GetMaxRank();
CardType = "Flush";
CardTypeNum = (int)eCardType.Flush;
return;
}
else if (CheckStraight() == "Stragiht" && CheckFlush() == null) // 順子 4
{
GetMaxRank();
CardType = "Straight";
CardTypeNum = (int)eCardType.Straight;
return;
}
else if(CheckPair() != null)
{
CardType = CheckPair();
}
else
{
GetMaxRank();
CardType = "High Card";
CardTypeNum = (int)eCardType.HighCard;
return;
}
}
//函數內容: 檢查是否為順子
//函數說明: 第2張是第1張 + 1 以此類推
//須注意 A 10 J Q K 特殊例子
public string CheckStraight()
{
int start = 0;
if (hand[0].Rank == 1) // A,10,J,Q,K 特例
{
start = 10;
for (int i = 0; i <= hand.GetUpperBound(0)-1; i++)
if (hand[i+1].Rank != start + i)
return null;
return "Stragiht";
}
start = hand[0].Rank;
for (int i = 0; i <= hand.GetUpperBound(0); i++)
if (hand[i].Rank != start + i)
return null;
return "Stragiht";
}
//函數內容: 檢查是否為同花
//函數說明: 只要有一張不同即null
public string CheckFlush()
{
int start = hand[0].Suit;
foreach (PokerCard card in hand)
if (card.Suit != start)
return null;
return "Flush";
}
//函數內容: 檢查是否為對子(包含 三條 葫蘆 鐵支)
//函數說明: 先使用GETMAX()函數取得最長值
//再依各情況分析
public string CheckPair()
{
SortByRank();
int sum = GetMax(); // 取得相同點數最長的數量
// 4 張 只有鐵支
if (sum == 4)
{
CardTypeNum = (int)eCardType.FourOfaKing;
return "Four Of a King";
}
// 3 張 有葫蘆 跟 三條
// 葫蘆判斷 OOO XX 或 OO XXX 所以 1.2 與 3.4 張必相同
// 為非則為三條
if (sum == 3)
{
if (hand[0].Rank == hand[1].Rank && hand[3].Rank == hand[4].Rank)
{
CardTypeNum = (int)eCardType.FullHouse;
return "Full House";
}
else
{
CardTypeNum = (int)eCardType.ThreeOfaKing;
return "Three Of aKing";
}
}
// 2張 有 Two pair 跟 One pair
// two pair排列組合 有 2 1 2 或 2 2 1 或 1 2 2 等情形
// 再分別對各情形處理即可
if (sum == 2)
{
if (hand[0].Rank == hand[1].Rank)
{
if (hand[3].Rank == hand[4].Rank||hand[2].Rank == hand[3].Rank)
{
secRank = hand[0].Rank; // 第二組PAIR
thrRank = hand[2].Rank; // 雜牌
CardTypeNum = (int)eCardType.TwoPair;
return "Two Pair";
}
else // 1 1 2 3 4 情形
{
secRank = hand[4].Rank; // 單支 最後一張
secRank = hand[3].Rank; // 單支 倒數第二張
CardTypeNum = (int)eCardType.OnePair;
return "One Pair";
}
}
else
{
if (hand[1].Rank == hand[2].Rank && hand[3].Rank == hand[4].Rank) // O XX WW 情形
{
secRank = hand[2].Rank; // 第二組PAIR
thrRank = hand[0].Rank; // 雜牌
CardTypeNum = (int)eCardType.TwoPair;
return "Two Pair";
}
else
{
//ONE PAIR牌剩下的三種情形 把最大 中間 第三 找到
if(hand[4].Rank == hand[3].Rank) //1 2 3 4 4 情形
{
secRank = hand[2].Rank;
thrRank = hand[1].Rank;
}
else if (hand[3].Rank == hand[2].Rank) // 1 2 3 3 4 情形
{
secRank = hand[4].Rank;
thrRank = hand[1].Rank;
}
else if (hand[2].Rank == hand[1].Rank) // 1 2 2 3 4 情形
{
secRank = hand[4].Rank;
thrRank = hand[3].Rank;
}
CardTypeNum = (int)eCardType.OnePair;
return "One Pair";
}
}
}
return null;
}
//函數內容:取得最大相同牌數,並用maxRank紀錄最多相同牌的值
//函數說明:
//3 3 2 2 2 回傳 3 並記錄 2
//3 2 2 2 2 回傳 4 並紀錄 2
//1 2 3 3 4 回傳 2 並記錄 3
//1 2 3 4 5 回傳 1
//以此類推
public int GetMax() //取得最多相同牌數
{
int count = 0;
int max = 1;
int last = 0;
for (int j = 0; j < 5; j++)
{
if (last != hand[j].Rank)
{
last = hand[j].Rank;
for (int i = j; i < 5; i++)
{
if (last == hand[i].Rank)
count++;
}
if (count > max)
{
max = count; // 紀錄長度
if (last == 1)
maxRank = last + 13; // 紀錄點數
else
maxRank = last;
}
}
count = 0;
}
return max;
}
//函數內容: 一般情況下判定最大張的牌並記錄在maxRank值內 (雜牌.順子.同花.同花順)
public void GetMaxRank()
{
if (hand[0].Rank == 1)
{
maxRank = hand[0].Rank + 13; // 若A為最大,A = 14點
secRank = hand[4].Rank;
thrRank = hand[3].Rank;
}
else
{
maxRank = hand[4].Rank; //最大張為 最後一張牌 (A 例外)
secRank = hand[3].Rank;
thrRank = hand[2].Rank;
}
}
//函數內容: 增加一張手牌
//函數說明: amount紀錄目前手牌數量,若超過傳回false
public bool Add(PokerCard c)
{
if (c == null || amount == 5)
return false;
hand[amount] = c;
amount++;
return true;
}
//函數內容: 兩張手牌比較牌的大小
//函數說明: 先比較牌型,牌型較大者獲勝
//牌行相同則比較最大張牌,若相同則在比較下一張,直到第三張
public bool CombatTo(HandCard p2)
{
int P1CardType = CardTypeNum;
int P2CardType = p2.CardTypeNum;
if (P1CardType > P2CardType)
return true;
else if (P1CardType < P2CardType)
return false;
else //牌型相同 則比最大張
{
if (MaxRank > p2.MaxRank)
return true;
else if (MaxRank < p2.MaxRank)
return false;
else // 最大張相同 則比第二大張
{
if (SecRank > p2.SecRank)
return true;
else if (SecRank < p2.SecRank)
return false;
else// 第二大張相同 則比第三大張
{
if (ThrRank > p2.ThrRank)
return true;
else if (ThrRank < p2.ThrRank)
return false;
}
}
}
//要是第三大張在比較點數總和
int player1Sum = 0;
int player2Sum = 0;
for (int i = 0; i < 5; i++)
{
player1Sum += hand[i].Rank;
player2Sum += p2.hand[i].Rank;
}
if (player1Sum > player2Sum)
return true;
else if (player1Sum < player2Sum)
return false;
//Default
return true;
}
public string CardType
{
get
{
if (cardtype == "")
GetCardType();
return cardtype;
}
set { cardtype = value; }
}
public int CardTypeNum
{
get
{
if (cardtypenum == 0)
GetCardType();
return cardtypenum;
}
set
{
if (value > 8 || value < 0)
cardtypenum = 0;
else
cardtypenum = value;
}
}
public int MaxRank
{
get { return maxRank; }
}
public int SecRank
{
get { return secRank; }
}
public int ThrRank
{
get { return thrRank; }
}
}
}
2014年4月6日 星期日
2014年3月24日 星期一
[Code Review] Team 08 - Hw04
PokerCard 視窗版 PokerCard.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WindowsFormsApplication1
{
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 SuitToUniCode()
{
switch (Suit)
{
case 0:
return "\u2663";
case 1:
return "\u2666";
case 2:
return "\u2665";
default:
return "\u2660";
}
}//將花色轉為 UniCode 字元碼
}
}
CarDeck.cs: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WindowsFormsApplication1
{
class CarDeck
{
public PokerCard[] Cards = new PokerCard[52];
public void CreateDeck()
{
for (int i = 0; i < 52; i++)
Cards[i] = new PokerCard();
}//產生出52個PokerCard的物件
public void ResetDeck()
{
for (int i = 0; i < 52; i++)
{
Cards[i].Rank = i % 13 + 1;
Cards[i].Suit = i / 13;
}
}//牌堆回復原始狀態
public void Shuffle()
{
Random r = new Random();
PokerCard temp;
int j;
for (int i = 0; i < 52; i++)
{
j = r.Next(52);
temp = Cards[i];
Cards[i] = Cards[j];
Cards[j] = temp;
}
}//洗牌
public void ResetByNum()
{
for (int i = 0; i < 52; i++)
{
Cards[i].Rank = (i + 4) / 4; ;
Cards[i].Suit = (i + 4) % 4;
}
}
}
}
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
CarDeck deck = new CarDeck();
PokerCard Cards = new PokerCard();
deck.CreateDeck();
switch (cbox_select.SelectedIndex)
{
case 0:
btxt_out.AppendText("ComboBox按照花色排列 已被選定\n");
deck.ResetDeck();
MessageBox.Show(PrintDeck(deck));
break;
case 1:
btxt_out.AppendText("ComboBox洗牌 已被選定\n");
deck.ResetDeck();
deck.Shuffle();
MessageBox.Show(PrintDeck(deck));
break;
case 2:
btxt_out.AppendText("CheckBox按照數字排列 已被選定\n");
deck.ResetDeck();
deck.ResetByNum();
MessageBox.Show(PrintDeck(deck));
break;
}
}
private void btn_correct2_Click(object sender, EventArgs e)
{
CarDeck deck = new CarDeck();
PokerCard Cards = new PokerCard();
deck.CreateDeck();
if (checkBox1.Checked)
{
deck.ResetDeck();
btxt_out.AppendText("CheckBox按照花色排列 已被選定\n");
MessageBox.Show(PrintDeck(deck));
}
if (checkBox2.Checked)
{
deck.ResetDeck();
deck.Shuffle();
btxt_out.AppendText("CheckBox洗牌 已被選定\n");
MessageBox.Show(PrintDeck(deck));
}
if (checkBox3.Checked)
{
deck.ResetDeck();
deck.ResetByNum();
btxt_out.AppendText("CheckBox按照點數排列 已被選定\n");
MessageBox.Show(PrintDeck(deck));
}
}
private void cbox_select_SelectedIndexChanged(object sender, EventArgs e)
{
}
private string PrintDeck(CarDeck D)
{
string StrDisplay = "";
for (int i = 0; i < 52; i++)
{
StrDisplay += PrintCards(D.Cards[i]) + " ";
if ((i + 1) % 13 == 0)
{
StrDisplay += "\n";
}
}
return StrDisplay;
}
private string PrintCards(PokerCard C)
{
string CardSum = C.RankToStr() + C.SuitToUniCode();
return CardSum;
}
}
}
訂閱:
文章 (Atom)