Question

I am making a game where in one part of it the player have to take part in conversation. The game asks player a question and gives 3 options to answer. When player answers, a new question pops up, according to player's previous answer. It means, that there are 3 possible potential questions now. Each of these questions brings 3 new answers, so there 9 potential answers now. And each answer leads to a question again, so there are 9 questions and 27 potential answers now and so on and so on...

I don't ask for solution, but an idea of how to set it up will be very appreciated. I just don't know how to organize it properly. How usually developers do it in their games?

Thanks!

EDIT:

Thanks to Duncan C for the idea. What I have done to solve the problem is just a plist with dictionary which contains a lot of small dictionaries inside. Each small dictionary - a question with possible answers and unique ID. I made an example of my model:

<key>q1</key>
<dict>

<key>question</key>
<string>Do you want to go left, right or straight?</string>

<key>a1</key>
<string>Left.</string>

<key>a2</key>
<string>Right.</string>

<key>a3</key>
<string>Straight.</string>

<key>a1key</key>
<string>q2.0</string>

<key>a2key</key>
<string>q2.1</string>

<key>a3key</key>
<string>q2.2</string>

</dict>


<key>q2.0</key>
<dict>

<key>question</key>
<string>You went left and found the key.</string>

<key>a1</key>
<string>Take the key.</string>

<key>a2</key>
<string>Go forward.</string>

<key>a3</key>
<string>Go back.</string>

<key>a1key</key>
<string>q2.01</string>

<key>a2key</key>
<string>q2.02</string>

<key>a3key</key>
<string>q2.03</string>

</dict>




<key>q2.1</key>
<dict>

<key>question</key>
<string>You went right and met a monster.</string>

<key>a1</key>
<string>Fight it.</string>

<key>a2</key>
<string>Run away.</string>

<key>a3</key>
<string>Hide from it.</string>

<key>a1key</key>
<string>q2.11</string>

<key>a2key</key>
<string>q2.12</string>

<key>a3key</key>
<string>q2.13</string>

</dict>


<key>q2.2</key>
<dict>

<key>question</key>
<string>You went straight and found a castle!</string>

<key>a1</key>
<string>Enter it.</string>

<key>a2</key>
<string>Continue going straight without visiting the castle.</string>

<key>a3</key>
<string>Go back.</string>

<key>a1key</key>
<string>q2.21</string>

<key>a2key</key>
<string>q2.22</string>

<key>a3key</key>
<string>q2.23</string>

</dict>

And so on and so on. So each time player chooses one of the option, a next linked dictionary comes up. I think it works really well and its possible to use same question to link between each other, so its not necessary to rewrite same things.

Was it helpful?

Solution

I would suggest using a plist rather than XML. Plists are easier to create and easier to read.

In either case though, putting your questions and answers into an external file makes your program flexible, without much effort. Then, if you decide later you want to have 50 questions, you just add records to your file.

I would suggest an array of dictionaries. You could create it like this:

#define K_QUESTION_KEY @"question"
#define K_ANSWERS_KEY @"answers"
#define K_CORRECT_ANSWER_INDEX @"answerIndex"


NSArray *questions = @[
  @{K_QUESTION_KEY: @"What is your quest",
    K_ANSWERS_KEY: @[@"I seek truth and enlightenment", 
                     @"I seek to escape from reality",
                     @"I seek the Holy Grail"];
   K_CORRECT_ANSWER_INDEX: @(2)
   },
  @{K_QUESTION_KEY: @"What is your favorite color",
    K_ANSWERS_KEY: @[@"Blue", 
                     @"Red",
                     @"Blue - no, green!"];
   K_CORRECT_ANSWER_INDEX: @(1)
   },
  @{K_QUESTION_KEY: @"What is the airspeed velocity of an unladen swallow",
    K_ANSWERS_KEY: @[@"42", 
                     @"I don't know",
                     @"A European or African swallow?"];
   K_CORRECT_ANSWER_INDEX: @(2)
   }

];

Then write it to disk using

[questions writeToFile: file_path atomically: YES];

Then you'd use similar syntax to read the file and traverse through it.

OTHER TIPS

i have not try it but here is my suggestion :

<qa>
<question_1 question="what is your name ?">
<option value="mikel"  />
<option value="john"  />
<option value="sosan"  />
</question_1>

<mikel value="what is the biggest thing in the word ?">
<option value="thing1" isTrue="false"/>
<option value="thing2" isTrue="false"/>
<option value="thing3" isTrue="true"/>
</mikel >

....
<!--and for other answers -->

<thing1 value="what is the biggest thing in the word ?">
<option value="thing11" isTrue="false"/>
<option value="thing22" isTrue="false"/>
<option value="thing33" isTrue="true"/>
</thing1>
... so on
</qa>

if you used the xml , then you can even use any other file for the same app .other questions .

hope this help you ,goodluck !

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top