Thank you for visiting Blazing Games

Coding Trivia

The big issue that comes up when starting development work on this episode was how to present the trivia. I felt that a conversation format would make the trivia fit into the rest of the series the best so opted to stick a trivia game into the conversation system. This was not overly difficult to do as questions are simply topics while the answers are simply the branches from that topic that lead to an explanation of the question. This still requires a number of conversation nodes be created. To handle all this work, a simple function to perform the work was created so the data that makes up the question simply gets passed to the maker function and it creates all the conversation nodes.

private function buildQuestion(num:int, question:String, answer:String,
wrong1:String, wrong2:String, wrong3:String, reason:String)
{
var fs:String = "ISFLAGSET TRUE";
var questionLabel = "Question" + num;
var w1Label:String = "wrong" + num + "a";
var w2Label:String = "wrong" + num + "b";
var w3Label:String = "wrong" + num + "c";
var ansLabel:String = "answer" + num;
var dialogList:Array = new Array(w1Label, w2Label,w3Label,ansLabel);

scrambleArray(dialogList);
_questionOrder.push(questionLabel);

// build result handling topics
_conversation.addTopic( new ConversationTopic(
w1Label, wrong1, reason,
3,1, fs, null, new Array(NEXTWRONG)));
_conversation.addTopic( new ConversationTopic(
w2Label, wrong2, reason,
3,1, fs, null, new Array(NEXTWRONG)));
_conversation.addTopic( new ConversationTopic(
w3Label, wrong3, reason,
3,1, fs, null, new Array(NEXTWRONG)));
_conversation.addTopic( new ConversationTopic(
ansLabel, answer, "That is correct. " + reason,
3,1, fs, null, new Array(NEXTQUESTION)));
// now build the question
_conversation.addTopic( new ConversationTopic(
questionLabel, questionLabel, question,
3,1, fs, null, dialogList));
}

private function scrambleArray(lst:Array):void
{
var swap:int;
var temp:String;

for (var cntr:int = 0; cntr < lst.length; ++cntr) {
swap = Math.floor(Math.random() * lst.length);
temp = lst[cntr];
lst[cntr] = lst[swap];
lst[swap] = temp;
}
}

The game logic then gets handled by a conversation handler event manager. This looks at what topic was selected and bases it’s actions on that. If the topic is NEXTQUESTION then the question has been answered correctly and the explanation is showing in which case, we see if all 12 questions have been answered so we know if the game has been won or that another question needs to be shown. The WRONGANSWER topic sees how many mistakes you have made. If it is your first mistake you are taken to a warning screen otherwise you are taken to the death topic (SECONDMISTAKE). A couple of topics to handle winning and losing send the core game to the appropriate actions. Finally, if none of the above has happened, the topic is an explanation so it displays the explanation topic indicated.

function topicHandler(event:Event):void {
var top:ConversationTopic = _conversation.getLastTopic();
trace(top.topic + "topic was selected");

if (top.topic == NEXTQUESTION) {
++_currentQuestion;
if (_currentQuestion == 12)
_conversation.showTopic(WIN);
else
_conversation.showTopic(_questionOrder[_currentQuestion]);
} else if (top.topic == NEXTWRONG) {
++_wrongCount;
if (_wrongCount > 1)
_conversation.showTopic(SECONDMISTAKE);
else
_conversation.showTopic(FIRSTMISTAKE);
} else if (top.topic == OVER) {
_owner.death();
} else if (top.topic == TOBECONTINUED) {
_owner.toScore();
} else {
_conversation.showTopic(top.topic);
}
}

While it took a little bit of effort to turn my conversation system into a trivia game, the amount of work was minimal and the results are, at least in my opinion, quite good. If someone wanted to get fancier with the trivia game, instead of just a conversation, the questions could be pointers to multimedia content which would give you the ability to have much more visually or audio oriented questions. The answers could also be media related so the question that asks for a planet would have pictures of the answers. Programming-wise, this would not be much more work to implement. Content-wise it would be a huge amount of work. Perhaps the next trivia game I develop will actually have something called “a budget” and I will be able to do something like this.

Previous page
Chapter 40 Page 5

About - Privacy Policy - Contact - Links - FAQ
Copyright © 2011 Blazing Games Inc. All Rights Reserved