Source

RockPaperScissors / RockPaperScissors / Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RockPaperScissors
{
  class Program
  {
    static void Main( string[] args )
    {
      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();
        Move player2Move = PromptForMove();

        Winner winner = rps.Play( player1Move, player2Move );
        gameResults.Add( winner );

        if ( winner == Winner.Draw )
          Console.WriteLine( "It's a draw" );
        else
          Console.WriteLine( GetPlayerName( winner, player1Name, player2Name )  + " Wins!" );
      }

      Winner bigWinner = srs.GetWhoWon( gameResults );
      Console.WriteLine();
      Console.WriteLine( GetPlayerName( bigWinner, player1Name, player2Name ) + " Wins it all!" );

      Console.ReadLine();
    }

    static Move PromptForMove()
    {
      Move m = Move.Rock;
      bool hasMove = false;
      while ( !hasMove )
      {
        Console.Write( "[R]ock, [P]aper, or [S]cissors? " );
        ConsoleKeyInfo player1Key = Console.ReadKey();
        Console.WriteLine();

        try
        {
          m = InputConverter.Convert( player1Key.KeyChar );
          hasMove = true;
        }
        catch ( ArgumentOutOfRangeException )
        {
          Console.WriteLine( "Invalid selection" + Environment.NewLine );
        }
      }

      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" );
    }
  }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.