Ejemplo n.º 1
0
    public bool TryBuyWatch()
    {
        if (!Table.Human.HasWatch)
        {
            return(false);
        }

        var response = _io.ReadString("Would you like to sell your watch");

        if (response.StartsWith("N", InvariantCultureIgnoreCase))
        {
            return(false);
        }

        var(value, message) = (_random.Next(10) < 7) switch
        {
            true => (75, "I'll give you $75 for it."),
            false => (25, "That's a pretty crummy watch - I'll give you $25.")
        };

        _io.WriteLine(message);
        Table.Human.SellWatch(value);
        // The original code does not have the computer part with any money

        return(true);
    }
Ejemplo n.º 2
0
    public void Play()
    {
        _io.Write(Resource.Streams.Introduction);
        if (!_io.ReadString("Do you want instructions").Equals("no", InvariantCultureIgnoreCase))
        {
            _io.Write(Resource.Streams.Instructions);
        }

        BuildBugs();

        _io.Write(Resource.Streams.PlayAgain);
    }
 internal static char GetYesNo(this IReadWrite io, string prompt)
 {
     while (true)
     {
         var response = io.ReadString($"{prompt} (Y-N)").FirstOrDefault();
         if ("YyNn".Contains(response))
         {
             return(char.ToUpperInvariant(response));
         }
     }
 }
Ejemplo n.º 4
0
    internal static string ReadYesNo(this IReadWrite io, string prompt)
    {
        while (true)
        {
            var response = io.ReadString(prompt).ToLower();

            if (response == "yes" || response == "no")
            {
                return(response);
            }

            io.Write(Streams.YesOrNo);
        }
    }
 internal static bool ReadYesNo(this IReadWrite io, string prompt)
 {
     while (true)
     {
         var response = io.ReadString(prompt);
         if (response.Equals("YES", InvariantCultureIgnoreCase))
         {
             return(true);
         }
         if (response.Equals("NO", InvariantCultureIgnoreCase))
         {
             return(false);
         }
         io.WriteLine("Answer Yes or No, please.");
     }
 }
Ejemplo n.º 6
0
 internal static bool ReadYes(this IReadWrite io, string prompt) =>
 io.ReadString(prompt).Equals("Yes", StringComparison.InvariantCultureIgnoreCase);