Commits

Kevin Berridge  committed 9708ec5

Gets player names

  • Participants
  • Parent commits ac8afba

Comments (0)

Files changed (1)

File RockPaperScissors/Program.cs

       RockPaperScissors rps = new RockPaperScissors();
       SingleRoundStrategy srs = new SingleRoundStrategy();
       List<Winner> gameResults = new List<Winner>();
+
+      string player1Name, player2Name;
+      Console.Write( "Player 1 Name: " );
+      player1Name = Console.ReadLine();
+
+      Console.Write( "Player 2 Name: " );
+      player2Name = Console.ReadLine();
+
       while ( srs.ShouldPlayAgain( gameResults ) )
       {
         Move player1Move = PromptForMove();
         if ( winner == Winner.Draw )
           Console.WriteLine( "It's a draw" );
         else
-          Console.WriteLine( ( winner == Winner.First ? "Player1" : "Player2" ) + " Wins!" );
+          Console.WriteLine( GetPlayerName( winner, player1Name, player2Name )  + " Wins!" );
       }
 
       Winner bigWinner = srs.GetWhoWon( gameResults );
       Console.WriteLine();
-      Console.WriteLine( ( bigWinner == Winner.First ? "Player1" : "Player2" ) + " Wins it all!" );
+      Console.WriteLine( GetPlayerName( bigWinner, player1Name, player2Name ) + " Wins it all!" );
 
       Console.ReadLine();
     }
 
       return m;
     }
+
+    static string GetPlayerName( Winner w, string player1Name, string player2Name )
+    {
+      if ( w == Winner.First )
+        return player1Name;
+      else if ( w == Winner.Second )
+        return player2Name;
+      else
+        throw new ArgumentOutOfRangeException( "The Winner must be either First or Second" );
+    }
   }
 }