private void SetPointPawn(Point point, GobangPlayer player) { main_chess[point.X, point.Y].GobangPlayer = player; main_chess[point.X, point.Y].StepNumber = PawnIndex++; LastPressPosition = point; CurrentPlayer = player; if (player == GobangPlayer.Player1) { Richard_Hu.CalculateAllPoints(); } }
private async void pictureBox1_Click(object sender, EventArgs e) { //press the chess board if (!IsGamePlaying) { return; } Point point_origin = pictureBox1.PointToClient(Cursor.Position); //check the position is correct if (point_origin.X % 25 > 20 || point_origin.X > 520) { return; } if (point_origin.Y % 25 > 20 || point_origin.Y > 520) { return; } Point point = MouseMovePoint(point_origin.X, point_origin.Y); // already has pawn if (IsPositionHasPawn(point)) { return; } if (CurrentPlayer != GobangPlayer.Player2) { SetPointPawn(point, GobangPlayer.Player2); LastPointOfPlayerUser = point; if (IsGameOver(point.X, point.Y, GobangPlayer.Player2)) { IsGamePlaying = false; label3.Text = "You Win"; label_score_you.Text = (Convert.ToInt32(label_score_you.Text) + 1).ToString(); } else { //waitting for computer to calculate label3.Text = "Thinking"; Point computer = await Richard_Hu.CalculateComputerAI(); SetPointPawn(computer, GobangPlayer.Player1); if (IsGameOver(computer.X, computer.Y, GobangPlayer.Player1)) { label3.Text = "You lose"; IsGamePlaying = false; label_score_computer.Text = (Convert.ToInt32(label_score_computer.Text) + 1).ToString(); } else { label3.Text = "waitting"; } pictureBox1.Refresh(); } } }