void b_Click(object sender, EventArgs e) { Button b = (Button)sender; Point p = (Point)b.Tag; model.MakeMove(p.X, p.Y, model.CurrentTurn); }
public void BotMove(GameModel model) { Random rnd = new Random(); for (int i = 0; i < model.Field.GetLength(0); ++i) { for (int j = 0; j < model.Field.GetLength(1); ++j) { if (model.Field[i, j] == GameModel.State.none) { Coordinate temp = new Coordinate(); temp.i = i; temp.j = j; freeСells.Add(temp); } } } do { try { Coordinate SelectedMove = freeСells[rnd.Next(0, freeСells.Count)]; model.MakeMove(SelectedMove.i, SelectedMove.j, model.CurrentMove); break; } catch (Exception) { continue; } } while (true); }
public void MakeMove(int i, int j, GameModel.State side) { model.MakeMove(i, j, side); if (model.GameOver) { MessageBox.Show("Game Over, winner is " + symbols[model.Winner] + "\n" + "Count of X's winners: " + GameModel.countXWin + "\n" + "Count of O's winners: " + GameModel.countOWin + "\n" + "Count of draws: " + GameModel.draw); DialogResult result = MessageBox.Show("Would you like to play again?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); if (result == DialogResult.Yes) { model = new GameModel(); model.UpdateView += UpdateView; UpdateView(model); } else { this.Close(); } } }