2014年6月23日 星期一
2014年5月4日 星期日
2014年5月1日 星期四
2014年4月13日 星期日
2014年4月4日 星期五
2014年3月24日 星期一
[Code Review] Team 01 - Hw04
Form1.cs
namespace OOPHW4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_ComboBoxTest_Click(object sender, EventArgs e)
{
CardDeck Deck = new CardDeck();
Deck.CreateDeck();
Deck.ResetDeck();
txt_Display.Text = "";
switch (cbo_SetWay.SelectedIndex)
{
case 0:
txt_Display.AppendText("ComboBox按花色排列 已被選定\n");
Deck.ResetDeck();
CardString(Deck);
break;
case 1:
txt_Display.AppendText("ComboBox亂數排列 已被選定\n");
Deck.Shuffle();
CardString(Deck);
break;
case 2:
txt_Display.AppendText("ComboBox按點數大小排列 已被選定\n");
Deck.SetDeckByRank();
CardString(Deck);
break;
default:
break;
}
}
private void btn_CheckBoxTest_Click(object sender, EventArgs e)
{
CardDeck Deck = new CardDeck();
Deck.CreateDeck();
Deck.ResetDeck();
txt_Display.Text = "";
if (chk_SetBySuit.Checked)
{
txt_Display.AppendText("CheckBox按花色排列 已被選定\n");
Deck.ResetDeck();
CardString(Deck);
}
if (chk_SetByRand.Checked)
{
txt_Display.AppendText("CheckBox亂數排列 已被選定\n");
Deck.Shuffle();
CardString(Deck);
}
if (chk_SetByRank.Checked)
{
txt_Display.AppendText("CheckBox按點數大小排列 已被選定\n");
Deck.SetDeckByRank();
CardString(Deck);
}
}
static void CardString(CardDeck deck)
{
string S="";
for (int i = 0; i <52 data-blogger-escaped-0="" data-blogger-escaped-anktostr="" data-blogger-escaped-deck.cards="" data-blogger-escaped-i="" data-blogger-escaped-if="" data-blogger-escaped-messagebox.show="" data-blogger-escaped-n="" data-blogger-escaped-pre="" data-blogger-escaped-s="" data-blogger-escaped-uittounicode="">
CardDeck.cs
namespace OOPHW4
{
class CardDeck
{
public PokerCard[] Cards = new PokerCard[52];
public void CreateDeck() //產生出52個PokerCard的物件
{
for (int i = 0; i < 52; i++)
{
Cards[i] = new PokerCard();
}
}
public void ResetDeck() //牌堆回復原始狀態
{
for (int i = 0; i < 52; i++)
{
Cards[i].Suit = i / 13 + 3;
Cards[i].Rank = i % 13 + 1;
}
}
public void Shuffle() //洗牌
{
Random rand = new Random();
PokerCard temp = new PokerCard();
for (int i = 0; i < 52; i++)
{
int T = rand.Next(52);
temp = Cards[i];
Cards[i] = Cards[T];
Cards[T] = temp;
}
}
public void SetDeckByRank()
{
for (int i = 0; i < 52; i++)
{
Cards[i].Suit = i % 4 + 3;
Cards[i].Rank = i /4 + 1;
}
}
}
}
PokerCard.cs
namespace OOPHW4
{
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() //將花色轉為 Unicode
{
string S;
switch(Suit)
{
case 3:
S = "\u2665";
break;
case 4:
S = "\u2666";
break;
case 5:
S = "\u2663";
break;
case 6:
S = "\u2660";
break;
default:
S = "";
break;
}
return S;
}
}
}
訂閱:
文章 (Atom)