Beispiel #1
0
        /// <summary> Show an estimated countdown to a region's next update </summary>
        public async Task Run()
        {
            var regions = await RepoRegionDump.Dump(Shared.UserAgent, Shared.UserTags).Regions(true);

            var targetIndex = -1;

            // Get target region from argument if it was provided
            if (argument != null)
            {
                targetIndex = regions.FindIndex(r => r.Name.ToLower() == argument.ToLower());
            }

            // Get target region from user (ask again if given target doesn't exist)
            while (targetIndex < 0)
            {
                UIConsole.Show("\nTarget Region: ");
                var t = UIConsole.GetInput();
                t = ResolveRegionName(t);

                if (t == "")
                {
                    return;
                }
                targetIndex = regions.FindIndex(r => r.Name.ToLower() == t.ToLower());
                if (targetIndex == -1)
                {
                    UIConsole.Show("Region name not found.\n");
                }
            }

            timer = new Kronos.Commands.Timer(regions[targetIndex].Name);

            #pragma warning disable CS4014
            timer.Run(Shared.UserAgent, Shared.UserTags, true);
            #pragma warning restore CS4014

            // Show timer header
            UIConsole.Show("Press [Q] to quit Timer.\n\n");
            UIConsole.Show($"{" Time".PadRight(9, ' ')} | {"Trigger".PadRight(7, ' ')} | Variance \n");
            UIConsole.Show($"{"".PadRight(10, '-')} {"".PadRight(9, '-')} {"".PadRight(12, '-')}\n");


            // Display the timer asynchronously so that it counts down consistently.
            await ShowUpdateTimer();

            // Tell timer to stop, if still running (in case user interrupted)
            timer.Stop();

            UIConsole.Show("\n\n");
        }
Beispiel #2
0
        public void Run()
        {
            UI.DisplayText("Beginning Yatzy Game!\n");

            while (Category.Categories.Count > 0)
            {
                UI.DisplayText($"Number of categories {Category.Categories.Count}\n");
                Player.RunRollTurn(3, UIConsole);

                UI.DisplayText($"\nPlayer's final dice hand is: ");
                UI.DisplayDiceHand(Player.DiceHand);

                // TODO: Refactor
                var hasSelectedCategory = true;
                while (hasSelectedCategory)
                {
                    UI.DisplayText("\nChoose a Category: ");
                    UI.DisplayCategories(Category.Categories);
                    var selectedCategory = UIConsole.GetInput();
                    try
                    {
                        if (Category.ValidateCategoryInput(selectedCategory))
                        {
                            hasSelectedCategory = false;
                        }
                        else
                        {
                            throw new Exception();
                        }
                        Category.RemoveCategory(selectedCategory);
                        Player.FormatDiceHand();
                        Score.AddScoreToTotal(Score.CalculateScore(Player.DiceHandValues, selectedCategory));
                        UI.DisplayText($"\nYour total is now: {Score.Total}\n");
                    }
                    catch (Exception)
                    {
                        UI.DisplayText("Invalid input! Please select a category: ");
                    }
                }
                Player.Reset();
            }
            UI.DisplayText("Game ending...");
        }