Source

RockPaperScissors / RockPaperScissors / SingleRoundStrategy.cs

Full commit
Kevin Berridge c3af1d3 










Kevin Berridge 2dec106 
Kevin Berridge c3af1d3 



Kevin Berridge 2dec106 

Kevin Berridge c3af1d3 
Kevin Berridge 2dec106 







Kevin Berridge c3af1d3 

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

namespace RockPaperScissors
{
  public class SingleRoundStrategy : IShouldPlayAgain, IKnowWhoWon
  {
    public bool ShouldPlayAgain( List<Player> gameResults )
    {
      return FindFirstWinner( gameResults ) == Player.Draw;
    }

    public Player GetWhoWon( List<Player> gameResults )
    {
      return FindFirstWinner( gameResults );
    }

    Player FindFirstWinner( List<Player> gameResults )
    {
      if ( gameResults == null || gameResults.Count == 0 ) return Player.Draw;

      foreach ( Player p in gameResults ) // find first winner
        if ( p != Player.Draw ) return p;

      return Player.Draw;
    }
  }
}