Rolcam

[WIP] Computercraft Tutorial - Section 4 - Test

Jun 15th, 2021 (edited)
802
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --This is part of a Computercraft Programming Teaching Program
  2.  
  3. --[[
  4. Work In Progress - Using Section 3 Test as a placeholder
  5. Todo List:
  6. Add Test 1 -
  7. Add Test 2 -
  8. Add Test 3 -
  9. ]]--
  10.  
  11. loop = 0
  12. rep = 0
  13. prog = 0
  14.  
  15. -- Generates test 1
  16. function gen1()
  17.     print("Generating test program 1...")
  18.     e.writeLine("[            ] <----- ")
  19.     e.writeLine("for e,0,-1 do")
  20.     e.writeLine("term.clear()")
  21.     e.writeLine("term.setCursorPos(1,1)")
  22.     e.writeLine("print(\"The number is: \"..e)")
  23.     e.writeLine("end")
  24.     e.close()
  25.     print("Program Generated")
  26.     sleep(3)
  27. end
  28.  
  29. -- Generates test 2
  30. function gen2()
  31.     print("Generating test program 2...")
  32.     e = fs.open("test", "w")
  33.     e.writeLine("e = 5")
  34.     e.writeLine("while e > 0 do")
  35.     e.writeLine("term.clear()")
  36.     e.writeLine("term.setCursorPos(1,1)")
  37.     e.writeLine("e = e - 1")
  38.     e.writeLine("runTime = os.clock()")
  39.     e.writeLine("[            ] <----- ")
  40.     e.writeLine("sleep(0.1)")
  41.     e.writeLine("end")
  42.     e.close()
  43.     print("Program Generated")
  44.     sleep(3)
  45. end
  46.  
  47. -- Generates test 3
  48. function gen3()
  49.     print("Generating test program 3...")
  50.     e = fs.open("test", "w")
  51.     e.writeLine("term.clear()")
  52.     e.writeLine("term.setCursorPos(1,1)")
  53.     e.writeLine("e = 10")
  54.     if prog == 0 then
  55.         e.writeLine("[         ] <----- ")
  56.     else
  57.         e.writeLine("[e = e + 3]")
  58.     end
  59.     e.writeline("print(e..\" = 13\")")
  60.     e.writeLine("Print(\"Hello World\")")
  61.     e.writeLine("Print(\"What's your name?/")")
  62.    if prog == 1 then
  63.         e.writeLine("[          ] <----- ")
  64.     else
  65.         e.writeLine("[          ]")
  66.     end
  67.     e.writeLine("end")
  68.     e.close()
  69.     print("Program Generated")
  70.     sleep(3)
  71. end
  72.  
  73.  
  74. term.clear()
  75. term.setCursorPos(1,1)
  76. term.setTextColor(colors.purple)
  77. print("Lesson 3 Test - Variables \n ")
  78. print("This is a basic knowledge test")
  79. print("You will be asked to complete a program by inserting a line of code")
  80. print("You aren't timed or scored and you have unlimited attempts \n ")
  81. print("Press the enter key when ready")
  82. read()
  83. gen1()
  84. loop = 1
  85. -- Test 1 of 3
  86. while loop == 1 do
  87.     rep = 6
  88.     term.clear()
  89.     term.setCursorPos(1,1)
  90.     term.setTextColor(colors.purple)
  91.     print("Test 1 of 3\n ")
  92.     test = fs.open("test", "r")
  93.     while rep > 0 do
  94.         print(test.readLine())
  95.         rep = rep - 1
  96.         sleep(0.1)
  97.     end
  98.     print(" \nDeclare the variable \"e\" with a value of 10")
  99.     print("Type \"help\" for a help or \"skip\" to skip")
  100.     input = read()
  101.     if (input == "e=10") or (input == "e = 10") then
  102.         term.setTextColor(colors.lime)
  103.         print("Good Job, that's the right command!")
  104.         sleep(2)
  105.         loop = 0
  106.     elseif input == "help" then
  107.         print("Check the monitor for the lesson")
  108.         shell.run("section2")
  109.         sleep(2)
  110.     elseif input == "skip" then
  111.         print("Skipping Test")
  112.         loop = 0
  113.         sleep(2)
  114.     else
  115.         print("Not quite. Try again")
  116.         sleep(2)
  117.     end
  118. end
  119. gen2()
  120. loop = 1
  121. -- Test 2 of 3
  122. while loop == 1 do
  123.     rep = 9
  124.     term.clear()
  125.     term.setCursorPos(1,1)
  126.     term.setTextColor(colors.purple)
  127.     print("Test 2 of 3\n ")
  128.     test = fs.open("test", "r")
  129.     while rep > 0 do
  130.         print(test.readLine())
  131.         rep = rep - 1
  132.         sleep(0.1)
  133.     end
  134.     print(" \nPrint the value of \"runTime\"")
  135.     print("Type \"help\" for a help or \"skip\" to skip")
  136.     input = read()
  137.     if input == "print(runTime)" then
  138.         term.setTextColor(colors.lime)
  139.         print("Good Job, that's the right command!")
  140.         sleep(2)
  141.         loop = 0
  142.     elseif input == "print(\"runTime\")" then
  143.         print("Close, but not quite")
  144.         print("You want to print the value of the variable, not the variable's name")
  145.         print("Try Again")
  146.         sleep(3)
  147.     elseif input == "print(runtime)" then
  148.         print("Close, but not quite")
  149.         print("Remember, variable names are case sensitive")
  150.         print("Try Again")
  151.         sleep(3)
  152.     elseif input == "help" then
  153.         print("Check the monitor for the lesson")
  154.         shell.run("section2")
  155.         sleep(2)
  156.     elseif input == "skip" then
  157.         print("Skipping Test")
  158.         loop = 0
  159.         sleep(2)
  160.     else
  161.         print("That's not quite right. Try again")
  162.         sleep(2)
  163.     end
  164. end
  165. gen3()
  166. loop = 1
  167. -- Test 3 of 3
  168. while loop == 1 do
  169.     rep = 9
  170.     term.clear()
  171.     term.setCursorPos(1,1)
  172.     term.setTextColor(colors.purple)
  173.     print("Test 3 of 3\n ")
  174.     test = fs.open("test", "r")
  175.     while rep > 0 do
  176.         print(test.readLine())
  177.         rep = rep - 1
  178.         sleep(0.1)
  179.     end
  180.     if prog == 0 then
  181.         print("Make the variable \"e\" equal to itself plus 3")
  182.         input = read()
  183.         if (input == "e = e + 3") or (input == "e=e+3") or (input == "e = e+3") then
  184.             term.setTextColor(colors.lime)
  185.             print("Good Job, that's the right command!")
  186.             sleep(2)
  187.             prog = 1
  188.             gen3()
  189.         elseif input == "help" then
  190.             print("Check the monitor for the lesson")
  191.             shell.run("section2")
  192.             sleep(2)
  193.         elseif input == "skip" then
  194.             print("Skipping...")
  195.             prog = 1
  196.             gen3()
  197.             sleep(2)
  198.         else
  199.             print("That's not quite right. Try again")
  200.             sleep(2)
  201.         end
  202.     else
  203.         print("Use the read command to declare the variable \"name\"")
  204.         input = read()
  205.         if (input == "name = read()") or (input == "name=read()") then
  206.             term.setTextColor(colors.lime)
  207.             print("Good Job, that's the right command!")
  208.             sleep(2)
  209.             loop = 0
  210.         elseif (input == "Name = read()") or (input == "name = Read()") or (input == "Name = Read()") then
  211.             print("Close, but not quite")
  212.             print("Remember, everything is case sensitive")
  213.             print("Try Again
  214.             sleep(4)
  215.         elseif input == "help" then
  216.             print("Check the monitor for the lesson")
  217.             shell.run("section2")
  218.             sleep(2)
  219.         elseif input == "skip" then
  220.             print("Skipping Test")
  221.             loop = 0
  222.             sleep(2)
  223.         else
  224.             print("That's not quite right. Try again")
  225.             sleep(2)
  226.         end
  227.     end        
  228. end
  229. term.clear()
  230. term.setCursorPos(1,1)
  231. term.setTextColor(colors.lime)
  232. print("Congrats, you have competed all three tests")
  233. sleep(3)
  234.        
RAW Paste Data