mercredi 1 juillet 2015

How does one cycle back to previous options in a C# console application?

To say I'm fresh off the boat would be an understatement. I think this solution is extremely simple for an experienced programmer, but I'm completely new to C# and coding in general, so I apologize if I offend anybody with my utter lack of comprehension. That being said, answers geared towards somebody completely new to coding would be appreciated. Basically, please assume no prior knowledge.

I'm working on a short text adventure as a learning experience. I'm trying to make a dialogue system where the player can choose three dialogue options:

  1. Player says something -> NPC responds -> Player responds to NPC's response -> NPC responds again -> options cycle back to the three initial dialogue options

  2. Player says something -> NPC responds -> options cycle back to the three initial dialogue options

  3. Player ends dialogue -> options return to main dialogue options (which encases the following code)

This is what I've come up with so far:

            //Talk to Smith
            if (Input == "TALK TO SMITH")
            {
                {
                    Console.Clear();
                    Console.WriteLine("Initial discussion and character introduction");
                    Console.WriteLine("(Enter the corresponding number with what you want to say)");
                    Console.WriteLine("What would you like to discuss with Smith?");
                }
                do
                {
                    correct = 0;
                    Console.WriteLine("1. Dialogue Option #1");
                    Console.WriteLine("2. Dialogue Option #2");
                    Console.WriteLine("3. Dialogue Option #3");
                    Input = Console.ReadLine().ToUpper();

                    if (Input == "1")
                    {
                        Console.Clear();
                        dialogue = 1;
                        correct = 1;
                        Console.WriteLine("Dialogue Option #1");
                        Console.WriteLine("Response #1");
                        Console.WriteLine("1. Dialogue Option #1A");
                        Console.WriteLine("2. Dialogue Option #1B");
                        Input = Console.ReadLine().ToUpper();

                        do
                        {
                            if (Input == "1")
                            {
                                dialogue = 0;
                                Console.Clear();
                                Console.WriteLine("Dialogue Option #1A");
                                Console.WriteLine("Response #1A");
                                Console.ReadKey();
                                correct = 1;
                            }
                            if (Input == "2")
                            {
                                dialogue = 0;
                                Console.Clear();
                                Console.WriteLine("Dialogue Option #1B");
                                Console.WriteLine("Response #1B");
                                Console.ReadKey();
                                correct = 1;
                            }

            } while (correct == 1 && dialogue == 0);
                    }
                    if (Input == "2" && dialogue == 0)
                    {
                        Console.Clear();
                        dialogue = 1;
                        correct = 1;
                        Console.WriteLine("Response #2");
                        Input = Console.ReadLine().ToUpper();
                    }
                    if (Input == "3")
                    {
                        Console.Clear();
                        dialogue = 1;
                        correct = 0;
                        Console.WriteLine("Response #3");
                        Input = Console.ReadLine().ToUpper();
                    }
                } while (correct == 1 && location == 1);
             }

(This is only a part of the game's code, not the entire program itself)

The issue is that once I've chosen options #1A, #1B, or #2 the program does not cycle back to the dialogue with the NPC, but the main menu that I've set up. I've tried multiple methods, but none seem to work.

Aucun commentaire:

Enregistrer un commentaire