示例#1
0
        private void StartDialogue(int n)
        {
            Console.Clear();
            DialogueComponent component = _dialogues[n].GetStartComponent();

            while (!component.IsEnding)
            {
                try
                {
                    Console.WriteLine($"\n{component.Sentence}\n");
                    foreach (var item in component.Answers.Keys)
                    {
                        Console.WriteLine($"{item}\n");
                    }

                    Console.Write("Введите ответ: ");
                    component = _dialogues[n].PutAnswer(Console.ReadLine());
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"{ex.Message}\n");
                }
            }

            Console.WriteLine($"\n{component.Sentence}\n");
            _dialogues[n].Reset();
        }
示例#2
0
        static void Main(string[] args)
        {
            string[] answers = { "Да", "Нет" };

            DialogueComponent firstEnding  = new DialogueComponent("Вы победили!");
            DialogueComponent secondEnding = new DialogueComponent("Вы проиграли");

            DialogueComponent firstBranching = new DialogueComponent
                                               (
                sentence: "А Ваша мама была орком?",
                answers: new Dictionary <string, DialogueComponent>()
                                               );

            firstBranching.Add(new KeyValuePair <string, DialogueComponent>(answers[0], firstEnding));
            firstBranching.Add(new KeyValuePair <string, DialogueComponent>(answers[1], secondEnding));

            DialogueComponent root = new DialogueComponent
                                     (
                sentence: "Вы орк?",
                answers: new Dictionary <string, DialogueComponent>()
                                     );

            root.Add(new KeyValuePair <string, DialogueComponent>(answers[0], firstBranching));
            root.Add(new KeyValuePair <string, DialogueComponent>(answers[1], secondEnding));

            Dialogue    dialogue = new Dialogue("Тест", root);
            DialogueGUI gUI      = new DialogueGUI(new Dialogue[] { dialogue });

            while (true)
            {
                gUI.Update();
            }
        }