1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include "DialougeTree.h"
#include <string>
#include <vector>
#include <iostream>
using namespace std;
DialougeNode::DialougeNode(string Text)
{
Text=text;
}
DialougeOption::DialougeOption(string Text, int returncode,DialougeNode *NextNode)
{
text = Text;
returnCode = returncode;
nextnode = NextNode;
}
DialougeTree::DialougeTree()
{
//ctor
}
void DialougeTree::init()
{
DialougeNode *node0 = new DialougeNode("Hello Brave warrior");
DialougeNode *node1 = new DialougeNode("I don't want to talk to you");
DialougeNode *node2 = new DialougeNode("I have a quest for you");
DialougeNode *node3 = new DialougeNode("You will get paid greddy asshole");
DialougeNode *node4 = new DialougeNode("Bring me 5 dandylions");
//node0
(*node0).dialougeoptions.push_back(DialougeOption("sup noob",0,node1));
(*node0).dialougeoptions.push_back(DialougeOption("Hello strange voice",0,node2));
dialougenodes.push_back(node0);
//node1
node1->dialougeoptions.push_back(DialougeOption("Aww",0,NULL));
dialougenodes.push_back(node1);
//node2
node2->dialougeoptions.push_back(DialougeOption("K. Bye",0,NULL));
node2->dialougeoptions.push_back(DialougeOption("What is it",0,node4));
node2->dialougeoptions.push_back(DialougeOption("Whats the pay?",0,node3));
dialougenodes.push_back(node2);
//node3
node3->dialougeoptions.push_back(DialougeOption("Ok what is it?",0,node4));
node3->dialougeoptions.push_back(DialougeOption("that sucks im out",0,NULL));
dialougenodes.push_back(node3);
//node4
node4->dialougeoptions.push_back(DialougeOption("Ok lets do it",1,NULL));
node4->dialougeoptions.push_back(DialougeOption("Nope",0,NULL));
dialougenodes.push_back(node4);
}
void DialougeTree::destorytree()
{
for (int i = 0; i < dialougenodes.size();i++)
{
delete dialougenodes[i];
}
dialougenodes.clear();
}
int DialougeTree::performdialouge()
{
if (dialougenodes.empty() == 0)
{
return -1;
}
DialougeNode *currentNode = dialougenodes[0];
while(true)
{
cout << currentNode->text << endl;
cout << endl;
for (int i = 0; i < currentNode->dialougeoptions.size(); i++)
cout << i + 1 << ": " << currentNode->dialougeoptions[i].text << endl;
}
int input;
cin >> input;
input --;
if (input < 0 || input > currentNode->dialougeoptions.size())
{
cout << "Invalid INput" << endl;
}
else{
if (currentNode ->dialougeoptions[input].nextnode == NULL)
{ return currentNode ->dialougeoptions[input].returnCode;
}
currentNode = currentNode ->dialougeoptions[input].nextnode;
}
}
|