Ejemplo n.º 1
0
        public void SelectTool(ToolDatabase toolDatabase)
        {
            Random random    = new Random();
            int    toolIndex = random.Next(toolDatabase.Tools.Count);

            SelectedTool = toolDatabase.Tools[toolIndex];
        }
Ejemplo n.º 2
0
 public void SelectTool(ToolDatabase toolDatabase)
 {
     string inputChoice;
     IToolChoice matchedTool;
     do
     {
         Console.WriteLine("Do you want to play Rock (R), Paper (P), or Scissors (S)?");
         inputChoice = Console.ReadLine();
     
     }
     while (IsChoiceInvalid(inputChoice, toolDatabase, out matchedTool));
     SelectedTool = matchedTool;
 }
Ejemplo n.º 3
0
 bool IsChoiceInvalid(string choice, ToolDatabase toolDatabase, out IToolChoice matchedTool)
 {
     foreach (var tool in toolDatabase.Tools)
     {
         if(choice.ToLower() == tool.Name.ToLower(), StringComparer.InvariantCultureIgnoreCase))
         {
             matchedTool = tool;
             return true;
         }
     }
 
     Console.WriteLine("Invalid Response. Please choose a valid letter response.");
     matchedTool = null;
     return false;
 }