2
\$\begingroup\$

I'm thinking of making a single method/class/something that will handle my dialogue in the game. AKA, something like:

Main text:

Choice 1
Choice 2

So I want a method that will able to put different strings into the main text section and also different strings into the Choice options. I've been thinking about solutions, and so far I've come up with just a simple method that accepts parameters for main text, choice1 and choice2 -- problem being that the strings called will be quite long and I think it looks a little clumsy? Also I won't want to have 2 choices every time, OR I want to have multiple "pages" of dialogue show up before you need to take an action. This would require me to overload methods which may turn out quite ugly?

So yeah I don't have a lot of experience with this and method overloading is all I've thought about for now. I've given thought to interfaces/abstract classes but I'm not entirely sure if they're even relevant for what I want to do. Any thoughts?

\$\endgroup\$
2
\$\begingroup\$

I suggest to use a tree (graph) class aproach. Place Main text into nodes and choise text into arcs (arrows)

Multi page Text can placed into sequential nodes with only one choice arc ("Next page")

enter image description here

Rough c# implementation:

public class DialogueArc {
    public String Text { get; set; }
    public DialogueTreeNode outgoingNode;
    public DialogueArc(String text, DialogueTreeNode N)
    {
        Text = text;
        outgoingNode = N;
    }

}
public class DialogueTreeNode
{
    public String Text { get; set; }
    public List<DialogueArc> Choiches = new List<DialogueArc>();
    public DialogueTreeNode(String text)
    {
        Text = text;
    }
    public void AddArc(string T, DialogueTreeNode N) {
        Choiches.Add(new DialogueArc(T, N));
    }
}

Dialogue creation example:

    //define nodes
    DialogueTreeNode Root = new DialogueTreeNode("First Page dialogue....");
    DialogueTreeNode RootPg2 = new DialogueTreeNode("Second page dialogue....");
    DialogueTreeNode RootPg3 = new DialogueTreeNode("third page page...");
    DialogueTreeNode afterCh1 = new DialogueTreeNode("After choice 1..");
    DialogueTreeNode afterCh2 = new DialogueTreeNode("After choice 2..");
    DialogueTreeNode afterCh1Ch1 = new DialogueTreeNode("After choice 1_1..");            
    DialogueTreeNode afterCh2Ch1 = new DialogueTreeNode("After choice 2_1..");
    //define choices
    Root.AddArc("Next page", RootPg2);
    RootPg2.AddArc("Next page", RootPg3);
    RootPg3.AddArc("Choice 1 txt", afterCh1);
    RootPg3.AddArc("Choice 2 txt", afterCh2);
    afterCh1.AddArc("Chise 1_1 txt", afterCh1Ch1);
    afterCh2.AddArc("Chise 2_1 txt", afterCh2Ch1);
|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ thanks for the comment -- but I have no clue what tree classes/nodes are! can you link me to a good explanation of them? :) \$\endgroup\$ – Jeff Burghess May 27 '15 at 8:18
  • \$\begingroup\$ stackoverflow.com/questions/66893/… I edited the answer with a rough tree implementation \$\endgroup\$ – dnk drone.vs.drones May 27 '15 at 8:57
  • \$\begingroup\$ thanks a bunch! I'll read up on the example that you've given here. \$\endgroup\$ – Jeff Burghess May 27 '15 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.