private void NovaIgra(object sender, EventArgs e) { Button sb = sender as Button; if (sb == null) { return; } if (sb.Name.Contains("X")) { igrac = 1; } else { igrac = 2; } buttons = new Button[3, 3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { Button b = new Button() { BackColor = Color.White, Dock = System.Windows.Forms.DockStyle.Fill, Font = new System.Drawing.Font("Stencil", 24F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))), Location = new System.Drawing.Point(3, 3), Name = "button" + i.ToString() + j.ToString(), Size = new System.Drawing.Size(93, 93), TabIndex = 0, Text = "", Tag = i * 10 + j, }; b.Click += b_Click; tlpGame.Controls.Add(b, j, i); buttons[i, j] = b; } } pnlHeader.Visible = false; pnlGameInfo.Visible = true; context = new ContextIksOks(new Tabla(), igrac); }
void b_Click(object sender, EventArgs e) { Button b = sender as Button; if (b == null) { return; } int x = (int)b.Tag; int y = x % 10; x = x / 10; UradiPotez(new Potez() { x = x, y = y, }); if (context.NaPotezu != igrac) { try { this.Enabled = false; if (context.TrenutnoStanje.DoKraja() == 0) { MessageBox.Show("Nerešeno"); return; } Potez p = ContextIksOks.MinMax(context, 8); UradiPotez(p); } finally { this.Enabled = true; } } }