Ejemplo n.º 1
0
        /// <summary>
        /// Method that verifies if someone won the game or if there is a draw.
        /// </summary>
        /// <returns>Return true if there is a draw or a win.</returns>
        private bool VerifyWin()
        {
            bool endMatch = false;

            // If players collide with each other at the same time
            if ((player1.DetectCollision(gameWorld) && player2.DetectCollision(gameWorld)) ||
                (player1.Row == player2.Row && player1.Column == player2.Column))
            {
                // End game as a draw
                endMatch = true;
                // NO PLAYER GETS POINTS
                // Render draw message
                renderer.RenderDraw();
                // Reset Game
                ResetGame();
            }
            // If player 1 collides
            else if (player1.DetectCollision(gameWorld))
            {
                // Player 2 Wins
                endMatch = true;
                // Increase Player Score
                player2.IncreaseScore();
                // Render Player 2 Message Wins
                renderer.RenderPlayer2Wins();
                // Reset Game
                ResetGame();
            }
            // If player 2 collides
            else if (player2.DetectCollision(gameWorld))
            {
                // Player 1 Wins
                endMatch = true;
                // Increase Player Score
                player1.IncreaseScore();
                // Render Player 1 Message Wins
                renderer.RenderPlayer1Wins();
                // Reset Game
                ResetGame();
            }

            // Returns true if there is a collision
            return(endMatch);
        }