Пример #1
0
        public void CanClearAutoDictionary()
        {
            AutoDictionary <string, bool> tested = new AutoDictionary <string, bool>()
            {
                { "hello", true },
                { "world", true }
            };

            tested.Clear();
            Assert.AreEqual(0, tested.Count);
            Assert.AreEqual(false, tested["hello"]);
            Assert.AreEqual(false, tested.ContainsKey("hello"));
            Assert.AreEqual(false, tested["world"]);
        }
Пример #2
0
 public bool Contains(KeyValuePair <string, string> item) => inner.ContainsKey(item.Key.ToLower());
Пример #3
0
 public bool HasOutput(string name)
 {
     return(myOutputDictionary.ContainsKey(name));
 }
Пример #4
0
        static void Main()
        {
            Console.OutputEncoding = Encoding.UTF8;
            Console.WindowWidth    = 200;
            Console.WindowHeight   = 40;

            var curUser = Environment.UserName;

            curUser = curUser.Substring(0, 1).ToUpper() + curUser.Substring(1).ToLower();
            Settings settings;

            SettingsUtil.LoadSettings(out settings);
            var highscore = settings.Highscores[curUser];

            var recent = new AutoDictionary <string, Highscore>(_ => new Highscore());
            int cur    = 0;
            ConsoleColoredString lastAttemptOutcome = null;

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Current highscores, in milliseconds:");
                WriteToConsole(settings.Highscores.Concat(recent).ToDictionary());

                if (lastAttemptOutcome != null)
                {
                    Console.WriteLine();
                    ConsoleUtil.WriteLine("Last attempt: " + lastAttemptOutcome);
                }

                Console.WriteLine();
                Console.WriteLine("Type every letter A-Z exactly once, either alphabetically or in any order. Wait 1 second when done, or press space to restart.");
                Console.WriteLine();

                var pressed = new Dictionary <char, DateTime>();
                Console.Title = string.Join(" ", Enumerable.Range('A', 26).Select(x => (char)x).Except(pressed.Keys).OrderBy(x => x));
                while (true)
                {
                    var key = Console.ReadKey(true);
                    Console.Write((key.KeyChar + " ").ToUpper());

                    if (key.KeyChar < 'a' || key.KeyChar > 'z')
                    {
                        break;
                    }
                    var chr = char.ToUpper(key.KeyChar);

                    if (pressed.ContainsKey(chr))
                    {
                        break;
                    }
                    pressed[chr]  = DateTime.UtcNow;
                    Console.Title = string.Join(" ", Enumerable.Range('A', 26).Select(x => (char)x).Except(pressed.Keys).OrderBy(x => x));

                    if (pressed.Count == 26)
                    {
                        break;
                    }
                }

                Console.WriteLine();
                Console.WriteLine('\x7');

                if (pressed.Count == 26)
                {
                    Console.WriteLine("Don't press anything now, to confirm you've typed just the 26 letters accurately and nothing else!");
                    var wait = DateTime.UtcNow;
                    while (DateTime.UtcNow < wait + TimeSpan.FromSeconds(1) && !Console.KeyAvailable)
                    {
                        Thread.Sleep(10);
                    }
                }

                if (pressed.Count == 26 && !Console.KeyAvailable)
                {
                    UpdateHighscore(highscore, pressed);
                    cur++;
                    UpdateHighscore(recent[$"Recent: {cur:00}"], pressed);
                    if (recent.ContainsKey($"Recent: {cur - 20:00}"))
                    {
                        recent.Remove($"Recent: {cur - 20:00}");
                    }

                    lastAttemptOutcome = "";
                    char expected   = 'A';
                    bool alphabetic = true;
                    foreach (var kvp in pressed.OrderBy(kvp => kvp.Value))
                    {
                        if (kvp.Key != expected)
                        {
                            alphabetic = false;
                        }
                        lastAttemptOutcome += $"{kvp.Key} ".Color(kvp.Key != expected ? ConsoleColor.Red : alphabetic ? ConsoleColor.Green : ConsoleColor.White);
                        expected            = (char)(kvp.Key + 1);
                    }
                    lastAttemptOutcome = (alphabetic ? "ALPHABETIC" : "any order") + " " + lastAttemptOutcome;

                    settings.Save();
                }
                else
                {
                    lastAttemptOutcome = "OOPS!...".Color(ConsoleColor.Magenta);
                }

                Console.WriteLine();
                Console.WriteLine();
            }
        }