2014年3月24日 星期一
[Code Review] Team 04 - 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;
using quiz4_40273040H;
namespace HW4
{
public partial class Form1 : Form
{
private CardDeck deck = null;
public Form1()
{
InitializeComponent();
InitDeck();
}
private void InitDeck()
{
deck=new CardDeck();
deck.CreateDeck();
deck.ResetDeck();
}
private void Print(CardDeck Deck1)
{
string x1="";
for (int i = 0; i < 52; i++)
{
x1 = string.Concat(x1, Deck1.Cards[i].RankToStr(), Deck1.Cards[i].SuitToAscii()," ");
if ((i + 1) % 13 == 0)
x1 = string.Concat(x1, "\n");
}
MessageBox.Show(x1);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (null == deck)
{
deck = new CardDeck();
deck.CreateDeck();
deck.ResetDeck();
}
tex_Message.Text = "";
switch (cbox_Select.SelectedIndex)
{
case 0:
tex_Message.AppendText("Combokbox 按花色排列 已被選定"+'\n');
deck.ResetDeck();
Print(deck);
break;
case 1:
tex_Message.AppendText("Combobox 亂數排列 已被選定"+'\n');
deck.Shuffle();
Print(deck);
break;
case 2:
tex_Message.AppendText("Combobox 按點數大小" + '\n');
deck.OrderByRank();
Print(deck);
break;
}
}
private void button2_Click(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
tex_Message.AppendText("Checkbox 按花色排列 已被選定" + '\n');
deck.ResetDeck();
Print(deck);
}
if (checkBox2.Checked)
{
tex_Message.AppendText("Checkbox 亂數排列 已被選定" + '\n');
deck.Shuffle();
Print(deck);
}
if (checkBox3.Checked)
{
tex_Message.AppendText("Checkbox 按點數大小 已被選定" + '\n');
deck.OrderByRank();
Print(deck);
}
}
}
}
CardDeck.cs using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace quiz4_40273040H
{
class CardDeck
{
public PokerCard[] Cards = new PokerCard[52];
public void CreateDeck()
{
for (int i = 0; i < Cards.GetLength(0); i++)
{
Cards[i]=new PokerCard();
}
}
public void ResetDeck()
{
for (int i = 0; i < 52; i++)
{
int j = i;
Cards[i].Suit = i/13+3;
Cards[i].Rank=j%13+1;
}
}
public void Shuffle()
{
Random rand = new Random();
PokerCard temp=new PokerCard();
int j;
for (int i = 0; i < 52; i++)
{
j=rand.Next(52);
temp = Cards[i];
Cards[i] = Cards[j];
Cards[j] = temp;
}
}
public void OrderByRank()
{
int i,pass;
PokerCard temp=new PokerCard();
for(pass=0;pass<51;pass++)
{
for(i=0;i<51-pass;i++)
{
if(Cards[i].Rank>=Cards[i+1].Rank)
{
temp=Cards[i];
Cards[i]=Cards[i+1];
Cards[i+1]=temp;
}
}
}
}
}
}
PokerCardcs.cs using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace quiz4_40273040H
{
class PokerCard
{
public int Suit; //花色
public int Rank; //點數
public string RankToStr()
{
switch (Rank)
{
case 1:
return (" A");
break;
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
return string.Concat(" ", Rank.ToString());
case 10:
return Rank.ToString();
case 11:
return (" J");
break;
case 12:
return (" Q");
break;
case 13:
return (" K");
break;
default:
return "";
}
}//將點數轉為字串
public string SuitToAscii()
{
string Str_Suit="";
switch(Suit)
{
case 3:
Str_Suit="\u2665";
break;
case 4:
Str_Suit="\u2666";
break;
case 5:
Str_Suit = "\u2663";
break;
case 6:
Str_Suit = "\u2660";
break;
}
return Str_Suit;
}
}
}
[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;
}
}
}
[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 " ";
}
}
}
}
[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;
}
}
}
[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;
}
}
}
test
//Ch05_01: MyFirstWinApp - 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 MyFirstWinApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("按我!");
}
}
}
[Code Review] Team 09 - Hw04
我先說自己覺得寫很爛的地方: 1. SuitToUnicode()沒用陣列,因為這次都在看新聞,寫得很倉促 2. Sort用最笨演算法(好像有內建Sort?) 3. Message輸出還是無法對齊,"\t"寬度會超過
//這是Program.cs******************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HW4___WinForm_Getting_start
{
class PokerCard
{
public int Rank; //點數
public int Suit; //花色
private static string[] strRank = new string[13] { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
public string RankToStr() //將點數轉為字串
{
return strRank[Rank];
}
public char SuitToAscii() //將花色轉為 Ascii 字元碼
{
return (char)Suit;
}
public String SuitToUnicode() //將花色轉為 Ascii 字元碼
{
switch(Suit)
{
case 3: return "\u2660"; break;
case 4: return "\u2663"; break;
case 5: return "\u2666"; break;
case 6: return "\u2665"; break;
}
return "ERROR";
}
}
class CardDeck
{
public PokerCard[] Cards;
public CardDeck()
{
Cards = new PokerCard[52];
CreateDeck();
ResetDeck();
}
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].Rank = i % 13;
Cards[i].Suit = (i / 13) + 3;
}
}
public void Shuffle() //洗牌
{
PokerCard TempCard;
Random rand = new Random();
for (int i = 0; i < 52; i++)
{
int A = rand.Next(52);
TempCard = Cards[A];
Cards[A] = Cards[i];
Cards[i] = TempCard;
}
}
public void SortByRank()
{
for (int i = 0; i < Cards.Length - 1; i++)
{
for (int j = 0; i + j < Cards.Length; j++)
{
if (Cards[i].Rank > Cards[i + j].Rank)
Swap(ref Cards[i], ref Cards[i + j]);
}
}
}
public void SortBySuit()
{
for (int i = 0; i < Cards.Length - 1; i++)
{
for (int j = 0; i + j < Cards.Length; j++)
{
if (Cards[i].Suit > Cards[i + j].Suit)
Swap(ref Cards[i], ref Cards[i + j]);
}
}
}
private static void Swap(ref PokerCard Card_A, ref PokerCard Card_B)
{
PokerCard TempCard;
TempCard = Card_A;
Card_A = Card_B;
Card_B = TempCard;
}
}
static class Program
{
///
/// 應用程式的主要進入點。
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
//這是Form1.cs******************************
namespace HW4___WinForm_Getting_start
{
public partial class Form1 : Form
{
CardDeck Carddeck;
public Form1()
{
InitializeComponent();
Carddeck = new CardDeck(); //已經自動初始化, 跟新買的牌一樣
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (0 == comboBox1.SelectedIndex/*按花色排列*/)
txt_Message.AppendText("comboBox 按花色排列 已被選定"+"\n");
if (1 == comboBox1.SelectedIndex/*按大小排列*/)
txt_Message.AppendText("comboBox 按大小排列 已被選定" + "\n");
if (2 == comboBox1.SelectedIndex/*亂數洗牌*/ )
txt_Message.AppendText("comboBox 亂數洗牌 已被選定" + "\n");
}
private void btn_ComboBox_Test_Click(object sender, EventArgs e)
{
String messageString = null;
if (0 == comboBox1.SelectedIndex/*按花色排列*/)Carddeck.SortBySuit();
if (1 == comboBox1.SelectedIndex/*按大小排列*/)Carddeck.SortByRank();
if (2 == comboBox1.SelectedIndex/*亂數洗牌*/ )Carddeck.Shuffle();
for (int i = 0; i < Carddeck.Cards.Length; i++)
{//產生顯示用字串
messageString +=
(Carddeck.Cards[i].Rank == (10 | 12) ? " " : " ") +
Carddeck.Cards[i].RankToStr() +
Carddeck.Cards[i].SuitToUnicode() +
(0 == (i + 1) % 13 ? "\n" : "");
}
MessageBox.Show(messageString);
}
private void chk_SortBy_Suit_CheckedChanged(object sender, EventArgs e)
{//按花色排列
Chk_CheckedChanged();
}
private void chk_SortBy_Rank_CheckedChanged(object sender, EventArgs e)
{//按點數排列
Chk_CheckedChanged();
}
private void chk_SortBy_Rand_CheckedChanged(object sender, EventArgs e)
{
Chk_CheckedChanged();
}
private void Chk_CheckedChanged()
{
if (true == chk_SortBy_Suit.Checked/*按花色排列*/)
txt_Message.AppendText("comboBox 按花色排列 已被選定" + "\n");
if (true == chk_SortBy_Rank.Checked/*按大小排列*/)
txt_Message.AppendText("comboBox 按大小排列 已被選定" + "\n");
if (true == chk_SortBy_Rand.Checked/*亂數洗牌*/ )
txt_Message.AppendText("comboBox 亂數洗牌 已被選定" + "\n");
}
private void btn_CheckBox_Test_Click(object sender, EventArgs e)
{
if (0 == comboBox1.SelectedIndex/*按花色排列*/) Carddeck.SortBySuit();
if (1 == comboBox1.SelectedIndex/*按大小排列*/) Carddeck.SortByRank();
if (2 == comboBox1.SelectedIndex/*亂數洗牌*/ ) Carddeck.Shuffle();
String messageString = null;
for (int i = 0; i < Carddeck.Cards.Length; i++)
{//產生顯示用字串
messageString +=
(Carddeck.Cards[i].Rank == (10|12) ? " " : " ") +
Carddeck.Cards[i].RankToStr() +
Carddeck.Cards[i].SuitToUnicode() +
( 0 == (i + 1) % 13 ? "\n" : "");
}
MessageBox.Show(messageString);
}
}
}
訂閱:
意見 (Atom)