In my continuing experiments with TNT Basic, I've decided to try programming a multiple-choice trivia quiz. So far I have two integer variables, qnum and score, and three string variables: answer, choice, name and question.
For each question, the program would read five lines: the question itself, the correct answer and three wrong answers. Here's the preliminary program flow:
1. Set score to 0 and qnum to 1. Variable qnum is a pointer to the next unused question in the file.
2. Ask the player to enter his/her name.
3. Open the data file.
4. Read the question text and four answer choices from the data file. Let answer be the correct answer and answer through answer be the wrong answers.
5. Shuffle the answer choices so that the correct answer does not always appear first. (This, to me, is one of the hardest parts to program. For example, choice is the first answer choice displayed, but the value of answer, the correct answer, may be assigned to choice, the third choice displayed. Put another way, the answer values are always read in order 0,1,2,3 but may be displayed in order 1,3,0,2.)
6. Display the question. Below it are four buttons, each labeled with a different answer choice.
7. If the player chose the correct answer, ring a bell and add 1 to the score. Go to step 9.
print "Correct answer!"
8. Sound a buzzer and indicate the correct answer. Do not deduct points for a wrong answer.
print "Sorry, the correct answer was:"
print answer ' Remember, the correct answer was read first
9. Add 1 to qnum.
10. Repeat from step 4 until all questions in the file have been used.
11. Display the player's final score.
Have I overlooked anything? Is there an efficient way to randomize the order in which the four answer choices are displayed for each question? I want to be able to add categories later, for use in TV-style games.
Quebec ( Canada )
Is there an efficient way to randomize the order in which the four answer choices are displayed for each question?
Hmmm i have an idea, though there's probably a better way. Anyway, if it works, who cares? ;)
I'd have an array containing 0,1,2,3 - and then randomly swap them.
code mockup: (not tested)
int id1, id2, swapvalue
for n=0 to 10 ' repeat ten times
swapvalue = order[id1]
order[id1] = order[id2]
order[id2] = swapvalue
and after display them in the order contained by 'order'
I've begun trying a new approach to my trivia quiz project. Instead of trying to randomize the order of answer choices for each question, I'm assigning the integers 0, 1, 2 and 3 to the answer choices. Here's my new question format:
Text of question
Integer for correct answer (0..3)
The player is expected to press a key (1, 2, 3 or 4) for the desired answer; key 1 is for choice 0, key 2 for choice 1 and so on. I've uploaded the current version of the game to my MidcoNet site.
But now I have a new problem: How do I tell TNT Basic where my question file is, and that it's a plain text, read-only file? The following code generates errors:
quizfile=open file (questions.txt,false,TEXT,Text)
If I can get this working, I may add categories. Any help would be appreciated.