Quipex

Quiz

Apr 24th, 2012
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. -- Quiz game by legomaniack
  2. -- edit the questions to your liking
  3. -- uses: vocab study, quiz your friends,
  4. -- test you memory... ect.
  5.  
  6.  
  7. -- numbers is just 1 through # of questions
  8. numbers = {1, 2, 3}
  9.  
  10. -- qs is the questions.
  11. qs = {"2 + 2", "8 + 1", "7 - 4"}
  12.  
  13. -- as is the awnsers to the questions
  14. -- order matters!
  15. as = {"4", "9", "3"}
  16.  
  17.  
  18. term.clear()
  19. term.setCursorPos(1,1)
  20. -- randomize table funtion written by casper:
  21. function randomizetable(tbl) -- send a table to this function
  22. for x = 1, #tbl + 0 do -- replacing the 0 with another # will jumble the table up more times but isn't really needed
  23. rnd = math.random(1, #tbl)
  24. table.insert(tbl, #tbl + 1, tbl[rnd])
  25. table.remove(tbl, rnd)
  26. end
  27. return tbl
  28. end
  29. while true do
  30. textutils.slowPrint("Welcome to the Quiz game!")
  31. sleep(1.5)
  32. order = randomizetable(numbers)
  33. correct = 0
  34. for i = 1, #order, 1 do
  35. print("Question number "..i..":")
  36. print(qs[order[i]])
  37. awnser = io.read()
  38. if awnser == as[order[i]] then
  39. correct = correct + 1
  40. print()
  41. end
  42. end
  43. term.clear()
  44. term.setCursorPos(1,1)
  45. print("Total correct: "..correct.." out of "..#order)
  46. print("Play again?")
  47. print("[y]es or [n]o")
  48. again = io.read()
  49. if again == "y" then
  50. term.clear()
  51. term.setCursorPos(1,1)
  52. elseif again == "n" then
  53.  
  54. term.clear()
  55. term.setCursorPos(1,1)
  56. break
  57. else
  58. print("invalid input. defalting to no.")
  59. sleep(3)
  60. term.clear()
  61. term.setCursorPos(1,1)
  62. break
  63. end
  64. end
Add Comment
Please, Sign In to add comment