Example #1
0
        private async Task ProcessInput(Keys cmd, string keyString)
        {
            if (cmd == Keys.None)
            {
                return;
            }

            lastInput = cmd;

            int waitTime = 700;

            if (IsCursorMovement(cmd))
            {
                await ExecuteCursorMovement(cmd);

                return;
            }

            var command = commands.FindCommand(keyString);

            if (command != null)
            {
                commands.CurrentCommand = command;

                await textArea.Print(command.Name);

                await command.Execute();
            }
            else
            {
                soundMan.PlaySound(LotaSound.Invalid);

                await gameControl.WaitAsync(waitTime);

                inputPrompt = true;
                return;
            }

            await AfterDoCommand(waitTime, cmd);
        }
Example #2
0
        public override async Task Execute()
        {
            await TextArea.PrintLine();

            var player = GameState.Player;

            renderer.InventoryScreen = 0;

            using (gameControl.PushRenderer(renderer))
            {
                while (renderer.InventoryScreen < 2)
                {
                    await gameControl.WaitAsync(150);

                    await gameControl.WaitForKey();

                    renderer.InventoryScreen++;
                }
            }
        }
Example #3
0
        public override async Task Execute()
        {
            MenuItemList theList = new MenuItemList("1", "2", "3", "4", "5");

            await TextArea.PrintLine();

            await TextArea.PrintLine("** Change gamespeed **", XleColor.Yellow);

            await TextArea.PrintLine("    (1 is fastest)", XleColor.Yellow);

            await TextArea.PrintLine();

            Player.Gamespeed = 1 + await QuickMenu.QuickMenu(theList, 2, Player.Gamespeed - 1);

            await TextArea.Print("Gamespeed is: ", XleColor.Yellow);

            await TextArea.PrintLine(Player.Gamespeed.ToString(), XleColor.White);

            systemState.Factory.SetGameSpeed(GameState, Player.Gamespeed);

            await gameControl.WaitAsync(GameState.GameSpeed.AfterSetGamespeedTime);
        }
Example #4
0
 public static Task Wait(this IXleGameControl gameControl, int howLong)
 {
     return(gameControl.WaitAsync(howLong));
 }
Example #5
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);
        }
Example #6
0
        public override async Task Execute()
        {
            MenuItemList menuItems = new MenuItemList("Yes", "No");
            int          choice;
            bool         saved = false;

            await TextArea.PrintLine("\nWould you like to save");

            await TextArea.PrintLine("the game in progress?");

            await TextArea.PrintLine();

            choice = await menu.QuickMenu(menuItems, 2);

            if (choice == 0)
            {
                gamePersistance.Save(Player);

                saved = true;

                await TextArea.PrintLine();

                await TextArea.PrintLine("Game Saved.");

                await TextArea.PrintLine();
            }
            else
            {
                ColorStringBuilder builder = new ColorStringBuilder();

                await TextArea.PrintLine();

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

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

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

                await TextArea.PrintLine();

                await TextArea.PrintLine();
            }

            await gameControl.WaitAsync(1500);

            await TextArea.PrintLine("Quit and return to title screen?");

            if (saved == false)
            {
                await TextArea.PrintLine("Unsaved progress will be lost.", XleColor.Yellow);
            }
            else
            {
                await TextArea.PrintLine();
            }

            await TextArea.PrintLine();

            choice = await menu.QuickMenu(menuItems, 2, 1);

            if (choice == 0)
            {
                systemState.ReturnToTitle = true;
            }
        }
Example #7
0
        private async Task <int> RunSubMenu(SubMenu menu)
        {
            this.menu = menu;

            menuRenderer.Menu = menu;

            for (int i = 0; i < menu.theList.Count; i++)
            {
                if (menu.theList[i].Length + 6 > menu.width)
                {
                    menu.width = menu.theList[i].Length + 6;
                }
            }

            string displayTitle = "Choose " + menu.title;

            if (displayTitle.Length + 2 > menu.width)
            {
                menu.width = displayTitle.Length + 2;
            }

            try
            {
                gameControl.PushRenderer(menuRenderer);

                Keys key;

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

                    if (key == Keys.Up)
                    {
                        menu.value--;
                        if (menu.value < 0)
                        {
                            menu.value = 0;
                        }
                    }
                    if (key == Keys.Down)
                    {
                        menu.value++;
                        if (menu.value >= menu.theList.Count)
                        {
                            menu.value = menu.theList.Count - 1;
                        }
                    }
                    else if (key >= Keys.D0)
                    {
                        int v;

                        if (key >= Keys.A)
                        {
                            v  = (int)(key) - (int)(Keys.A);
                            v += 10;
                        }
                        else
                        {
                            v = key - Keys.D0;
                        }

                        if (v < menu.theList.Count)
                        {
                            menu.value = v;
                            key        = Keys.Enter;
                        }
                    }
                } while (key != Keys.Enter);

                await gameControl.WaitAsync(300);
            }
            finally
            {
                gameControl.PopRenderer(menuRenderer);
            }

            return(menu.value);
        }