private void field_Click(object sender, System.EventArgs e) { MyPicBox box = sender as MyPicBox; Coordinate move = new Coordinate(box.x, box.y); Console.WriteLine("Got click on field: {0}", move); if (!valid(move)) { MessageBox.Show("Invalid move " + move); } else { RegHumanMove(move); if (winning(1)) { MessageBox.Show(this, "You win"); DumpHistory(); ai = new NewAiPlayer(); } else { ai.RegOppMove(move); move = ai.GetMove(); RegAiMove(move); if (winning(-1)) { MessageBox.Show("You lost"); DumpHistory(); ai = new NewAiPlayer(); } } } }
private void InitBoard() { picboard = new MyPicBox[15, 15]; for (int x = 0; x < picboard.GetLength(0); ++x) { for (int y = 0; y < picboard.GetLength(1); ++y) { board[x, y] = 0; picboard[x, y] = new MyPicBox(); picboard[x, y].Image = (Image)(empty.Image).Clone(); picboard[x, y].Location = new System.Drawing.Point(x * 32, y * 32); this.picboard[x, y].Name = "picboard_" + x + "_" + y; this.picboard[x, y].Size = new System.Drawing.Size(32, 32); this.picboard[x, y].SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; this.picboard[x, y].TabIndex = 0; picboard[x, y].x = x; picboard[x, y].y = y; panel1.Controls.Add(picboard[x, y]); this.picboard[x, y].Click += new System.EventHandler(this.field_Click); } } }