Пример #1
0
        public XleGameControl(
            IXleScreen screen,
            IStatsDisplay statsDisplay,
            IXleWaiter waiter,
            IXleInput input,
            ISoundMan soundMan,
            ITextArea textArea,
            GameState gameState,
            XleSystemState systemState)
        {
            this.screen       = screen;
            this.statsDisplay = statsDisplay;
            this.waiter       = waiter;
            this.input        = input;
            this.soundMan     = soundMan;
            this.textArea     = textArea;
            this.gameState    = gameState;
            this.systemState  = systemState;

            soundMan.ErrorMessage += message =>
            {
                textArea.PrintLine();
                textArea.PrintLine(message);
            };

            textArea.Waiter += WaitAsync;
        }
Пример #2
0
        private async Task OutputException(Exception exception)
        {
            if (exception is AggregateException agg && agg.InnerExceptions.Count == 1)
            {
                await OutputException(agg.InnerException);

                return;
            }

            try
            {
                inputPrompt = false;

                await textArea.PrintLine();

                await textArea.PrintLine(WrapText($"Error: {exception.GetType()}"), Color.Red);

                await textArea.PrintLine(WrapText(exception.Message), Color.Red);

                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
            }
            catch (Exception exx)
            {
                int j = 4;
            }
            finally
            {
                await Prompt();
            }
        }
Пример #3
0
        /// <summary>
        /// Asks the user to choose a number.
        /// </summary>
        /// <param name="max">The maximum value the user is allowed to select.</param>
        /// <returns></returns>
        public async Task <int> ChooseNumber(int max)
        {
            int method = 0;
            int amount = 0;

            await TextArea.PrintLine();

            await TextArea.Print("Enter number by ", XleColor.White);

            await TextArea.Print("keyboard", XleColor.Yellow);

            await TextArea.Print(" or ", XleColor.White);

            await TextArea.Print("joystick", XleColor.Cyan);

            await TextArea.PrintLine();

            await TextArea.PrintLine();

            Keys key;

            do
            {
                key = await gameControl.WaitForKey(showPrompt : false);

                if (method == 0)
                {
                    switch (key)
                    {
                    case Keys.None:
                        break;

                    case Keys.Right:
                    case Keys.Up:
                    case Keys.Left:
                    case Keys.Down:

                        await TextArea.PrintLine("Use joystick - press button when done");

                        await TextArea.PrintLine();

                        await TextArea.PrintLine("  Horizontal - Slow change", XleColor.Cyan);

                        await TextArea.PrintLine("  Vertical   - Fast change", XleColor.Cyan);

                        await TextArea.PrintLine("                          - 0 -");

                        method = 2;

                        break;

                    default:
                        await TextArea.PrintLine("Keyboard entry-press return when done", XleColor.Yellow);

                        await TextArea.PrintLine();

                        await TextArea.PrintLine();

                        await TextArea.PrintLine("                          - 0 -");

                        method = 1;

                        break;
                    }
                }

                if (method == 1)
                {
                    if (key >= Keys.D0 && key <= Keys.D9)
                    {
                        amount = 10 * amount + key - Keys.D0;
                    }

                    if (key == Keys.Back)
                    {
                        amount /= 10;
                    }

                    amount = Math.Min(amount, max);
                    amount = Math.Max(amount, 0);

                    await TextArea.RewriteLine(4, "                          - " + amount.ToString() + " -");
                }
                else if (method == 2)
                {
                    switch (key)
                    {
                    case Keys.Right:
                        amount++;
                        break;

                    case Keys.Up:
                        amount += 20;
                        break;

                    case Keys.Left:
                        amount--;
                        break;

                    case Keys.Down:
                        amount -= 20;
                        break;
                    }

                    if (amount > max)
                    {
                        amount = max;
                    }

                    if (amount < 0)
                    {
                        amount = 0;
                    }

                    await TextArea.RewriteLine(4, "                          - " + amount.ToString() + " -");
                }
            } while (key != Keys.Enter);

            await TextArea.PrintLine();

            return(amount);
        }
Пример #4
0
        public async Task <int> QuickMenuCore(MenuItemList items, int spaces, int value, Color clrInit, Color clrChanged)
        {
            Require.That <ArgumentOutOfRangeException>(value >= 0, "value should be positive");
            Require.That <ArgumentOutOfRangeException>(value < items.Count, "value should be less than items.Count");

            int    result = value;
            string topLine;
            string bulletLine;
            int    lineIndex = TextArea.CursorLocation.Y;

            Color[] colors = new Color[40];

            if (lineIndex >= 4)
            {
                lineIndex = 3;
            }

            for (int i = 0; i < 40; i++)
            {
                colors[i] = clrChanged;
            }

            int[] spacing = new int[items.Count];
            int   last    = 0;

            spacing[0] = 8;

            // Construct the temporary line
            string tempLine = "Choose: ";

            for (int i = 0; i < items.Count; i++)
            {
                bulletLine = items[i];

                tempLine += bulletLine + new string(' ', spaces);

                spacing[i] += last + bulletLine.Length - 1;
                last        = spacing[i] + spaces + 1;
            }

            await TextArea.PrintLine(tempLine, clrInit);

            await TextArea.PrintLine();

            topLine  = tempLine;
            tempLine = new string(' ', spacing[result]) + "`";

            await TextArea.RewriteLine(lineIndex + 1, tempLine, clrInit);

            Keys key;

            do
            {
                key = await gameControl.WaitForKey(showPrompt : false);

                if (key == Keys.Left)
                {
                    result--;
                    if (result < 0)
                    {
                        result = 0;
                    }
                }
                if (key == Keys.Right)
                {
                    result++;
                    if (result >= items.Count)
                    {
                        result = items.Count - 1;
                    }
                }
                else if (key >= Keys.D0)
                {
                    for (int i = 0; i < items.Count; i++)
                    {
                        bulletLine = items[i];

                        if (key - Keys.A ==
                            char.ToUpperInvariant(bulletLine[0]) - 'A')
                        {
                            result = i;
                            key    = Keys.Enter;
                        }
                    }
                }

                tempLine = new string(' ', spacing[result]) + "`";

                if (key != Keys.None)
                {
                    await TextArea.RewriteLine(lineIndex, topLine, clrChanged);

                    await TextArea.RewriteLine(lineIndex + 1, tempLine, clrChanged);
                }
            } while (key != Keys.Enter);

            await gameControl.WaitAsync(100);

            await TextArea.PrintLine();

            return(result);
        }
Пример #5
0
        public override async Task Execute()
        {
            await textArea.PrintLine("-choose above", XleColor.Cyan);

            Player.CurrentWeapon = await equipmentPicker.PickWeapon(Player.CurrentWeapon);
        }