/// <summary> /// Update the images of the players on the UI /// </summary> private void updateImagePlayer() { //Transparency if (board.GetTurn()) { ImageBlack.Opacity = 0.5; ImageWhite.Opacity = 1; } else { ImageWhite.Opacity = 0.5; ImageBlack.Opacity = 1; } //Crown if (board.GetWhiteScore() > board.GetBlackScore()) { ImageCrownWhite.Visibility = Visibility.Visible; ImageCrownBlack.Visibility = Visibility.Hidden; } else if (board.GetWhiteScore() < board.GetBlackScore()) { ImageCrownWhite.Visibility = Visibility.Hidden; ImageCrownBlack.Visibility = Visibility.Visible; } }
/// <summary> /// /// </summary> private void CheckFinished() { if (board.IsFinished()) { // Partie terminée var scoreBlack = board.GetBlackScore(); var scoreWhite = board.GetWhiteScore(); UpdateUI(true); // Affichage du gagnant string winner; if (scoreBlack > scoreWhite) { winner = $"Gagnant : {NOIR}"; } else if (scoreWhite > scoreBlack) { winner = $"Gagnant : {BLANC}"; } else { winner = "Match nul"; } var m = MessageBox.Show($"Score joueur noir : {board.GetBlackScore()}\nScore joueur blanc : {board.GetWhiteScore()}\n{winner}\n\nSouhaitez-vous relancer une partie ?", "Partie terminée !", MessageBoxButton.YesNo); if (m == MessageBoxResult.Yes) { // Recommence une partie StartGame(); } else { // Ferme l'application Close(); } } else { // Partie pas terminée UpdateUI(false); contextPlayers.WhiteTurn = whiteTurn; contextPlayers.Timer.Start(); } }
/// <summary> /// Called when mouse click is released on canvas board. Makes moves for player and IA /// </summary> /// <param name="sender">sender object</param> /// <param name="e">mouse event</param> private void CanBoard_MouseUp(object sender, MouseButtonEventArgs e) { //If game as started and it is player turn if (isPlaying && (!isIA || turnToWhite)) { //Getting canvas board dimensions double canvasHeight = canBoard.ActualHeight / 8.0; double canvasWidth = canBoard.ActualWidth / 8.0; //Getting mouse positions double eX = e.GetPosition(canBoard).X; double eY = e.GetPosition(canBoard).Y; //Setting counter positions int squareIdI = (int)(eX / canvasWidth); int squareIdJ = (int)(eY / canvasHeight); //If move can be played if (board.IsPlayable(squareIdI, squareIdJ, turnToWhite)) { //Move is played bool changePlayer = board.PlayMove(squareIdI, squareIdJ, turnToWhite); //If game is finished if (board.Ended) { //Displaying a label with the winner DisplayWinner(); } //Changing players if (changePlayer) { turnToWhite = !turnToWhite; } } } //If game as started and it is IA turn if (isPlaying && isIA && !turnToWhite) { bool changePlayer = false; while (!changePlayer && !board.Ended) { //IA finds its next move to play Tuple <int, int> IA = board.GetNextMove(board.GetBoard(), 1, turnToWhite); //Move is played changePlayer = board.PlayMove(IA.Item1, IA.Item2, turnToWhite); //If game is finished if (board.Ended) { //Displaying a label with the winner DisplayWinner(); } } //Changing players if (changePlayer) { turnToWhite = !turnToWhite; } } //Updating board PrintBoard(); //Updating scores this.WhiteScore = board.GetWhiteScore(); this.BlackScore = board.GetBlackScore(); }