Advertisement
metro80

QuickType

Nov 1st, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.38 KB | None | 0 0
  1. --   
  2. --  QuickType - A small mini-game.
  3. --     Made by UseTheForce Productions
  4. --     
  5. --     Credits:
  6. --     Luke M.
  7. --
  8.  
  9. if not fs.exists("CCQT/UTFPro") then
  10.     fs.makeDir("CCQT")
  11.     local UTFPro = fs.open("CCQT/UTFPro", "w")
  12.     UTFPro.writeLine("bbbbbbbbbbbbb9")
  13.     UTFPro.writeLine("b7bb88888777b9")
  14.     UTFPro.writeLine("b7bb7b8b7bbbb9")
  15.     UTFPro.writeLine("b7bb7b8b77bbb9")
  16.     UTFPro.writeLine("b7bb7b8b7bbbb9")
  17.     UTFPro.writeLine("b7777b8b7bbbb9")
  18.     UTFPro.writeLine("bbbbbbbbbbbbb9")
  19.     UTFPro.writeLine("99999999999999")
  20.     UTFPro.close()
  21. end
  22.  
  23. img = paintutils.loadImage("CCQT/UTFPro")
  24. local score = 0
  25. local dgtime = 5
  26.  
  27. function clear()
  28.     term.clear()
  29.     term.setCursorPos(1,1)
  30. end
  31.  
  32. clear()
  33.  
  34. function saveScore(value)
  35.     file = fs.open("CCQT/highscore.txt", "w")
  36.     file.writeLine(value)
  37.     file.close()
  38. end
  39.  
  40. function getScore()
  41.     if not fs.exists("CCQT/highscore.txt") then
  42.         file = fs.open("CCQT/highscore.txt", "w")
  43.         file.writeLine("0")
  44.         file.close()
  45.         getScore()
  46.     else
  47.         file = fs.open("CCQT/highscore.txt", "r")
  48.         highscore = file.readAll()
  49.         file.close()
  50.         return tonumber(highscore)
  51.     end
  52. end
  53.  
  54. function gsleep()
  55.     sleep(tonumber(gtime))
  56.     return "HI"
  57. end
  58.  
  59. function easyQuestion()
  60.     local letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
  61.     local question = {letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)]}
  62.     return question[1]..question[2]..question[3]..question[4]..question[5]..question[6]
  63. end
  64.  
  65. function hardQuestion()
  66.     local letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
  67.     local question = {letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)]}
  68.     return question[1]..question[2]..question[3]..question[4]..question[5]..question[6]
  69. end
  70.  
  71. function insaneQuestion()
  72.     local letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ":", "{", "}", "[", "]", "!", "@", "#", "$", "%", "%", "^", "&", "*", "(", ")", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "/", "\\"}
  73.     local question = {letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)]}
  74.     return question[1]..question[2]..question[3]..question[4]..question[5]..question[6]
  75. end
  76.  
  77. function easy()
  78.     clear()
  79.     eword = easyQuestion()
  80.     print("Score: "..score)
  81.     print("")
  82.     print(eword)
  83.     io.write("> ")
  84.     einput = io.read()
  85.     if string.lower(einput) == string.lower(eword) then
  86.         print("Correct!")
  87.         isCorrect = true
  88.     elseif string.lower(einput) ~= string.lower(eword) then
  89.         print("Incorrect! You have lost.")
  90.         isCorrect = false
  91.         hs = getScore()
  92.         if tonumber(score) > tonumber(hs) then
  93.             print("New High Score!!!")
  94.             saveScore(score)
  95.         end
  96.             sleep(1)
  97.             return false
  98.     end
  99. end
  100.  
  101. function hard()
  102.     clear()
  103.     hword = hardQuestion()
  104.     print("Score: "..score)
  105.     print("")
  106.     print(hword)
  107.     io.write("> ")
  108.     hinput = io.read()
  109.     if hinput == hword then
  110.         print("Correct!")
  111.         isCorrect = true
  112.     elseif einput ~= eword then
  113.         print("Incorrect! You have lost.")
  114.         isCorrect = false
  115.         hs = getScore()
  116.         if tonumber(score) > tonumber(hs) then
  117.             print("New High Score!!!")
  118.             saveScore(score)
  119.         end
  120.             sleep(1)
  121.             return false
  122.     end
  123. end
  124.  
  125. function insane()
  126.     clear()
  127.     iword = insaneQuestion()
  128.     print("Score: "..score)
  129.     print("")
  130.     print(iword)
  131.     io.write("> ")
  132.     iinput = io.read()
  133.     if iinput == iword then
  134.         print("Correct!")
  135.         isCorrect = true
  136.     elseif einput ~= eword then
  137.         print("Incorrect! You have lost.")
  138.         isCorrect = false
  139.         hs = getScore()
  140.         if tonumber(score) > tonumber(hs) then
  141.             print("New High Score!!!")
  142.             saveScore(score)
  143.         end
  144.             sleep(1)
  145.             return false
  146.     end
  147. end
  148.  
  149. function moreInfo()
  150.     clear()
  151.     print("             <[[[QuickType]]]>")
  152.     print("                     Info")
  153.     print("")
  154.     print("All you have to do is copy what comes up on the screen as fast as you can. The time you typed in the beginning was how long you have to type the word in the time between when it appears and when you have to type it.\n")
  155.     print("Easy: Not case-sensitive. Only Letters. Just copy!")
  156.     print("")
  157.     print("Hard: Case-sensitive. Only letters.")
  158.     print("")
  159.     print("Insane: Case-sensitive. Letters, numbers, symbols.")
  160.     print("")
  161.     print("Press any key to continue...")
  162.     while true do
  163.         event = os.pullEvent()
  164.         if event == "key" then
  165.             parallel.waitForAll(unosleep, hi)
  166.             start()
  167.         end
  168.     end
  169. end
  170.  
  171. function unosleep()
  172.     sleep(0.5)
  173. end
  174.    
  175. function hi()
  176.     print("")
  177.     print("                       ...")
  178. end
  179.  
  180. function start()
  181.     score = 0
  182.     gtime = htime
  183.     hs = getScore()
  184.     repeat 
  185.         clear()
  186.         print("             <[[[QuickType]]]>     High Score: "..hs)
  187.         print("           Choose your Gamemode:")
  188.         print("")
  189.         print("                Easy (e)")
  190.         print("                Hard (h)")
  191.         print("               Insane (i)")
  192.         print("              More Info (m)")
  193.         print("                Exit (ex)")
  194.         print("")
  195.         io.write("                > ")
  196.         gamemode = string.lower(io.read())
  197.        
  198.         if gamemode == "e" then
  199.             gtype = "easy"
  200.        
  201.         elseif gamemode == "h" then
  202.             gtype = "hard"
  203.            
  204.         elseif gamemode == "i" then
  205.             gtype = "insane"
  206.            
  207.         elseif gamemode == "ex" then
  208.             print("Goodbye!")
  209.             sleep(2)
  210.             clear()
  211.             error()
  212.            
  213.         elseif gamemode == "m" then
  214.             moreInfo()
  215.            
  216.         else
  217.             print("Invalid Answer")
  218.             sleep(1)
  219.         end
  220.     until gtype ~= nil
  221.     clear()
  222.     print("Are you ready? (y/n)")
  223.     io.write("> ")
  224.     local input = string.lower(io.read())
  225.     if input == "y" then
  226.         clear()
  227.         if gtype == "easy" then
  228.             geasy()
  229.             start()
  230.         elseif gtype == "hard" then
  231.             ghard()
  232.             start()
  233.         elseif gtype == "insane" then
  234.             ginsane()
  235.             start()
  236.         else
  237.             print("An Unknown Error Occurred...")
  238.             sleep(2)
  239.             error()
  240.         end
  241.     else
  242.         start()
  243.     end
  244. end
  245.  
  246. function geasy()
  247.     x = parallel.waitForAny(gsleep, easy)
  248.     if x == 2 then
  249.         if isCorrect == false then
  250.             start()
  251.         else
  252.             score = score + 1
  253.             gtime = gtime - 0.2
  254.             sleep(1)
  255.             geasy()
  256.         end
  257.     end
  258.     if x == 1 then
  259.         print("\nTime is up! You lose!")
  260.         if score > hs then
  261.             print("New High Score!")
  262.             saveScore(score)
  263.         end
  264.         sleep(2)
  265.         return "HI"
  266.     end
  267. end
  268.  
  269. function ghard()
  270.     x = parallel.waitForAny(hard, gsleep)
  271.     if x == 1 then
  272.         if isCorrect == false then
  273.             start()
  274.         else
  275.             score = score + 1
  276.             gtime = gtime - 0.2
  277.             sleep(1)
  278.             geasy()
  279.         end
  280.     end
  281.     if x == 2 then
  282.         print("\nTime is up! You lose!")
  283.         if score > hs then
  284.             print("New High Score!")
  285.             saveScore(score)
  286.         end
  287.         sleep(2)
  288.         return "HI"
  289.     end
  290. end
  291.  
  292. function ginsane()
  293.     x = parallel.waitForAny(insane, gsleep)
  294.     if x == 1 then
  295.         if isCorrect == false then
  296.             start()
  297.         else
  298.             score = score + 1
  299.             gtime = gtime - 0.2
  300.             sleep(1)
  301.             geasy()
  302.         end end
  303.     if x == 2 then
  304.         print("\nTime is up! You lose!")
  305.         if score > hs then
  306.             print("New High Score!")
  307.             saveScore(score)
  308.         end
  309.         sleep(2)
  310.         return "HI"
  311.     end
  312. end
  313.  
  314. print("Getting highscore...")
  315. hs = getScore()
  316. function timew()
  317.     io.write("Enter time > ")
  318.     htime = tonumber(io.read())
  319.     if htime == nil then
  320.         print("Must be a number")
  321.         timew()
  322.     elseif htime < 0 then
  323.         print("Must be greater than 0")
  324.         timew()
  325.     elseif htime > 10 then
  326.         print("Must be less than or equal to 10")
  327.         timew()
  328.     else
  329.         gtime = htime
  330.     end
  331. end
  332. timew()    
  333. print("Initializing...")
  334. sleep(0.82946)
  335. clear()
  336. sleep(1)
  337. if term.isColor() then
  338.     paintutils.drawImage(img, 19, 4)
  339.     term.setCursorPos(11, 13)
  340.     term.setBackgroundColor(colors.black)
  341.     write("UseTheForce Productions Presents")
  342. else
  343.     term.setCursorPos(11, 10)
  344.     write("UseTheForce Productions Presents")
  345. end
  346. sleep(3)
  347. term.setBackgroundColor(colors.black)
  348. clear()
  349. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement