Skip to content

Latest commit

 

History

History
61 lines (55 loc) · 1.49 KB

File metadata and controls

61 lines (55 loc) · 1.49 KB

Pergunta

40 - Escreve documentação em formato XML para o método RockPaperScissors apresentado em baixo, seguindo as melhores práticas para o efeito. Os valores ROCK, PAPER e SCISSORS devem ser considerados como constantes inteiras.

static int RockPaperScissors(int player1, int player2)
{
    if (player1 == player2)
    {
        return 0; // Draw
    }
    if (((player1 == ROCK) && (player2 == SCISSORS)) ||
        ((player1 == SCISSORS) && (player2 == PAPER)) ||
        ((player1 == PAPER) && (player2 == ROCK)))
    {
        return 1; // Player 1 wins
    }
    else
    {
        return 2; // Player 2 wins
    }
}

Soluções

Solução 1

/// <summary>
/// This method will determine which player will win the game by following
/// simple rules: Rock beats Scissors, Scissors beat Paper and
/// Paper beats Rock.
/// </summary>
/// <param name="player1">Choice of player 1</param>
/// <param name="player2">Choice of player 2</param>
/// <returns>
/// Returns a number, 0, 1 or 2, depending on the result of the game
///</returns>
static int RockPaperScissors(int player1, int player2)
{
    if (player1 == player2)
    {
        return 0; // Draw
    }
    if (((player1 == ROCK) && (player2 == SCISSORS)) ||
        ((player1 == SCISSORS) && (player2 == PAPER)) ||
        ((player1 == PAPER) && (player2 == ROCK)))
    {
        return 1; // Player 1 wins
    }
    else
    {
        return 2; // Player 2 wins
    }
}

Por Lucas Viana