Commits

Kevin Berridge committed ac8afba

renamed Player to Winner

  • Participants
  • Parent commits 76f341e

Comments (0)

Files changed (7)

File RockPaperScissors.Specs/GameSpecs.cs

   [Subject( "Round" )]
   public class when_playing_a_round
   {
-    static Player winner1;
-    static Player winner2;
-    static Player winner3;
-    static Player winner4;
-    static Player winner5;
-    static Player winner6;
-    static Player winner7;
-    static Player winner8;
-    static Player winner9;
+    static Winner winner1;
+    static Winner winner2;
+    static Winner winner3;
+    static Winner winner4;
+    static Winner winner5;
+    static Winner winner6;
+    static Winner winner7;
+    static Winner winner8;
+    static Winner winner9;
 
     Because of = () =>
     {
 
     It should_pick_rock_over_scissors = () =>
     {
-      winner1.ShouldEqual( Player.First );
-      winner2.ShouldEqual( Player.Second );
+      winner1.ShouldEqual( Winner.First );
+      winner2.ShouldEqual( Winner.Second );
     };
 
     It should_pick_scissors_over_paper = () =>
     {
-      winner3.ShouldEqual( Player.First );
-      winner4.ShouldEqual( Player.Second );
+      winner3.ShouldEqual( Winner.First );
+      winner4.ShouldEqual( Winner.Second );
     };
 
     It should_pick_paper_over_rock = () =>
     {
-      winner5.ShouldEqual( Player.First );
-      winner6.ShouldEqual( Player.Second );
+      winner5.ShouldEqual( Winner.First );
+      winner6.ShouldEqual( Winner.Second );
     };
 
-    It should_draw_on_rock_rock = () => winner7.ShouldEqual( Player.Draw );
+    It should_draw_on_rock_rock = () => winner7.ShouldEqual( Winner.Draw );
 
-    It should_draw_on_scissors_scissors = () => winner8.ShouldEqual( Player.Draw );
+    It should_draw_on_scissors_scissors = () => winner8.ShouldEqual( Winner.Draw );
     
-    It should_draw_on_paper_paper = () => winner9.ShouldEqual( Player.Draw );
+    It should_draw_on_paper_paper = () => winner9.ShouldEqual( Winner.Draw );
   }
 
   [Subject( "Single Round" )]
     static bool shouldPlayAgainIfNoGamesPlayed;
     static bool shouldPlayAgainIfOneGameWon;
     static bool shouldPlayAgainIfDraws;
-    static Player whoWon;
+    static Winner whoWon;
 
     Because of = () =>
     {
-      List<Player> gameResults = new List<Player>();
+      List<Winner> gameResults = new List<Winner>();
       SingleRoundStrategy srs = new SingleRoundStrategy();
 
       shouldPlayAgainIfNoGamesPlayed = srs.ShouldPlayAgain( gameResults );
 
-      gameResults.Add( Player.First );
+      gameResults.Add( Winner.First );
 
       shouldPlayAgainIfOneGameWon = srs.ShouldPlayAgain( gameResults );
 
-      gameResults = new List<Player>();
-      gameResults.Add( Player.Draw );
-      gameResults.Add( Player.Draw );
+      gameResults = new List<Winner>();
+      gameResults.Add( Winner.Draw );
+      gameResults.Add( Winner.Draw );
 
       shouldPlayAgainIfDraws = srs.ShouldPlayAgain( gameResults );
 
-      gameResults.Add( Player.First );
+      gameResults.Add( Winner.First );
 
       whoWon = srs.GetWhoWon( gameResults );
     };
     It should_play_again_if_games_drawn_but_none_won = () => shouldPlayAgainIfDraws.ShouldBeTrue();
 
     It should_know_who_won = () =>
-      whoWon.ShouldEqual( Player.First );
+      whoWon.ShouldEqual( Winner.First );
   }
 
   [Subject( "Input" )]

File RockPaperScissors/IKnowWhoWon.cs

 {
   public interface IKnowWhoWon
   {
-    Player GetWhoWon( List<Player> gameResults );
+    Winner GetWhoWon( List<Winner> gameResults );
   }
 }

File RockPaperScissors/IShouldPlayAgain.cs

 {
   public interface IShouldPlayAgain
   {
-    bool ShouldPlayAgain( List<Player> gameResults );
+    bool ShouldPlayAgain( List<Winner> gameResults );
   }
 }

