Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Курсовая по программированию (2012).docx
Скачиваний:
102
Добавлен:
20.04.2015
Размер:
286.2 Кб
Скачать
    1. Код Form1(Main)

  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. private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)

  14. {

  15. }

  16. private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)

  17. {

  18. if (dataGridView1.CurrentCell.Value != "") return;

  19. dataGridView1.CurrentCell.Value = "x";

  20. string[,] s = new string[3, 3];

  21. for (int i = 0; i < 3; i++)

  22. for (int j = 0; j < 3; j++)

  23. s[i, j] = dataGridView1.Rows[i].Cells[j].Value.ToString(); //в массив dataGridView1

  24. switch (X0.Step(ref s))

  25. {

  26. case 0:

  27. for (int i = 0; i < 3; i++)

  28. for (int j = 0; j < 3; j++)

  29. {

  30. dataGridView1.Rows[i].Cells[j].Value = s[i, j];

  31. if (dataGridView1.Rows[i].Cells[j].Value == "o") dataGridView1.Rows[i].Cells[j].Style.ForeColor = Color.Blue;

  32. }

  33. break;

  34. case 1: for (int i = 0; i < 3; i++)

  35. for (int j = 0; j < 3; j++)

  36. {

  37. dataGridView1.Rows[i].Cells[j].Value = s[i, j];

  38. if (dataGridView1.Rows[i].Cells[j].Value == "o") dataGridView1.Rows[i].Cells[j].Style.ForeColor = Color.Blue;

  39. }

  40. label2.Text = (int.Parse(label2.Text) + 1).ToString(); MessageBox.Show("Вы выйграли!", "Ура!");

  41. for (int i = 0; i < 3; i++)

  42. for (int j = 0; j < 3; j++)

  43. { dataGridView1.Rows[i].Cells[j].Value = ""; dataGridView1.Rows[i].Cells[j].Style.ForeColor = Color.Red; }

  44. break;

  45. case 2: 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. label3.Text = (int.Parse(label3.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;} break;

  55. case 3: for (int i = 0; i < 3; i++)

  56. for (int j = 0; j < 3; j++)

  57. {

  58. dataGridView1.Rows[i].Cells[j].Value = s[i, j];

  59. if (dataGridView1.Rows[i].Cells[j].Value == "o") dataGridView1.Rows[i].Cells[j].Style.ForeColor = Color.Blue;

  60. } MessageBox.Show("Ничья!", "Жаль...");

  61. for (int i = 0; i < 3; i++)

  62. for (int j = 0; j < 3; j++)

  63. {dataGridView1.Rows[i].Cells[j].Value = ""; dataGridView1.Rows[i].Cells[j].Style.ForeColor=Color.Red;} break;

  64. }

  65. }

  66. private void label2_Click(object sender, EventArgs e)

  67. {

  68. }

  69. private void label3_Click(object sender, EventArgs e)

  70. {

  71. }

  72. private void Form1_Load(object sender, EventArgs e)

  73. {

  74. }

  75. private void label4_Click(object sender, EventArgs e)

  76. {

  77. }

  78. private void выходToolStripMenuItem_Click(object sender, EventArgs e)

  79. {

  80. Application.Exit();

  81. }

  82. private void игроToolStripMenuItem_Click_1(object sender, EventArgs e)

  83. {

  84. for (int i = 0; i < 3; i++)

  85. for (int j = 0; j < 3; j++)

  86. {

  87. dataGridView1.Rows[i].Cells[j].Value = "";

  88. label2.Text = "0"; label3.Text = "0";

  89. }

  90. }

  91. private void ToolStripMenuItem_Click(object sender, EventArgs e)

  92. {

  93. }

  94. private void оПрограммеToolStripMenuItem_Click(object sender, EventArgs e)

  95. {

  96. MessageBox.Show("Правила игры: \nИгроки по очереди ставят на свободные клетки поля 3х3 знаки (один всегда крестики, другой всегда нолики). Первый, выстроивший в ряд 3 своих фигуры по вертикали, горизонтали или диагонали, выигрывает. Первый ход делает игрок, ставящий крестики.", "Крестики-нолики");

  97. }

  98. }

  99. }