Form 6 Form 7 Windows Forms Application 1

  • Slides: 107
Download presentation

Form 6

Form 6

Form 屬性 7

Form 屬性 7

Windows. Forms. Application 1. Program. cs (1/2) using System; System. Collections. Generic; System. Linq;

Windows. Forms. Application 1. Program. cs (1/2) using System; System. Collections. Generic; System. Linq; System. Windows. Forms; namespace Windows. Forms. Application 1 { static class Program { /// <summary> /// 應用程式的主要進入點。 /// </summary> [STAThread] 8

Windows. Forms. Application 1. Program. cs (2/2) static void Main() { Application. Enable. Visual.

Windows. Forms. Application 1. Program. cs (2/2) static void Main() { Application. Enable. Visual. Styles(); Application. Set. Compatible. Text. Rendering. Default(false); Application. Run(new Form 1()); } } } 9

Windows. Forms. Application 1. Form 1. Designer. cs (1/3) namespace Windows. Forms. Application 1

Windows. Forms. Application 1. Form 1. Designer. cs (1/3) namespace Windows. Forms. Application 1 { partial class Form 1 { /// <summary> /// 設計 具所需的變數。 /// </summary> private System. Component. Model. IContainer components = null; /// <summary> /// 清除任何使用中的資源。 /// </summary> /// <param name="disposing">如果應該處置 Managed 資源則為 true,否則為 false。</param> 10

Windows. Forms. Application 1. Form 1. Designer. cs (2/3) protected override void Dispose(bool disposing)

Windows. Forms. Application 1. Form 1. Designer. cs (2/3) protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components. Dispose(); } base. Dispose(disposing); } #region Windows Form 設計 具產生的程式碼 /// <summary> /// 此為設計 具支援所需的方法 - 請勿使用程式碼編輯 器修改這個方法的內容。 /// </summary> 11

Windows. Forms. Application 1. Form 1. Designer. cs (3/3) private void Initialize. Component() {

Windows. Forms. Application 1. Form 1. Designer. cs (3/3) private void Initialize. Component() { this. components = new System. Component. Model. Container(); this. Auto. Scale. Mode = System. Windows. Forms. Auto. Scale. Mode. Font; this. Text = "Form 1"; } #endregion } } 12

程式Using. Message. Box畫面 15

程式Using. Message. Box畫面 15

Using. Message. Box. Program. cs using System; using System. Collections. Generic; using System. Windows.

Using. Message. Box. Program. cs using System; using System. Collections. Generic; using System. Windows. Forms; namespace Using. Message. Box { static class Program { static void Main() { Application. Enable. Visual. Styles(); Application. Set. Compatible. Text. Rendering. Default(false) ; Application. Run(new Main. Form()); //********************** Message. Box. Show("Main form has been closed"); //********************** } } 16 }

程式Using. Controls畫面 19

程式Using. Controls畫面 19

Using. Controls. Form 1. cs (1/2) using using System; System. Collections. Generic; System. Component.

Using. Controls. Form 1. cs (1/2) using using System; System. Collections. Generic; System. Component. Model; System. Data; System. Drawing; System. Linq; System. Text; System. Windows. Forms; namespace Using. Controls { public partial class Form 1 : Form { public Form 1() { Initialize. Component(); } 21

Using. Controls. Form 1. cs (2/2) private void Event. Args { button 1_Click(object sender,

Using. Controls. Form 1. cs (2/2) private void Event. Args { button 1_Click(object sender, e) //******************* Message. Box. Show("Hello!"+text. Box 1. Text); //******************* } } } 22

Using. Controls. Form 1. Designer. cs 部份程式碼 (1/2) private void Initialize. Component() { this.

Using. Controls. Form 1. Designer. cs 部份程式碼 (1/2) private void Initialize. Component() { this. button 1 = new System. Windows. Forms. Button(); this. text. Box 1 = new System. Windows. Forms. Text. Box(); this. label 1 = new System. Windows. Forms. Label(); this. Suspend. Layout(); // // button 1 // this. button 1. Location = new System. Drawing. Point(166, 192); this. button 1. Name = "button 1"; this. button 1. Size = new System. Drawing. Size( 75, 23); 23

Using. Controls. Form 1. Designer. cs 部份程式碼 (2/2) this. button 1. Tab. Index =

Using. Controls. Form 1. Designer. cs 部份程式碼 (2/2) this. button 1. Tab. Index = 0; this. button 1. Text = "確定"; this. button 1. Use. Visual. Style. Back. Color = true; this. button 1. Click += new System. Event. Handler(this. button 1_Click); // // text. Box 1 // this. text. Box 1. Location = new System. Drawing. Point(136, 55); this. text. Box 1. Name = "text. Box 1"; this. text. Box 1. Size = new System. Drawing. Size( 105, 22); this. text. Box 1. Tab. Index = 1; . . . } 24

程式Using. Menu. Strip選單建立 30

程式Using. Menu. Strip選單建立 30

Using. Menu. Strip. Main. Form. cs 部份程式碼 public partial class Main. Form : Form

Using. Menu. Strip. Main. Form. cs 部份程式碼 public partial class Main. Form : Form { public Main. Form() { Initialize. Component(); } private void 輸入表格Tool. Strip. Menu. Item_Click( object sender, Event. Args e) { //****************** 計算Tool. Strip. Menu. Item. Enabled = true; //****************** } } 31

程式Using. Menu. Strip畫面 32

程式Using. Menu. Strip畫面 32

程式Using. Dialog. Form畫面 34

程式Using. Dialog. Form畫面 34

對話表單設計 • • • 專案/加入新項目/Windows Form Label/Text. Box/Button Text. Box屬性(Text, Text. Align)及Button行為 調整設定 35

對話表單設計 • • • 專案/加入新項目/Windows Form Label/Text. Box/Button Text. Box屬性(Text, Text. Align)及Button行為 調整設定 35

程式Using. Dialog. Form結構 37

程式Using. Dialog. Form結構 37

程式Using. Dialog. Form「計算」 順序圖 39

程式Using. Dialog. Form「計算」 順序圖 39

Using. Dialog. Form. Main. Form. cs (1/3) using using System; System. Collections. Generic; System.

Using. Dialog. Form. Main. Form. cs (1/3) using using System; System. Collections. Generic; System. Component. Model; System. Data; System. Drawing; System. Linq; System. Text; System. Windows. Forms; namespace Using. Dialog. Form { public partial class Main. Form : Form { 40

Using. Dialog. Form. Main. Form. cs (2/3) //***************** int[, ] t; //***************** public Main.

Using. Dialog. Form. Main. Form. cs (2/3) //***************** int[, ] t; //***************** public Main. Form() { Initialize. Component(); } private void 輸入表格 Tool. Strip. Menu. Item_Click(object sender, Event. Args e) { //****************** Dialog diag = new Dialog(); diag. Show. Dialog(); t = diag. Content; 計算Tool. Strip. Menu. Item. Enabled = true; //****************** } 41

Using. Dialog. Form. Main. Form. cs (3/3) private void 計算 Tool. Strip. Menu. Item_Click(object

Using. Dialog. Form. Main. Form. cs (3/3) private void 計算 Tool. Strip. Menu. Item_Click(object sender, Event. Args e) { //***************** Output output = new Output(); output. Do. Computation(t); output. Show. Dialog(); //***************** } } } 42

Using. Dialog. Form. Dialog. cs (1/3) using System; using System. Collections. Generic; using System.

Using. Dialog. Form. Dialog. cs (1/3) using System; using System. Collections. Generic; using System. Component. Model; using System. Data; using System. Drawing; using System. Text; using System. Windows. Forms; namespace Using. Dialog. Form { public partial class Dialog : Form { //****************** int[ , ] table = new int[2, 3]; //****************** public Dialog() { Initialize. Component(); } 43

Using. Dialog. Form. Dialog. cs (2/3) private void button 1_Click(object sender, Event. Args e)

Using. Dialog. Form. Dialog. cs (2/3) private void button 1_Click(object sender, Event. Args e) { //********************** table[0, 0] = Convert. To. Int 32(text. Box 1. Text); table[0, 1] = Convert. To. Int 32(text. Box 2. Text); table[0, 2] = Convert. To. Int 32(text. Box 3. Text); table[1, 0] = Convert. To. Int 32(text. Box 4. Text); table[1, 1] = Convert. To. Int 32(text. Box 5. Text); table[1, 2] = Convert. To. Int 32(text. Box 6. Text); Message. Box. Show(table[0, 0]. To. String()+ "t" + table[0, 1]. To. String()+ "t" + table[0, 2]. To. String()+ "n" + table[1, 0]. To. String()+ "t" + table[1, 1]. To. String()+ "t" + table[1, 2]. To. String() + "n"); //**********************44 }

Using. Dialog. Form. Dialog. cs (3/3) private void button 2_Click(object sender, Event. Args e)

Using. Dialog. Form. Dialog. cs (3/3) private void button 2_Click(object sender, Event. Args e) { //***************** Dispose(); //***************** } //*********************** public int[, ] Content { get { return table; } } //*********************** } } 45

Using. Dialog. Form. Output. cs (1/6) using System; using System. Collections. Generic; using System.

Using. Dialog. Form. Output. cs (1/6) using System; using System. Collections. Generic; using System. Component. Model; using System. Data; using System. Drawing; using System. Linq; using System. Text; using System. Windows. Forms; namespace Using. Dialog. Form { public partial class Output : Form { public Output() { Initialize. Component(); } 46

Using. Dialog. Form. Output. cs (2/6) //*********************** public void Do. Computation(int[, ] t) {

Using. Dialog. Form. Output. cs (2/6) //*********************** public void Do. Computation(int[, ] t) { int[, ] table = t; int[] row. Sum = Row. Sum(t); int[] col. Sum = Col. Sum(t); int total. Sum = Total. Sum(t); rich. Text. Box 1. Text = "表格統計結果n" + " t 1t 2t 3t總和n" + "1t"+table[0, 0]. To. String()+"t"+ table[0, 1]. To. String()+"t table[0, 2]. To. String()+"t"+ row. Sum[0]. To. String()+"n"+ 47

Using. Dialog. Form. Output. cs (3/6) "2t"+table[1, 0]. To. String()+"t"+ table[1, 1]. To. String()+"t"+

Using. Dialog. Form. Output. cs (3/6) "2t"+table[1, 0]. To. String()+"t"+ table[1, 1]. To. String()+"t"+ table[1, 2]. To. String()+"t"+ row. Sum[1]. To. String()+"n"+ "總和t"+col. Sum[0]. To. String()+"t"+ col. Sum[1]. To. String()+"t"+ col. Sum[2]. To. String()+"t"+ total. Sum. To. String()+"n"; } 48

Using. Dialog. Form. Output. cs (4/6) private int[] Row. Sum(int[, ] data) { int

Using. Dialog. Form. Output. cs (4/6) private int[] Row. Sum(int[, ] data) { int n. Row = data. Get. Upper. Bound(0) + int n. Col = data. Get. Upper. Bound(1) + int[] row. Sum = new int[n. Row]; for (int i = 0; i < n. Row; ++i) { row. Sum[i] = 0; for (int j = 0; j < n. Col; ++j) { row. Sum[i] += data[i, j]; } } return row. Sum; } 1; 1; 49

Using. Dialog. Form. Output. cs (5/6) private int[] Col. Sum(int[, ] data) { int

Using. Dialog. Form. Output. cs (5/6) private int[] Col. Sum(int[, ] data) { int n. Row = data. Get. Upper. Bound(0) + int n. Col = data. Get. Upper. Bound(1) + int[] col. Sum = new int[n. Col]; for (int j = 0; j < n. Col; ++j) { col. Sum[j] = 0; for (int i = 0; i < n. Row; ++i) { col. Sum[j] += data[i, j]; } } return col. Sum; } 1; 1; 50

Using. Dialog. Form. Output. cs (6/6) private { int int for { int Total.

Using. Dialog. Form. Output. cs (6/6) private { int int for { int Total. Sum(int[, ] data) n. Row = data. Get. Upper. Bound(0) + 1; n. Col = data. Get. Upper. Bound(1) + 1; total. Sum = 0; (int i = 0; i < n. Row; ++i) for (int j = 0; j < n. Col; ++j) { total. Sum += data[i, j]; } } return total. Sum; } //********************* } } 51

Model-View-Controller *D. Collins, Designing Object-Oriented User Interfaces, Benjamin/Cummings, 1995. 54

Model-View-Controller *D. Collins, Designing Object-Oriented User Interfaces, Benjamin/Cummings, 1995. 54

MVCExample. Table. cs (1/4) using System; namespace MVCExample { public class Table { private

MVCExample. Table. cs (1/4) using System; namespace MVCExample { public class Table { private int[, ] data; public Table() { data = new int[1, 1]; data[0, 0] = 0; } public Table(int[, ] data) { this. data = data; } 57

MVCExample. Table. cs (2/4) public int Element(int i, int j) { return data[i, j];

MVCExample. Table. cs (2/4) public int Element(int i, int j) { return data[i, j]; } public int[] Row. Sum() { int n. Row = data. Get. Upper. Bound(0) + int n. Col = data. Get. Upper. Bound(1) + int[] row. Sum = new int[n. Row]; for (int i = 0; i < n. Row; ++i) { row. Sum[i] = 0; for (int j = 0; j < n. Col; ++j) row. Sum[i] += data[i, j]; } } return row. Sum; } 1; 1; { 58

MVCExample. Table. cs (3/4) public int[] Col. Sum() { int n. Row = data.

MVCExample. Table. cs (3/4) public int[] Col. Sum() { int n. Row = data. Get. Upper. Bound(0) + int n. Col = data. Get. Upper. Bound(1) + int[] col. Sum = new int[n. Col]; for (int j = 0; j < n. Col; ++j) { col. Sum[j] = 0; for (int i = 0; i < n. Row; ++i) { col. Sum[j] += data[i, j]; } } return col. Sum; } 1; 1; 59

MVCExample. Table. cs (4/4) public int Total. Sum() { int n. Row = data.

MVCExample. Table. cs (4/4) public int Total. Sum() { int n. Row = data. Get. Upper. Bound(0) + int n. Col = data. Get. Upper. Bound(1) + int total. Sum = 0; for (int i = 0; i < n. Row; ++i) { for (int j = 0; j < n. Col; ++j) { total. Sum += data[i, j]; } } return total. Sum; } 1; 1; } } 60

複製Using. Dialog. Form. Dialog, Using. Dialog. Form. Main. Form, Using. Dialog. Form. Output •

複製Using. Dialog. Form. Dialog, Using. Dialog. Form. Main. Form, Using. Dialog. Form. Output • 專案/加入現有項目. . . • 選擇Using. Dialog. Form. Dialog. cs加入 • 按右鍵選擇「設計 具檢視」, 作區便 會出現的Dialog對話表單,同時系統也自動 將相關控制元件加入專案 • 同法加入Using. Dialog. Form. Main. Form. cs及 Using. Dialog. Form. Output. cs • 注意它們的命名空間是Using. Dialog. Form 61

MVCExample. Program. cs (1/2) /* * MVC Example * 示範MVC架構 * 5/12/2011 * skj

MVCExample. Program. cs (1/2) /* * MVC Example * 示範MVC架構 * 5/12/2011 * skj */ using System; using System. Collections. Generic; using System. Linq; using System. Windows. Forms; //******************* using Using. Dialog. Form; //******************* namespace MVCExample { 62

MVCExample. Program. cs (2/2) static class Program { /// <summary> /// 應用程式的主要進入點。 /// </summary>

MVCExample. Program. cs (2/2) static class Program { /// <summary> /// 應用程式的主要進入點。 /// </summary> [STAThread] static void Main() { Application. Enable. Visual. Styles(); Application. Set. Compatible. Text. Rendering. Default(false) ; Application. Run(new Main. Form()); } } } 63

程式Displaying. Cards畫面 65

程式Displaying. Cards畫面 65

Displayingc. Cards. Main. Form. Designer. cs (1/4) //*************** using System. Drawing; //*************** namespace Displaying.

Displayingc. Cards. Main. Form. Designer. cs (1/4) //*************** using System. Drawing; //*************** namespace Displaying. Cards { partial class Main. Form { /// <summary> /// 設計 具所需的變數。 /// </summary> private System. Component. Model. IContainer components = null; //********************** private Image image; private Graphics graphics; private bool started = false; //********************** 67

Displayingc. Cards. Main. Form. Designer. cs (2/4) /// <summary> /// 清除任何使用中的資源。 /// </summary> ///

Displayingc. Cards. Main. Form. Designer. cs (2/4) /// <summary> /// 清除任何使用中的資源。 /// </summary> /// <param name="disposing">如果應該處置 Managed 資源則為 true,否則為 false。</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components. Dispose(); } base. Dispose(disposing); } 68

Displayingc. Cards. Main. Form. Designer. cs (3/4) //********************* private void Display. Image() { int

Displayingc. Cards. Main. Form. Designer. cs (3/4) //********************* private void Display. Image() { int si = list. Box 1. Selected. Index; string[] suit = { "s", "h", "d", "c" }; int i = list. Box 2. Selected. Index + 1; string rank = i. To. String(); string file. Name = ". . \Playing. Cards\" + suit[si] + rank + ". jpg"; image = Image. From. File(file. Name); graphics = Create. Graphics(); graphics. Draw. Image(image, 5, 5, 85, 150); } 69

Displayingc. Cards. Main. Form. Designer. cs (4/4) protected override void On. Paint(System. Windows. Forms.

Displayingc. Cards. Main. Form. Designer. cs (4/4) protected override void On. Paint(System. Windows. Forms. Paint. Event. Args e) { base. On. Paint(e); if (started) { Display. Image(); } } //********************* #region Windows Form 設計 具產生的程式碼. . . #endregion. . . } } 70

Main. Form. cs (1/2) using System; using System. Collections. Generic; using System. Component. Model;

Main. Form. cs (1/2) using System; using System. Collections. Generic; using System. Component. Model; using System. Data; using System. Drawing; using System. Linq; using System. Text; using System. Windows. Forms; namespace Displaying. Cards { public partial class Main. Form : Form { public Main. Form() { Initialize. Component(); } 71

Main. Form. cs (2/2) private void Main. Form_Load(object sender, Event. Args e) { }

Main. Form. cs (2/2) private void Main. Form_Load(object sender, Event. Args e) { } private void button 1_Click(object sender, Event. Args e) { //********* Display. Image(); //********* } } } 72

Black. Jack_0_1 G 類別圖 75

Black. Jack_0_1 G 類別圖 75

互動設計:Activity Diagram 77

互動設計:Activity Diagram 77

起始處理:Collaboration Diagram 79

起始處理:Collaboration Diagram 79

起始處理:Sequence Diagram 80

起始處理:Sequence Diagram 80

玩家要牌:Sequence Diagram 81

玩家要牌:Sequence Diagram 81

玩家停牌:Sequence Diagram 82

玩家停牌:Sequence Diagram 82

Black. Jack_0_1 G. Main. Form. cs (1/11) using System; using System. Collections. Generic; using

Black. Jack_0_1 G. Main. Form. cs (1/11) using System; using System. Collections. Generic; using System. Component. Model; using System. Data; using System. Drawing; using System. Linq; using System. Text; using System. Windows. Forms; namespace Black. Jack_0_1 G { //****************** public struct Player. Info { public string name; public Status status; 84

Black. Jack_0_1 G. Main. Form. cs (2/11) public int total. Points; Card[] cards; int

Black. Jack_0_1 G. Main. Form. cs (2/11) public int total. Points; Card[] cards; int n. Cards; } //****************** public partial class Main. Form : Form { //**************** private Game game; private Player. Info player. Info; private Player. Info dealer. Info; private Image image; private Graphics graphics; private bool in. Game = false; //**************** 85

Black. Jack_0_1 G. Main. Form. cs (3/11) public Main. Form() { Initialize. Component(); }

Black. Jack_0_1 G. Main. Form. cs (3/11) public Main. Form() { Initialize. Component(); } private void button 1_Click(object sender, Event. Args e) { //******************* game. Process. Player. Run(out player. Info); Show. Info(); Check. Black. Jack. Or. Burst(player. Info); Check. Black. Jack. Or. Burst(dealer. Info); //******************* } 86

Black. Jack_0_1 G. Main. Form. cs (4/11) //********************* private void Show. Info() { int

Black. Jack_0_1 G. Main. Form. cs (4/11) //********************* private void Show. Info() { int i; string file. Name; graphics = Create. Graphics(); for (i = 0; i < player. Info. n. Cards; ++i) { file. Name = ". . \Playing. Cards\" + player. Info. cards[i]. Name() + ". jpg"; image = Image. From. File(file. Name); graphics. Draw. Image(image, 5+100*i, 220, 85, 150); } 87

Black. Jack_0_1 G. Main. Form. cs (5/11) ". jpg"; for (i = 0; i

Black. Jack_0_1 G. Main. Form. cs (5/11) ". jpg"; for (i = 0; i < dealer. Info. n. Cards; ++i) { file. Name = ". . \Playing. Cards\" + dealer. Info. cards[i]. Name() + image = Image. From. File(file. Name); graphics. Draw. Image(image, 5+100*i, 5, 85, 150); } label 1. Text = dealer. Info. total. Points. To. String(); label 2. Text = player. Info. total. Points. To. String(); label 11. Text = dealer. Info. name; label 12. Text = player. Info. name; } 88

Black. Jack_0_1 G. Main. Form. cs (6/11) private void button 3_Click(object sender, Event. Args

Black. Jack_0_1 G. Main. Form. cs (6/11) private void button 3_Click(object sender, Event. Args e) { //********************* // "開始"按鈕 in. Game = true; game = new Game(); game. Init. Play(out player. Info, out dealer. Info); Show. Info(); Check. Black. Jack. Or. Burst(player. Info); Check. Black. Jack. Or. Burst(dealer. Info); button 3. Enabled = false; button 4. Enabled = true; //********************* } 89

Black. Jack_0_1 G. Main. Form. cs (7/11) private void button 2_Click(object sender, Event. Args

Black. Jack_0_1 G. Main. Form. cs (7/11) private void button 2_Click(object sender, Event. Args e) { //******************* // "停"按鈕 game. Process. Dealer. Run(out dealer. Info); Show. Info(); Check. Black. Jack. Or. Burst(player. Info); Check. Black. Jack. Or. Burst(dealer. Info); if (player. Info. status == Status. PASS && dealer. Info. status == Status. PASS) { 90

Black. Jack_0_1 G. Main. Form. cs (8/11) if (dealer. Info. total. Points >= player.

Black. Jack_0_1 G. Main. Form. cs (8/11) if (dealer. Info. total. Points >= player. Info. total. Points) { Message. Box. Show(dealer. Info. name + "勝" + player. Info. name); } else { Message. Box. Show(player. Info. name + "勝" + dealer. Info. name); } } //******************* } 91

Black. Jack_0_1 G. Main. Form. cs (9/11) private void Check. Black. Jack. Or. Burst(Player.

Black. Jack_0_1 G. Main. Form. cs (9/11) private void Check. Black. Jack. Or. Burst(Player. Info info) { if (info. status == Status. BLACK_JACK) { Message. Box. Show(info. name+" 二十一點"); } if (info. status == Status. BURST) { Message. Box. Show(info. name + " 爆!!!"); } } 92

Black. Jack_0_1 G. Main. Form. cs (10/11) private void button 4_Click(object sender, Event. Args

Black. Jack_0_1 G. Main. Form. cs (10/11) private void button 4_Click(object sender, Event. Args e) { //******************* // "清除"按鈕 in. Game = false; Invalidate(); label 1. Text = "0"; label 2. Text = "0"; button 4. Enabled = false; button 3. Enabled = true; //******************* } 93

Black. Jack_0_1 G. Main. Form. cs (11/11) //********************* protected override void On. Paint(Paint. Event.

Black. Jack_0_1 G. Main. Form. cs (11/11) //********************* protected override void On. Paint(Paint. Event. Args e) { base. On. Paint(e); if (in. Game) { Show. Info(); } } //********************* } } 94

Black. Jack_0_1 G. Game. cs (1/7) /* * 二十一點遊戲, for GUI version * 11/21/2008

Black. Jack_0_1 G. Game. cs (1/7) /* * 二十一點遊戲, for GUI version * 11/21/2008 */ using System; namespace Black. Jack_0_1 G { class Game { const int N_PLAYERS = 2; Deck deck; Player[] players = new Player[N_PLAYERS]; public Game() { 95

Black. Jack_0_1 G. Game. cs (2/7) players[0] = new Player("Jeng"); players[N_PLAYERS - 1] =

Black. Jack_0_1 G. Game. cs (2/7) players[0] = new Player("Jeng"); players[N_PLAYERS - 1] = new Dealer(); deck = new Deck(); } public void Init. Play(out Player. Info player. Info, out Player. Info dealer. Info) { int i; // 第一輪發牌 for (i = 0; i < N_PLAYERS; ++i) { players[i]. Save. ACard( deck. Deal. ACard()); } 96

Black. Jack_0_1 G. Game. cs (3/7) // 第二輪發牌 for (i = 0; i <

Black. Jack_0_1 G. Game. cs (3/7) // 第二輪發牌 for (i = 0; i < N_PLAYERS; ++i) { players[i]. Save. ACard( deck. Deal. ACard()); } player. Info. name = players[0]. Name; player. Info. status = players[0]. Get. Status(); player. Info. total. Points = players[0]. Get. Total. Points(); player. Info. cards = players[0]. Dump. Cards(); player. Info. n. Cards = players[0]. Get. NCards(); 97

Black. Jack_0_1 G. Game. cs (4/7) dealer. Info. name = players[N_PLAYERS - 1]. Name;

Black. Jack_0_1 G. Game. cs (4/7) dealer. Info. name = players[N_PLAYERS - 1]. Name; dealer. Info. status = players[N_PLAYERS 1]. Get. Status(); dealer. Info. total. Points = players[N_PLAYERS 1]. Get. Total. Points(); dealer. Info. cards = players[N_PLAYERS 1]. Dump. Cards(); dealer. Info. n. Cards = players[N_PLAYERS 1]. Get. NCards(); } 98

Black. Jack_0_1 G. Game. cs (5/7) public void Process. Player. Run(out Player. Info player.

Black. Jack_0_1 G. Game. cs (5/7) public void Process. Player. Run(out Player. Info player. Info) { players[0]. Save. ACard(deck. Deal. ACard()); player. Info. name = players[0]. Name; player. Info. status = players[0]. Get. Status(); player. Info. total. Points = players[0]. Get. Total. Points(); player. Info. cards = players[0]. Dump. Cards(); player. Info. n. Cards = players[0]. Get. NCards(); } 99

Black. Jack_0_1 G. Game. cs (6/7) public void Process. Dealer. Run(out Player. Info dealer.

Black. Jack_0_1 G. Game. cs (6/7) public void Process. Dealer. Run(out Player. Info dealer. Info) { while ( players[N_PLAYERS 1]. Want. One. More. Card()) { players[N_PLAYERS - 1]. Save. ACard( deck. Deal. ACard()); } dealer. Info. name = players[N_PLAYERS - 1]. Name; dealer. Info. status = players[N_PLAYERS 1]. Get. Status(); dealer. Info. total. Points = players[N_PLAYERS 100 1]. Get. Total. Points();

Black. Jack_0_1 G. Game. cs (7/7) dealer. Info. cards = players[N_PLAYERS 1]. Dump. Cards();

Black. Jack_0_1 G. Game. cs (7/7) dealer. Info. cards = players[N_PLAYERS 1]. Dump. Cards(); dealer. Info. n. Cards = players[N_PLAYERS 1]. Get. NCards(); } } } 101

Black. Jack_0_1 G. Player. cs (1/6) /* * 模擬玩家, for GUI version * 4/19/2009

Black. Jack_0_1 G. Player. cs (1/6) /* * 模擬玩家, for GUI version * 4/19/2009 */ using System; namespace Black. Jack_0_1 G { class Player { // a player can have at most 11 cards // {A, A, 2, 2, 3, 3, 3} // for not burst or Black. Jack private Card[] hand = new Card[11]; private int n. Cards; 102

Black. Jack_0_1 G. Player. cs (2/6) private Status status; private int total. Points; private

Black. Jack_0_1 G. Player. cs (2/6) private Status status; private int total. Points; private string name; public Player() { n. Cards = 0; name = "無名氏"; } public Player(string name) { n. Cards = 0; this. name = name; } 103

Black. Jack_0_1 G. Player. cs (3/6) public string Name { get { return name;

Black. Jack_0_1 G. Player. cs (3/6) public string Name { get { return name; } } public void Save. ACard(Card card) { hand[n. Cards++] = card; Status. Checker. Determine. Status. And. Total. Poi nts(hand, n. Cards, out status, out total. Points); } public Status Get. Status() { return status; } 104

Black. Jack_0_1 G. Player. cs (4/6) public int Get. Total. Points() { return total.

Black. Jack_0_1 G. Player. cs (4/6) public int Get. Total. Points() { return total. Points; } virtual public bool Want. One. More. Card() { Console. Write("要再一張牌嗎? (y/n) "); string answer = Console. Read. Line(); return (answer == "Y" || answer == "y"); } public void Dump() { int i; Console. Write(name + " 牌: "); 105

Black. Jack_0_1 G. Player. cs (5/6) for (i = 0; i < n. Cards;

Black. Jack_0_1 G. Player. cs (5/6) for (i = 0; i < n. Cards; ++i) { hand[i]. Dump(); Console. Write("t"); if ((i + 1) % 5 == 0) Console. Write. Line(); } Console. Write. Line(); Console. Write. Line(name + " 總點數: " + total. Points); } public Card[] Dump. Cards() { return hand; } 106

Black. Jack_0_1 G. Player. cs (6/6) public int { return } Get. NCards() n.

Black. Jack_0_1 G. Player. cs (6/6) public int { return } Get. NCards() n. Cards; } } 107