1. public partial class Form1 : Form
2. {
3. public Form1()
4. {
5. InitializeComponent();
6. dataGridView1.RowTemplate.Height = 95;
7. dataGridView1.RowCount = 3;
8. dataGridView1.ColumnCount = 3;
9. for (int i = 0; i < 3; i++)
10. for (int j = 0; j < 3; j++)
11. dataGridView1.Rows[i].Cells[j].Value = "";
12. }
13.
14.
15.
16.
17. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
18. {
19.
20. }
21.
22. private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
23. {
24.
25.
26. if (dataGridView1.CurrentCell.Value != "") return;
27.
28. dataGridView1.CurrentCell.Value = "x";
29. string[,] s = new string[3, 3];
30. for (int i = 0; i < 3; i++)
31. for (int j = 0; j < 3; j++)
32. s[i, j] = dataGridView1.Rows[i].Cells[j].Value.ToString(); //в массив dataGridView1
33.
34. switch (X0.Step(ref s))
35. {
36.
37. case 0:
38. for (int i = 0; i < 3; i++)
39. for (int j = 0; j < 3; j++)
40. {
41. dataGridView1.Rows[i].Cells[j].Value = s[i, j];
42. if (dataGridView1.Rows[i].Cells[j].Value == "o") dataGridView1.Rows[i].Cells[j].Style.ForeColor = Color.Blue;
43. }
44. break;
45. case 1: for (int i = 0; i < 3; i++)
46. for (int j = 0; j < 3; j++)
47. {
48. dataGridView1.Rows[i].Cells[j].Value = s[i, j];
49. if (dataGridView1.Rows[i].Cells[j].Value == "o") dataGridView1.Rows[i].Cells[j].Style.ForeColor = Color.Blue;
50. }
51. label2.Text = (int.Parse(label2.Text) + 1).ToString(); MessageBox.Show("Вы выйграли!", "Ура!");
52. for (int i = 0; i < 3; i++)
53. for (int j = 0; j < 3; j++)
54. { dataGridView1.Rows[i].Cells[j].Value = ""; dataGridView1.Rows[i].Cells[j].Style.ForeColor = Color.Red; }
55. break;
56. case 2: for (int i = 0; i < 3; i++)
57. for (int j = 0; j < 3; j++)
58. {
59. dataGridView1.Rows[i].Cells[j].Value = s[i, j];
60. if (dataGridView1.Rows[i].Cells[j].Value == "o") dataGridView1.Rows[i].Cells[j].Style.ForeColor = Color.Blue;
61. }
62. label3.Text = (int.Parse(label3.Text) + 1).ToString(); MessageBox.Show("Вы проиграли!", "Увы!");
63. for (int i = 0; i < 3; i++)
64. for (int j = 0; j < 3; j++)
65. {dataGridView1.Rows[i].Cells[j].Value = ""; dataGridView1.Rows[i].Cells[j].Style.ForeColor=Color.Red;} break;
66. case 3: for (int i = 0; i < 3; i++)
67. for (int j = 0; j < 3; j++)
68. {
69. dataGridView1.Rows[i].Cells[j].Value = s[i, j];
70. if (dataGridView1.Rows[i].Cells[j].Value == "o") dataGridView1.Rows[i].Cells[j].Style.ForeColor = Color.Blue;
71. } MessageBox.Show("Ничья!", "Жаль...");
72. for (int i = 0; i < 3; i++)
73. for (int j = 0; j < 3; j++)
74. {dataGridView1.Rows[i].Cells[j].Value = ""; dataGridView1.Rows[i].Cells[j].Style.ForeColor=Color.Red;} break;
75.
76. }
77.
78.
79.
80. }
81.
82. private void label2_Click(object sender, EventArgs e)
83. {
84.
85. }
86.
87. private void label3_Click(object sender, EventArgs e)
88. {
89.
90. }
91.
92. private void Form1_Load(object sender, EventArgs e)
93. {
94.
95. }
96.
97. private void label4_Click(object sender, EventArgs e)
98. {
99.
100. }
101.
102.
103.
104. private void выходToolStripMenuItem_Click(object sender, EventArgs e)
105. {
106. Application.Exit();
107. }
108.
109. private void игроToolStripMenuItem_Click_1(object sender, EventArgs e)
110. {
111. for (int i = 0; i < 3; i++)
112. for (int j = 0; j < 3; j++)
113. {
114. dataGridView1.Rows[i].Cells[j].Value = "";
115. label2.Text = "0"; label3.Text = "0";
116. }
117. }
118.
119. private void ToolStripMenuItem_Click(object sender, EventArgs e)
120. {
121.
122. }
123.
124. private void оПрограммеToolStripMenuItem_Click(object sender, EventArgs e)
125. {
126. MessageBox.Show("Правила игры: \nИгроки по очереди ставят на свободные клетки поля 3х3 знаки (один всегда крестики, другой всегда нолики). Первый, выстроивший в ряд 3 своих фигуры по вертикали, горизонтали или диагонали, выигрывает. Первый ход делает игрок, ставящий крестики.", "Крестики-нолики");
127.
128. }
129. }
130. }
Список литературы
· msdn.microsoft.com
· cyberforum.ru/windows-forms/
· С/C++ Програмирование на языке высокого уровня
· http://dotnetgrains.sql.ru/
· http://www.gotdotnet.ru/
· http://www.aspnetmania.com/
· www.rsdn.ru
· .NET Framework Solutions: In Search of the Lost Win32 API by John Paul Mueller
· Учебное пособие №2056