Okay, so I am making a quiz game, and I wanted to add in an area where people (taking the quiz) could work out the math problems. I have this code
sync on : sync rate 60
cls rgb(192,192,192)
do
prevx = mx
prevy = my
mx = mousex()
my = mousey()
if mouseclick()
line prevx,prevy,mx,my
endif
sync
if spacekey()=1 then cls rgb(192,192,192)
loop
But I have no clue at how I would implement it into this code
`Quiz Example
`======================
` What is a player? Define it in a UDT
Type PlayerType
Name$
Score
Endtype
` What specifications should all quiz entries have in common?
` Define that in a default entry
Global DefaultPlayer as PlayerType
` In this quiz, all players names start off as 'Player'
DefaultPlayer.Name$ = "Player"
` Create a list of X amount of players
` Usually there is only one player, but usual doesn't always stay usual
Dim Players( 1 ) as PlayerType
` Who am I? I am player 1
Global Me = 1
` What is my name?
Input "What is your name? Please enter: ", Players( Me ).Name$
` What is a quiz? Define it as a UDT
Type QuizEntryType
Question$
Question2$
CorrectAnswer
Answer1$
Answer2$
Answer3$
Answer4$
Score
Endtype
` Create a list of X amount of quiz entries;
Dim QuizEntry( 0 ) as QuizEntryType
` What specifications should all quiz entries have in common?
` Define that in a default entry
Global DefaultQuizEntry as QuizEntryType
` In this quiz, all entries have a score of 1
DefaultQuizEntry.Score = 1
` Get questions and feedback number of quiz entries
Global NumberOfQuestions = 0
NumberOfQuestions = GetQuestions()
` What is a result? Define it as a UDT
Type ResultType
Text$
Message$
Sound
BackgroundColour
ContinueQuiz
Endtype
` There are two results; correct and incorrect; but we will start from index zero as a boolean switch
` Zero is false, one is true
Dim Result( 1 ) as ResultType
` Set their information
Result( 0 ).Text$ = "WRONG ANSWER"
Result( 0 ).Message$ = "Press Any Key To Continue"
Result( 0 ).BackgroundColour = rgb (255,0,0)
Result( 0 ).Sound = 3
Result( 0 ).ContinueQuiz = 1 ` In this quiz, the game will not answer any more questions when the answer is wrong
Result( 1 ).Text$ = "Correct" ` We will display each message line by line
Result( 1 ).Message$ = "Press any key to continue"
Result( 1 ).BackgroundColour = rgb (0,255,0)
Result( 1 ).Sound = 3
Result( 1 ).ContinueQuiz = 1
Do
Randomize Timer() ` Shuffle random questions in random mode
Question = 1
` Call GetQuestions() again if we are using random mode or removing questions from the list
Repeat
Continue = 0 ` Do not continue if the question is wrong
Cls rgb (0,0,255)
Print "Question "; Question
Print
Print QuizEntry( Question ).Question$
Print QuizEntry( Question ).Question2$
Print "-----------------------------"
Print "A: "; QuizEntry( Question ).Answer1$
Print "B: "; QuizEntry( Question ).Answer2$
Print "C: "; QuizEntry( Question ).Answer3$
Print "D: "; QuizEntry( Question ).Answer4$
Print
Wait 1000 ` Wait a little before listening for the next keystroke (Matrix1 users use Nice Wait / Nice Sleep )
` Wait for an answer in a CPU friendly fashion
Repeat
k$ = MyCPUFriendlySuspendForKeyFunction$()
` Select the result via lowercase (small letters)
` Set to continue if the answer is correct
ValidKeystroke = 0 ` Assume the keystroke is invalid if not a,b,c or d
Select Lower$(k$) ` Matrix1 users use Fast Lower$(k$)
Case "a"
If QuizEntry( Question ).CorrectAnswer = 1
Continue = 1
Endif
ValidKeystroke = 1
Endcase
Case "b"
If QuizEntry( Question ).CorrectAnswer = 2
Continue = 1
Endif
ValidKeystroke = 1
Endcase
Case "c"
If QuizEntry( Question ).CorrectAnswer = 3
Continue = 1
Endif
ValidKeystroke = 1
Endcase
Case "d"
If QuizEntry( Question ).CorrectAnswer = 4
Continue = 1
Endif
ValidKeystroke = 1
Endcase
Endselect
Until ValidKeystroke
` If print the result
Cls Result( Continue ).BackgroundColour
Print Result( Continue ).Text$
Print Result( Continue ).Message$
` 1 multiplied by something equals the same thing
` 0 multplied by something equals 0
` Therefore the correct answer multiplied by score awarded will award the score
Inc Players(Me).Score, Continue * QuizEntry( Question ).Score
MyCPUFriendlySuspendForKeyFunction()
` Is this a test or an elimination? Continue asking questions if it is a test
Continue = Result( Continue ).ContinueQuiz
` Assume next question
Inc Question
` Or select a random question by using the following lines instead of the previous
` Remove From Queue QuizEntry()
` Question = Rnd( Array Count( QuizEntry() ) )
Until Continue = 0 Or Question > Array Count( QuizEntry() ) Or Array Count( QuizEntry() ) = 0
Question = 1
If EscapeKey()
End ` Will occur anyway if you do not use: Disable EscapeKey
Endif
CLS
Print Players(Me).Name$; " your final score was "; Players(Me).Score
Print "Press any key to continue, or escape to exit"
` Next player
Inc Me
If Me > Array Count( Players() )
For p = 1 to Array Count( Players() )
Players(p).Score = 0
Next p
Me = 1
Endif
MyCPUFriendlySuspendForKeyFunction()
Loop
End
//===================================================
Function MyCPUFriendlySuspendForKeyFunction$()
Clear Entry Buffer ` Wipe off the last key pressed
Repeat
Sync Sleep 10
Sleep 1
` Matrix1 users; use the more effecient Nice Sleep 1 or Nice Wait 1 - no difference
k$ = Inkey$()
Until k$ <> ""
Endfunction k$
//===================================================
Function MyCPUFriendlySuspendForKeyFunction()
Wait 200
Repeat
Sync Sleep 10
Sleep 1
` Matrix1 users; use the more effecient Nice Sleep 1 or Nice Wait 1 - no difference
Until Scancode()
Endfunction
//===================================================
Function GetQuestions()
` Now we could load an XML file from MS Excel or connect to a MS Access or
` load the questions from the internet, or from an INI file; I've left that
` up to you; in such a case you would do something along the lines of
` this function: LoadQuestions() See next function which demonstrates
` loading a simple text file
Array Insert At Bottom QuizEntry()
Index = Array Count( QuizEntry() )
QuizEntry( Index ) = DefaultQuizEntry
QuizEntry( Index ).Question$ = "How long is a foot?"
QuizEntry( Index ).CorrectAnswer = 2
QuizEntry( Index ).Answer1$ = "12 centimeters"
QuizEntry( Index ).Answer2$ = "12 inches"
QuizEntry( Index ).Answer3$ = "8 inches"
QuizEntry( Index ).Answer4$ = "20 meters"
` QuizEntry( Index ).Score = 1
Inc Index ` Advance to the next question
Array Insert At Bottom QuizEntry()
QuizEntry( Index ) = DefaultQuizEntry
QuizEntry( Index ).Question$ = "Camille buys a pair of shoes for $15.95. She gives the clerk $20.00. How much"
QuizEntry( Index ).Question2$ = "change will Camille Recieve?"
QuizEntry( Index ).CorrectAnswer = 3
QuizEntry( Index ).Answer1$ = "$4"
QuizEntry( Index ).Answer2$ = "$4.15"
QuizEntry( Index ).Answer3$ = "$4.05"
QuizEntry( Index ).Answer4$ = "$5.05"
` QuizEntry( Index ).Score = 1
Inc Index ` Advance to the next question
Array Insert At Bottom QuizEntry()
QuizEntry( Index ) = DefaultQuizEntry
QuizEntry( Index ).Question$ = "Choose the correct sum: 543 + 96"
QuizEntry( Index ).CorrectAnswer = 3
QuizEntry( Index ).Answer1$ = "553"
QuizEntry( Index ).Answer2$ = "533"
QuizEntry( Index ).Answer3$ = "639"
QuizEntry( Index ).Answer4$ = "539"
` QuizEntry( Index ).Score = 2
Inc Index ` Advance to the next question
Array Insert At Bottom QuizEntry()
QuizEntry( Index ) = DefaultQuizEntry
QuizEntry( Index ).Question$ = "Divide:"
QuizEntry( Index ).Question2$ = " 25 / 3 "
QuizEntry( Index ).CorrectAnswer = 1
QuizEntry( Index ).Answer1$ = "8 Remainder 1"
QuizEntry( Index ).Answer2$ = "7 Remainder 3"
QuizEntry( Index ).Answer3$ = "7 Remainder 2"
QuizEntry( Index ).Answer4$ = "8 Remainder 2"
` QuizEntry( Index ).Score = 3
Inc Index ` Advance to the next question
Array Insert At Bottom QuizEntry()
QuizEntry( Index ) = DefaultQuizEntry
QuizEntry( Index ).Question$ = "Round the number to the greatest place and then add."
QuizEntry( Index ).Question2$ = "470 + 176"
QuizEntry( Index ).CorrectAnswer = 4
QuizEntry( Index ).Answer1$ = "300"
QuizEntry( Index ).Answer2$ = "500"
QuizEntry( Index ).Answer3$ = "600"
QuizEntry( Index ).Answer4$ = "700"
` QuizEntry( Index ).Score = 3
Inc Index ` Advance to the next question
Array Insert At Bottom QuizEntry()
QuizEntry( Index ) = DefaultQuizEntry
QuizEntry( Index ).Question$ = "How many thousands are there in the number 200,000?"
QuizEntry( Index ).CorrectAnswer = 1
QuizEntry( Index ).Answer1$ = "20"
QuizEntry( Index ).Answer2$ = "2"
QuizEntry( Index ).Answer3$ = "200"
QuizEntry( Index ).Answer4$ = "10"
` QuizEntry( Index ).Score = 3
Inc Index ` Advance to the next question
Array Insert At Bottom QuizEntry()
QuizEntry( Index ) = DefaultQuizEntry
QuizEntry( Index ).Question$ = "How many thousands are there in the number 200,000?"
QuizEntry( Index ).CorrectAnswer = 1
QuizEntry( Index ).Answer1$ = "20"
QuizEntry( Index ).Answer2$ = "2"
QuizEntry( Index ).Answer3$ = "200"
QuizEntry( Index ).Answer4$ = "10"
` QuizEntry( Index ).Score = 3
Endfunction Index
//===================================================
Function LoadQuestions()
Remstart
` Decrypt("QuestionFile.Txt") ` Use encrpytion if necessary, check TGC for encryption examples
Open To Read 1, "QuestionFile.Txt"
Index = 1
While File End(1) = 0
Array Insert At Bottom
Read String 1, data$ : QuizEntry( Index ).Question$ = data$
Read String 1, data$ : QuizEntry( Index ).CorrectAnswer = Val( data$ ) ` Matrix1 users use IntVal()
Read String 1, data$ : QuizEntry( Index ).Answer1$ = data$
` And so on....
Inc Index
EndWhile
Close File 1
NumberOfQuestions = Index
` Encrypt("QuestionFile.Txt") ` Use encrpytion if necessary
RemEnd
Endfunction
I want it to only be available when the math problems are present, but not available when we are just "typing our name" or anything like that. Thanks for your help!