Advertisement
Redxone

Science Test for CC

Aug 13th, 2016
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.65 KB | None | 0 0
  1. --]] Vital testing aperatus made by LEW, Intelligence by Gluuon
  2. os.pullEvent = os.pullEventRaw
  3. local sbc = term.setBackgroundColor
  4. local stc = term.setTextColor
  5. local scp = term.setCursorPos
  6. local cls = term.clear
  7. local line = paintutils.drawLine
  8. local box = paintutils.drawBox
  9. local fbox = paintutils.drawFilledBox
  10. local w,h = term.getSize()
  11. local theme = {
  12.     bc = colors.black,
  13.     tc = colors.green,
  14.     barbc = colors.orange,
  15.     bartc = colors.white,
  16.     qbc = colors.green,
  17.     qtc = colors.white,
  18.     answerbc = colors.lightGray,
  19.     answertc = colors.gray,
  20. }
  21. qcor = 0
  22. local passers = {}
  23. local subjects = {
  24.     {s="Theoretical Physics",q={
  25.         {s="Fact",q="Since protons are positivly charged \n how do they all stay together?",a="strongforce"},
  26.         {s="Theory",q="If light is a EM Field, and always remains \n a constant speed we can assume \n from this that light  \n is a type of..",a="gravity"},
  27.         {s="Theory",q="Name a force that can escape a blackhole.", a="kinetic"},
  28.         {s="Fact",q="How about an easy one, its part of \n the lepton family and is unseeable.", a="electron"},
  29.         {s="Fact",q="What are the 3 color wave lengths \ngluons can have. \n(list them with their 1st inital) ", a="rgb"},
  30.         {s="Fact",q="What was the primary reason why \n einstein couldnt unite relativity \n and quantum physics \n in one word. ", a="gravity"},
  31.         {s="Fact",q="Is it energy effective to harvest \ncarbon from the air in a \nform of plastic?",a="no"},
  32.         {s="Fact",q="Describe why we will never see \nthe light from some galaxys \nin one word.", a="expansion"},
  33.         {s="Theory",q="Einsteins theory that states \n that light and gravity are \n 2 differant versions of the \n same thing is called. ", a="unified field theory"},
  34.         {s="Fact",q="If nothing can move faster than \n light then why will we never \n see the light from some \n galaxys?.", a="space expansion"},   
  35.     }},
  36.     {s="Chemistry",q={
  37.         {s="Fact",q="Name the 3 items of the fire pyramid. (order: left right down) ",a="oxygen heat fuel"},
  38.         {s="Fact",q="What partical family are quarks part of?",a="boson"},
  39.         {s="Fact",q="List the electron subshells atom (non theoretical). ",a="spdf"},
  40.         {s="Fact",q="List all the electron shells. ",a="KLMNOP"},
  41.         {s="Fact",q="Is Water a polar or non-polar molecule?.",a="polar"},
  42.         {s="Fact",q="What spin is a proton?.",a="1/2"},
  43.         {s="Fact",q="Can there be a maximum number of protons to a nucleus?.",a="yes"},
  44.         {s="Fact",q="Which elementary particle is analogous \n to the exchange of photons in \n the electromagnetic force between \n two charged particles, \n and is used to keep protons and neutrons \n ect, together?",a="gluon"},
  45.         {s="Fact",q="What atom am i talking about, it has 20 electrons. ",a="calcium"},
  46.         {s="Fact",q="Which atom is used all around the world \n mainly because of its valence electrons? ",a="carbon"},
  47.     }},
  48.     {s="Computercraft",q={
  49.         {s="Fact",q="What math function would i use to check \n the color table based on a  \n16bit number? ",a="math.log"},
  50.         {s="Fact",q="Should i calculate before drawing or draw before calculating?",a="draw before calculating"},
  51.         {s="Fact",q="Write the code needed to move \n the player on the map from its x \n and y to x+1, y-1 and check \n the collision before moving. \n(player id is 1 and block id \nis anything but 0) ",a="if(map[y-1][x+1] == 0)then map[y][x] = 0 map[y-1][x+1] = 1 end"},
  52.         {s="Fact",q="Whats more effective than calling player.draw(player)? ",a="player:draw()"},
  53.         {s="Fact",q="Is Computercrafts fs api the same as Lua's?",a="no"},
  54.         {s="Fact",q="Whats the best way to eliminate \n screen flickering in \n 1 word.",a="buffers"},
  55.         {s="Fact",q="Whats the most effective way to \n store information \n for a map?",a="tables"},
  56.         {s="Fact",q="Is there a way to condense a space? (byte(32))",a="yes"},
  57.         {s="Fact",q="Whats the lazy way to eliminate \n screen flickering? \n (Type the function but \n dont pass an argument)",a="term.current().setVisible"},
  58.         {s="Fact",q="Who invented ComputerCraft?",a="Dan200"},
  59.     }},
  60. }
  61. qtable = {}
  62.  
  63. local function reverse(tbl)
  64.     ntbl = {}
  65.     ntbl[1] = tbl[#tbl]
  66.     for i = 1, #tbl do
  67.         ntbl[i] = tbl[#tbl]
  68.     end
  69.     return ntbl
  70. end
  71.  
  72. local function lnwrite(txt)
  73.     local x,y = term.getCursorPos()
  74.     local ln = 0
  75.     for line in txt:gmatch("[^\n]+") do
  76.         scp(x,y+ln)
  77.         write(line)
  78.         ln = ln + 1
  79.     end
  80. end
  81. local function getlns(txt)
  82.     local ln = 0
  83.     for line in txt:gmatch("[^\n]+") do
  84.         ln = ln + 1
  85.     end
  86.  
  87.     return ln
  88. end
  89.  
  90. local function starfield(chance)
  91.     local scols = {colors.white,colors.lightGray,colors.gray}
  92.     --local ptc = term.getTextColor()
  93.     for y = 1, h do
  94.         for x = 1, w do
  95.             if(math.random(0,chance) == 1)then
  96.                 stc(scols[math.random(1,3)])
  97.                 scp(x,y)
  98.                 write("*")
  99.             end
  100.         end
  101.     end
  102.     stc(colors.white)
  103. end
  104.  
  105. local function msgbox(msg,isc)
  106.  
  107.     local ccs = {
  108.         colors.gray,
  109.         colors.lime,
  110.         colors.green,
  111.     }
  112.     local ics = {
  113.         colors.pink,
  114.         colors.orange,
  115.         colors.red,
  116.     }
  117.     --local ptc = term.getTextColor()
  118.     stc(colors.white)
  119.     local bw = w
  120.     local bh = 5
  121.     local ume = ics
  122.     if(isc)then ume = ccs end
  123.     for i = 1, #ume do
  124.         fbox(1, math.max(h/2) - bh/2,bw, math.floor(h/2) + bh/2,ume[i])
  125.         sleep(0.1)
  126.     end
  127.     scp( ((w/2)) - (#msg/2), math.max(h/2)-(getlns(msg)-1))
  128.     lnwrite(msg)
  129.     stc(colors.lightGray)
  130.     scp( ((w/2)) - 6, math.floor(h/2)+(getlns(msg)-1))
  131.     lnwrite("Press any key.")
  132.     os.pullEvent("key")
  133.     stc(colors.white)  
  134.     return isc
  135. end
  136.  
  137. local function clscr()
  138.     sbc(theme.bc)
  139.     stc(theme.tc)
  140.     cls()
  141.     starfield(20)
  142. end
  143.  
  144. local function transition(speed)
  145.     local c = {
  146.         colors.gray,
  147.         colors.lightGray,
  148.         colors.white,
  149.     }
  150.     for i = 1, 2 do
  151.         for i = 1, #c do
  152.             sbc(c[i])
  153.             cls()
  154.             sleep(speed)
  155.         end
  156.         reverse(c)
  157.     end
  158. end
  159.  
  160. local function spaceBox(inout)
  161.     local bh = 5
  162.     if(inout == 'in')then
  163.         sbc(theme.bc)
  164.         cls()
  165.         sleep(0.01)
  166.         for cop = 0, bh do
  167.             term.current().setVisible(false)
  168.             sbc(theme.bc)
  169.             cls()
  170.             starfield(20)
  171.             fbox(1, math.max(h/2) - cop/2,w, math.floor(h/2) + cop/2,colors.purple)
  172.             term.current().setVisible(true)
  173.             sleep(0.001)
  174.         end
  175.     elseif(inout == 'out')then
  176.         for cop = 0, bh do
  177.             term.current().setVisible(false)
  178.             sbc(theme.bc)
  179.             cls()
  180.             sleep(0.01)
  181.             starfield(20)
  182.             fbox(1, math.max(h/2) - (bh-cop)/2,w, math.floor(h/2) + (bh-cop)/2,colors.purple)
  183.             term.current().setVisible(true)
  184.             sleep(0.001)
  185.         end
  186.         sbc(theme.bc)
  187.         cls()
  188.         sleep(0.01)
  189.     end
  190. end
  191.  
  192. local function win()
  193.     clscr()
  194.     stc(theme.qtc)
  195.     local bh = 5
  196.     starfield(20)
  197.     msgloop = {
  198.                 "You have proven you're intelligence!",
  199.                 "Nova warmly invites you to join a group of",
  200.                 "Interblocktional Space And Physics thoery! (ISAP)",
  201.                 "Welcome aboard! we will now send the coords to",
  202.                 "Beam up to our academy!",
  203.                 "Do you accept this request to beam up?"
  204.               }
  205.     for i = 1, #msgloop do
  206.         msg = msgloop[i]
  207.         spaceBox('in')
  208.         scp( ((w/2)) - (#msg/2), math.floor(h/2))
  209.         write(msg)
  210.         if(i == #msgloop)then
  211.             stc(colors.pink)
  212.             scp( ((w/2)) - 9, math.floor(h/2)+1)
  213.             lnwrite("Press Y to accept.")
  214.             local _, k = os.pullEvent("key")
  215.             if(k == keys.y)then
  216.                 --]] Beam dem up suun, WOW (wink)!
  217.                 spaceBox('out')
  218.                 local cmd = peripheral.wrap("back")
  219.                 -- ]] Set cmd block cmd and teleport to it
  220.             else
  221.                 os.reboot()
  222.             end
  223.         else
  224.             os.pullEvent("key")
  225.             spaceBox('out')
  226.         end
  227.     end
  228.  
  229. end
  230.  
  231. local function qDraw(qNum)
  232.     clscr()
  233.     starfield(20)
  234.     scp(2,1)
  235.     write(qNum .. ". " .. "Subject: " .. qtable[qNum].s)
  236.     sbc(theme.barbc)
  237.     local rev = false
  238.     for i = 0, getlns(qtable[qNum].q) do
  239.         if(rev)then line(3,3+i,w,3+i) else  line(2,3+i,w-1,3+i) end
  240.         rev = not rev
  241.     end
  242.     stc(theme.bartc)
  243.     scp(4,3)
  244.     lnwrite(qtable[qNum].q)
  245.     sbc(theme.qbc)
  246.     stc(theme.qtc)
  247.     scp(1,10)
  248.     write(string.rep(" ",4) .."Type answer below.")
  249.     sbc(theme.answerbc)
  250.     stc(theme.answertc)
  251.     scp(10,14)
  252.     write(string.rep(" ",w-18))
  253.     scp(10,14)
  254.     local ans = read()
  255.     if(string.lower(ans) ==string.lower(qtable[qNum].a))then
  256.         --]] then User got the question correct.
  257.         qcor = qcor + 1
  258.     end
  259.     transition(0.1)
  260.     if(qNum < #qtable)then
  261.         return qDraw(qNum+1)
  262.     else
  263.         -- Test is over!, calculate final score!
  264.         local perc = (qcor/#qtable)*100
  265.         local grade = "DNF"
  266.         if(perc == 100)       then grade = "A"
  267.             elseif(perc >= 90)then grade = "A+"
  268.             elseif(perc >= 80)then grade = "B"
  269.             elseif(perc >= 70)then grade = "C"
  270.             elseif(perc >= 60)then grade = "D"
  271.             elseif(perc < 60) then grade = "F"
  272.         end
  273.         clscr()
  274.         local good = (perc >= 85)
  275.         msgbox("Final Score: " .. perc .. "% " .. "\nGrade: " .. grade .. "\nPassing: " .. tostring(good),good)
  276.         if(good)then return win() end
  277.         clscr()
  278.         sleep(0.1)
  279.         os.reboot()
  280.     end
  281. end
  282.  
  283. local function choosesubject()
  284.     clscr()
  285.     fbox(5,3,w-2,h-2,colors.lightGray)
  286.     scp(5,2)
  287.     sbc(colors.gray)
  288.     term.clearLine()
  289.     write(" Subject Name         |  Number of Questions ")
  290.     local selsub = 1
  291.     local offs = 0
  292.     local insel = true
  293.     local function draw()
  294.         local mdraw = #subjects
  295.         if(mdraw - h-4 > 0)then mdraw = h-4 end
  296.         for i = 1+offs, mdraw+offs do
  297.             sbc(colors.lightGray)
  298.             stc(colors.black)
  299.             if(selsub == i)then
  300.                 sbc(colors.gray)
  301.                 stc(colors.white)
  302.             end
  303.             scp(5,(i-offs)+3)
  304.             write(subjects[i].s .. "   " .. "Q: " .. #subjects[i].q)
  305.         end
  306.     end
  307.     local function update(e)
  308.         if(e[1] == "key")then
  309.             if(e[2] == keys.up and selsub > 1)then
  310.                 selsub = selsub - 1
  311.                 draw()
  312.             elseif(e[2] == keys.down and selsub < #subjects)then
  313.                 selsub = selsub + 1
  314.                 draw()
  315.             elseif(e[2] == keys.enter)then
  316.                 insel = false
  317.                 return subjects[selsub].q
  318.             end
  319.         end
  320.     end
  321.     local function loop()
  322.         while insel do
  323.             local e = {os.pullEvent()}
  324.             local res = update(e)
  325.             if(res ~= nil)then return res end
  326.         end
  327.     end
  328.     draw()
  329.     qtable = loop()
  330.     qDraw(1)
  331. end
  332. choosesubject()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement