Пример #1
0
        public virtual List <Card> selectCardsOrNone(List <Card> fromList, int nUpToCardsToSelect, string question, string extraName = "none")
        {
            List <Card> resChoise = new List <Card>();

            for (int i = 0; i < nUpToCardsToSelect; ++i)
            {
                int decidedIndex = makeDescision(CardChoiseContext.WithNoneOption(fromList, question, extraName)) - 1;
                if (decidedIndex < 0)
                {
                    return(resChoise);
                }
                resChoise.Add(fromList[decidedIndex]);
                fromList.RemoveAt(decidedIndex);
            }
            return(resChoise);
        }
Пример #2
0
        public virtual List <Card> selectCards(List <Card> fromList, int nCardsToSelect, string question)
        {
            if (fromList.Count <= nCardsToSelect)
            {
                return(fromList);
            }
            List <Card> resChoise = new List <Card>();

            for (int i = 0; i < nCardsToSelect; ++i)
            {
                int decidedIndex = makeDescision(CardChoiseContext.Default(fromList, question));
                resChoise.Add(fromList[decidedIndex]);
                fromList.RemoveAt(decidedIndex);
            }
            return(resChoise);
        }
Пример #3
0
        public static int deckCreatingDialog(
            List <Card> deckCards,
            List <Card> collectionCads,
            ConsoleWindowText deckWindow,
            ConsoleWindowText collectionWindow,
            ConsoleWindowText descriptionWindow,
            ConsoleWindowText console)
        {
            CardChoiseContext choiseCollection =
                CardChoiseContext.WithNoneOption(collectionCads, "COLLECTION", "Finish deck building");
            CardChoiseContext choiseDeck =
                CardChoiseContext.WithNoneOption(deckCards, "DECK", "Save deck");

            // turning a deck into Card and Count

            Console.CursorVisible = false;

            PreviewType wasPreviewType = previewType;

            previewType = PreviewType.inCollection;

            collectionWindow.ClearLogWindow();
            collectionWindow.AddLog((choiseCollection.Question.Length == 0 ? "Make a descision:" : (choiseCollection.Question + ":")).PadRight(collectionWindow.Width), ConsoleColor.Yellow, ConsoleColor.DarkGreen);
            int collectionSelected = 0, collectionFromIndex = 0, deckSelected = 0, deckFromIndex = 0;

            RedrawScrollCollection(null, choiseCollection.ChoiseOptions, 0, 0, collectionWindow);
            RedrawScrollCollection(null, choiseDeck.ChoiseOptions, 0, 0, deckWindow);
            while (true)
            {
                RedrawScrollCollection(null, choiseCollection.ChoiseOptions, collectionSelected, collectionFromIndex, collectionWindow, true);
                RedrawScrollCollection(null, choiseDeck.ChoiseOptions, deckSelected, deckFromIndex, deckWindow, false);
                ScrollChooser(ref collectionSelected, ref collectionFromIndex, choiseCollection, collectionWindow, descriptionWindow, ConsoleKey.Tab, ConsoleKey.LeftArrow,
                              RedrawScrollCollection,
                              () =>
                {
                    if (collectionSelected == 0)
                    {
                        return;
                    }
                    deckCards.Add(collectionCads[collectionSelected - 1].spawnCard());
                    choiseDeck = CardChoiseContext.WithNoneOption(deckCards, "DECK", "Save deck");
                    RedrawScrollCollection(null, choiseDeck.ChoiseOptions, deckSelected, deckFromIndex, deckWindow, false);
                    DeckBuilder.Check(deckCards, console);
                });
                RedrawScrollCollection(null, choiseCollection.ChoiseOptions, collectionSelected, collectionFromIndex, collectionWindow, false);
                RedrawScrollCollection(null, choiseDeck.ChoiseOptions, deckSelected, deckFromIndex, deckWindow, true);
                ScrollChooser(ref deckSelected, ref deckFromIndex, choiseDeck, deckWindow, descriptionWindow, ConsoleKey.Tab, ConsoleKey.RightArrow,
                              RedrawScrollCollection,
                              () =>
                {
                    if (deckSelected == 0)
                    {
                        return;
                    }
                    choiseDeck.RemoveAt(deckSelected);
                    if (deckSelected >= choiseDeck.OptionsCount)
                    {
                        deckSelected = choiseDeck.OptionsCount - 1;
                    }
                    deckWindow.ClearLogWindow();
                    RedrawScrollCollection(null, choiseDeck.ChoiseOptions, deckSelected, deckFromIndex, deckWindow);
                    DeckBuilder.Check(deckCards, console);
                });
            }
            choiseCollection.HighlightSelected(-1);
            collectionWindow.ClearLogWindow();

            previewType = wasPreviewType;
            return(collectionSelected);
        }
Пример #4
0
 public virtual int chooseUnitsPlaceInRow(List <Unit> neigthboors)
 {
     return(makeDescision(CardChoiseContext.WithNoneOption(neigthboors, "Select a unit to left", "Become the most left")));
 }
Пример #5
0
        static void ScrollChooser(
            ref int answer, ref int intFrom,
            CardChoiseContext choise,
            ConsoleWindowText collectionWindow,
            ConsoleWindowText descriptionWindow,
            ConsoleKey exit,
            ConsoleKey use,
            UpdateCallBack redraw,
            CallBack onUseItem)
        {
            ConsoleKey pressed = ConsoleKey.NoName;

            do
            {
                pressed = Console.ReadKey().Key;
                // . . . . navigating in list
                List <int> needRedraw = new List <int>();
                if (pressed == ConsoleKey.DownArrow || pressed == ConsoleKey.UpArrow)
                {
                    int offset = pressed == ConsoleKey.DownArrow ? 1 : -1;
                    answer += offset;
                    if (answer < 0)
                    {
                        answer = choise.OptionsCount - 1;
                    }
                    if (answer > choise.OptionsCount - 1)
                    {
                        answer = 0;
                    }

                    if (answer < intFrom)
                    {
                        intFrom = answer;
                    }
                    if (answer > intFrom + collectionWindow.Heigth - 1)
                    {
                        intFrom = answer - collectionWindow.Heigth + 1;
                    }

                    for (int i = 0; i < Math.Min(collectionWindow.Heigth, choise.OptionsCount); ++i)
                    {
                        needRedraw.Add(intFrom + i);
                    }
                }
                if (needRedraw.Count > 0)
                {
                    choise.HighlightSelected(answer);
                    if (!choise.PreviewSelected(answer, descriptionWindow))
                    {
                        descriptionWindow.ClearLogWindow();
                        descriptionWindow.AddLog(choise.DescriptionForOption(answer));
                    }
                }
                redraw(needRedraw, choise.ChoiseOptions, answer, intFrom, collectionWindow, true);
                //
                if (pressed == use)
                {
                    onUseItem();
                }
            } while (pressed != exit);
        }