Exemplo n.º 1
0
        /// <summary>
        /// CheckWin() calls methods in the gameboard class to check if there is horizontal, vertical or diagnol win
        /// </summary>
        private void CheckWin()
        {
            /// These methods will return true or false depending if there was a win or not
            /// IsDiagonalWin variable is set to true if there is a diagnol win
            IsDiagonalWin = gb.IsDiagonalWin();
            /// isVertWin variable is set to true if there is a vertical win
            IsVertWin = gb.IsVertWin();
            /// isHorzWin variable is set to true if there is a horizontal win
            IsHorzWin = gb.IsHorzWin();


            //HighlightWinningMove();
            ///Checks to see if the if the methods from the Gameboard class return true
            ///If it does return true it will display the Player that won in the tb_player_wins
            if (IsDiagonalWin)
            {
                ///Check if it is player 1 for win
                if (player1.isTurn)
                {
                    ///Highlight winning row, column, diag
                    HighlightWinningMove();
                    ///if so increment player 2 score and set the tb to player 2 wins
                    player2.newPlayerScore();
                    ///sets the score for lbl_Player_2_value.Content score
                    lbl_Player_2_value.Content = player2.score;
                    ///sets the text of the status to player 2 wins
                    tb_player_wins.Text = "Player 2 Wins!!!";
                    ///sets the bisgamestarted to false to end selection
                    bisGameStarted = false;
                }
                ///Check if it is player 2 for win
                else if (player2.isTurn)
                {
                    ///Highlight winning row, column, diag
                    HighlightWinningMove();
                    ///Because they offset if it changes on a winning move it is player 1 points
                    player1.newPlayerScore();
                    ///sets the score for lbl_Player_1_value.Content score
                    lbl_Player_1_value.Content = player1.score;
                    ///sets the text of the status to player 1 wins
                    tb_player_wins.Text = "Player 1 Wins!!!";
                    ///sets the bisgamestarted to false to end selection
                    bisGameStarted = false;
                }
            }
            ///Checks to see if it a VertWin
            else if (IsVertWin)
            {
                ///Check if it is player 1 turn
                if (player1.isTurn)
                {
                    ///Highlight winning row, column, diag
                    HighlightWinningMove();
                    ///if so increment player 2 score and set the tb to player 2 wins
                    player2.newPlayerScore();
                    ///sets the score for lbl_Player_2_value.Content score
                    lbl_Player_2_value.Content = player2.score;
                    ///sets the text of the status to player 2 wins
                    tb_player_wins.Text = "Player 2 Wins!!!";
                    ///sets the bisgamestarted to false to end selection
                    bisGameStarted = false;
                }
                else if (player2.isTurn)
                {
                    ///Highlight winning row, column, diag
                    HighlightWinningMove();
                    ///Because they offset if it changes on a winning move it is player 1 points
                    player1.newPlayerScore();
                    ///sets the score for lbl_Player_1_value.Content score
                    lbl_Player_1_value.Content = player1.score;
                    ///sets the text of the status to player 1 wins
                    tb_player_wins.Text = "Player 1 Wins!!!";
                    ///sets the bisgamestarted to false to end selection
                    bisGameStarted = false;
                }
            }
            ///Checks to see if it a VertWin
            else if (IsHorzWin)
            {
                ///Check if it is player 1 turn
                if (player1.isTurn)
                {
                    ///Highlight winning row, column, diag
                    HighlightWinningMove();
                    ///if so increment player 2 score and set the tb to player 2 wins
                    player2.newPlayerScore();
                    ///sets the score for lbl_Player_2_value.Content score
                    lbl_Player_2_value.Content = player2.score;
                    ///sets the text of the status to player 2 wins
                    tb_player_wins.Text = "Player 2 Wins!!!";
                    ///sets the bisgamestarted to false to end selection
                    bisGameStarted = false;
                }
                else if (player2.isTurn)
                {
                    ///Highlight winning row, column, diag
                    HighlightWinningMove();
                    ///Because they offset if it changes on a winning move it is player 1 points
                    player1.newPlayerScore();
                    ///sets the score for lbl_Player_1_value.Content score
                    lbl_Player_1_value.Content = player1.score;
                    ///sets the text of the status to player 1 wins
                    tb_player_wins.Text = "Player 1 Wins!!!";
                    ///sets the bisgamestarted to false to end selection
                    bisGameStarted = false;
                }
            }
            else if (gb.IsTie())
            {
                ///increment tie score and set it to the ties value, then display Tie!!! try again
                tie++;
                ///set content to lbl_ties_value to tie total
                lbl_ties_value.Content = tie.ToString();
                ///sets the text of the status to Tie!!! Try Again.
                tb_player_wins.Text = "Tie!!! Try Again.";
                ///sets the bisgamestarted to false to end selection
                bisGameStarted = false;
            }
        }