TGC Codebase Backup



Simple Quiz Game by Mobiius

23rd Mar 2013 11:56
Summary

This is a very simple quiz game framework. Use this to learn about types, arrays, while loops and music file usage.



Description

This is a very simple quiz game framework. You load two mp3s, one plays when you get the answer right, the other when you get it wrong. You store the questions, multiple choice answers, and the correct answer in a type array. Enter the correct answer number and press enter, iof you're right you get a point.

This is designed to be very simplistic so that you can learn for yourself the principles required to improve it.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    Load Music 1, "Correct.mp3"
Load Music 2, "InCorrect.mp3"
Type tQuestion
   Question$
   Answer1$
   Answer2$
   Answer3$
   Answer5$
   CorrectAnswer
EndType
Dim Questions( 10 ) As tQuestions

Questions( 1 ).Question$ = "What is 1 + 1?"
Questions( 1 ).Answer1$ = "1"
Questions( 1 ).Answer2$ = "2"
Questions( 1 ).Answer3$ = "3"
Questions( 1 ).Answer4$ = "4"
Questions( 1 ).CorrectAnswer = 2

Questions( 2 ).Question$ = "What is 10 * 10?"
Questions( 2 ).Answer1$ = "1"
Questions( 2 ).Answer2$ = "10"
Questions( 2 ).Answer3$ = "100"
Questions( 2 ).Answer4$ = "1000"
Questions( 2 ).CorrectAnswer = 3


CurrentQuestion = 1
Correct = 0
InCorrect = 0

While Questions( CurrentQuestion ).Question$ <> ""
   Print "Correct: " + Str$( Correct ) + " : Incorrect: " + Str$( Incorrect )
   Print Questions( CurrentQuestion ).Question$
   Print "1) " + Questions( CurrentQuestion ).Answer1$
   Print "2) " + Questions( CurrentQuestion ).Answer2$
   Print "3) " + Questions( CurrentQuestion ).Answer3$
   Print "4) " + Questions( CurrentQuestion ).Answer4$
   Sync
   Input Answer$
   If Int( Answer$ ) = Questions( CurrentQuestion ).CorrectAnswer
      Correct = Correct + 1
      Play Music 1 : Repeat : Sync : Until Music Playing( 1 ) = 0
   Else
      InCorrect = InCorrect + 1
      Play Music 2 : Repeat : Sync : Until Music Playing( 2 ) = 0
   EndIf
   CurrentQuestion = CurrentQuestion + 1
EndWhile