mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2026-01-06 01:57:58 -08:00
Removed spaces from top-level directory names.
Spaces tend to cause annoyances in a Unix-style shell environment. This change fixes that.
This commit is contained in:
42
74_Rock_Scissors_Paper/csharp/Choices.cs
Normal file
42
74_Rock_Scissors_Paper/csharp/Choices.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
|
||||
namespace RockScissorsPaper
|
||||
{
|
||||
public class Choices
|
||||
{
|
||||
public static readonly Choice Rock = new Choice("3", "Rock");
|
||||
public static readonly Choice Scissors = new Choice("2", "Scissors");
|
||||
public static readonly Choice Paper = new Choice("1", "Paper");
|
||||
|
||||
private static readonly Choice[] _allChoices;
|
||||
private static readonly Random _random = new Random();
|
||||
|
||||
static Choices()
|
||||
{
|
||||
Rock.CanBeat = Scissors;
|
||||
Scissors.CanBeat = Paper;
|
||||
Paper.CanBeat = Rock;
|
||||
|
||||
_allChoices = new[] { Rock, Scissors, Paper };
|
||||
}
|
||||
|
||||
public static Choice GetRandom()
|
||||
{
|
||||
return _allChoices[_random.Next(_allChoices.GetLength(0))];
|
||||
}
|
||||
|
||||
public static bool TryGetBySelector(string selector, out Choice choice)
|
||||
{
|
||||
foreach (var possibleChoice in _allChoices)
|
||||
{
|
||||
if (string.Equals(possibleChoice.Selector, selector))
|
||||
{
|
||||
choice = possibleChoice;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
choice = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user