File RockPaperScissors/Player.cs

 
 namespace RockPaperScissors
 {
-  public enum Player
+  public enum Winner
   {
     First,
     Second,

File RockPaperScissors/Program.cs

     {
       RockPaperScissors rps = new RockPaperScissors();
       SingleRoundStrategy srs = new SingleRoundStrategy();
-      List<Player> gameResults = new List<Player>();
+      List<Winner> gameResults = new List<Winner>();
       while ( srs.ShouldPlayAgain( gameResults ) )
       {
         Move player1Move = PromptForMove();
         Move player2Move = PromptForMove();
 
-        Player winner = rps.Play( player1Move, player2Move );
+        Winner winner = rps.Play( player1Move, player2Move );
         gameResults.Add( winner );
 
-        if ( winner == Player.Draw )
+        if ( winner == Winner.Draw )
           Console.WriteLine( "It's a draw" );
         else
-          Console.WriteLine( ( winner == Player.First ? "Player1" : "Player2" ) + " Wins!" );
+          Console.WriteLine( ( winner == Winner.First ? "Player1" : "Player2" ) + " Wins!" );
       }
 
-      Player bigWinner = srs.GetWhoWon( gameResults );
+      Winner bigWinner = srs.GetWhoWon( gameResults );
       Console.WriteLine();
-      Console.WriteLine( ( bigWinner == Player.First ? "Player1" : "Player2" ) + " Wins it all!" );
+      Console.WriteLine( ( bigWinner == Winner.First ? "Player1" : "Player2" ) + " Wins it all!" );
 
       Console.ReadLine();
     }

File RockPaperScissors/RockPaperScissors.cs

 {
   public class RockPaperScissors
   {
-    public Player Play( Move player1Move, Move player2Move )
+    public Winner Play( Move player1Move, Move player2Move )
     {
       switch ( player1Move )
       {
         case Move.Rock:
-          if ( player2Move == Move.Scissors ) return Player.First;
-          else if ( player2Move == Move.Rock ) return Player.Draw;
-          else return Player.Second;
+          if ( player2Move == Move.Scissors ) return Winner.First;
+          else if ( player2Move == Move.Rock ) return Winner.Draw;
+          else return Winner.Second;
         case Move.Scissors:
-          if ( player2Move == Move.Paper ) return Player.First;
-          else if ( player2Move == Move.Scissors ) return Player.Draw;
-          else return Player.Second;
+          if ( player2Move == Move.Paper ) return Winner.First;
+          else if ( player2Move == Move.Scissors ) return Winner.Draw;
+          else return Winner.Second;
         case Move.Paper:
-          if ( player2Move == Move.Rock ) return Player.First;
-          else if ( player2Move == Move.Paper ) return Player.Draw;
-          else return Player.Second;
+          if ( player2Move == Move.Rock ) return Winner.First;
+          else if ( player2Move == Move.Paper ) return Winner.Draw;
+          else return Winner.Second;
         default:
           throw new NotSupportedException( "No matches" );
       }

File RockPaperScissors/SingleRoundStrategy.cs

 {
   public class SingleRoundStrategy : IShouldPlayAgain, IKnowWhoWon
   {
-    public bool ShouldPlayAgain( List<Player> gameResults )
+    public bool ShouldPlayAgain( List<Winner> gameResults )
     {
-      return FindFirstWinner( gameResults ) == Player.Draw;
+      return FindFirstWinner( gameResults ) == Winner.Draw;
     }
 
-    public Player GetWhoWon( List<Player> gameResults )
+    public Winner GetWhoWon( List<Winner> gameResults )
     {
       return FindFirstWinner( gameResults );
     }
 
-    Player FindFirstWinner( List<Player> gameResults )
+    Winner FindFirstWinner( List<Winner> gameResults )
     {
-      if ( gameResults == null || gameResults.Count == 0 ) return Player.Draw;
+      if ( gameResults == null || gameResults.Count == 0 ) return Winner.Draw;
 
-      foreach ( Player p in gameResults ) // find first winner
-        if ( p != Player.Draw ) return p;
+      foreach ( Winner p in gameResults ) // find first winner
+        if ( p != Winner.Draw ) return p;
 
-      return Player.Draw;
+      return Winner.Draw;
     }
   }
 }