✔ 最佳答案
1. 定義 global variables, 問題和答案可放進 text file load 出來, 如果嫌麻煩可直接放係 variable 內:
dim n as integer ' number of questions
dim questions(1 to 10) as string
dim answers(1 to 10, 1 to 4) as string
dim correctAns (1 to 10) as integer
dim seq(1 to 10) as integer
dim questionIndex
dim questionNumber
dim numberOfCorrect
n = 10
questions(1) = "blah blah blah...?"
answers(1,1) = "answer a"
answers(1,2) = "answer b"
answers(1,3) = "answer c"
answers(1,4) = "answer d"
correctAns(1) = 3
questions(2) = "dah dah dah...?"
answers(2,1) = "answer 1"
answers(2,2) = "answer 2"
answers(2,3) = "answer 3"
answers(2,4) = "answer 4"
correctAns(2) = 2
...................... 如此類推
2. 將問題編號放進一個 array 內, 如 1 到 10:
for i = 1 to n
seq[i] = i
next i
3. 將 array 內之問題編號隨機排放:
for i = n to 1 step -1
idx = Int(RND() * (i + 1))
tmp = seq(i)
seq(i) = seq(idx)
seq(idx) = tmp
next i
4. 遊戲開始:
questionIndex = 1
numberOfCorrect = 0
5. 每次出問題時
questionNumber = seq(questionIndex)
questionIndex = questionIndex + 1
6. 顯示第 questionNumber 條問題, 供玩家作答, 如:
labelQuestion.caption = questions(questionNumber)
labelAnswer1.caption = answers(questionNumber, 1)
labelAnswer2.caption = answers(questionNumber, 2)
labelAnswer3.caption = answers(questionNumber, 3)
labelAnswer4.caption = answers(questionNumber, 4)
7. Check 答案, 如:
if playerChoice = correctAns(questionNumber) then numberOfCorrect = numberOfCorrect + 1
8. 當 questionIndex > n 時, 所有問題問完, 顯示答對左幾題 (numberOfCorrect).