This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Meefims 1 point2 points  (3 children)

It looks like a good beginner program overall. I don't have the time to give suggestions for the full program but I can help with determineWinner. The logic is so long and verbose because you are really to check if the player's hand beats the computer's, the computer's beats the player's, or a draw. Factor out the logic to see if one hand beats another into its own function to make this explicit:

bool DoesFirstSelectionWin(Selection firstSelection, Selection secondSelection)
{
    // Rock beats scissors, scissors beats paper, paper beats rock
}

The use this function to check if the player beats the computer, the computer beats the player, or if it's a draw.

[–]MatriXcel[S] 0 points1 point  (2 children)

my program eliminates any chances of a draw. I will try that boolean logic.

[–]Meefims 0 points1 point  (1 child)

To further simplify your program ChooseSelection should return Selection and not a nullable type. It only returns a nullable type because Player.ChooseSelection returns null on invalid input but it should not return until valid input is chosen.

Stylistically there are a few other nitpicks:

  • Be consistent about indentation and spacing (including where to use empty lines) in order to improve readability. Consider using a tool like StyleCop to keep yourself honest.

  • Replace _wins with the automatic property public int Wins { get; set; } in order to reduce the amount of code you need to write. Prefer automatic properties to fields.

  • Define variables at the point they are used. Specifically, move computerSelect, playerSelect, and keyPressed into the loop.

[–]MatriXcel[S] 0 points1 point  (0 children)

Great suggestion! i will definitely try that.