Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This is part of a Computercraft Programming Teaching Program
- for i = 1, #tSides do
- monitor = peripheral.wrap(tSides[i])
- if monitor then
- side = tSides[i]
- break
- end
- end
- -- Clears the monitor screen
- function reset()
- term.redirect(peripheral.wrap(side))
- term.clear()
- term.restore()
- end
- loop = 0
- rep = 0
- prog = 0
- -- Generates test 1
- function gen1()
- print("Generating test program 1...")
- e = fs.open("test", "w")
- e.writeLine("[ ] <----- ")
- e.writeLine("term.setCursorPos(1,1)")
- e.writeLine("print(\"Hello World\")")
- e.close()
- print("Program Generated")
- sleep(3)
- end
- -- Generates test 2
- function gen2()
- print("Generating test program 2...")
- e = fs.open("test", "w")
- e.writeLine("e = 5")
- e.writeLine("while e > 0 do")
- e.writeLine("term.clear()")
- e.writeLine("term.setCursorPos(1,1)")
- e.writeLine("e = e - 1")
- e.writeLine("eTime = os.clock()")
- e.writeLine("print(eTime)")
- e.writeLine("[ ] <----- ")
- e.writeLine("end")
- e.close()
- print("Program Generated")
- sleep(3)
- end
- -- Generates test 3
- function gen3()
- print("Generating test program 3...")
- e = fs.open("test", "w")
- e.writeLine("term.clear()")
- e.writeLine("term.setCursorPos(1,1)")
- e.writeLine("Print(\"Hello\")")
- if prog == 0 then
- e.writeLine("[ ] <----- ")
- else
- e.writeLine("[sleep(3)]")
- end
- e.writeLine("print(\"World\")")
- if prog == 1 then
- e.writeLine("[ ] <----- ")
- else
- e.writeLine("[ ]")
- end
- e.writeLine("end")
- e.close()
- print("Program Generated")
- sleep(3)
- end
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.purple)
- print("Lesson 2 Test - Basic Commands \n ")
- print("This is a basic knowledge test")
- print("You will be asked to complete a program by inserting a line of code")
- print("You aren't timed or scored and you have unlimited attempts \n ")
- print("Press the enter key when ready")
- read()
- gen1()
- loop = 1
- reset()
- -- Test 1 of 3
- while loop == 1 do
- rep = 4
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.purple)
- print("Test 1 of 3\n ")
- test = fs.open("test", "r")
- while rep > 0 do
- print(test.readLine())
- rep = rep - 1
- sleep(0.1)
- end
- print(" \nClear the screen")
- print("Type \"help\" for a help or \"skip\" to skip")
- input = read()
- if input == "term.clear()" then
- term.setTextColor(colors.lime)
- print("Good Job, that's the right command!")
- sleep(2)
- loop = 0
- elseif input == "clear" then
- print("You're close, but not quite.")
- print("That works on the terminal, but not in a program")
- print("Try Again")
- sleep(5)
- elseif input == "help" then
- print("Check the monitor for the lesson")
- shell.run("section2")
- sleep(2)
- elseif input == "skip" then
- print("Skipping Test")
- loop = 0
- sleep(2)
- else
- print("Not quite. Try again")
- sleep(2)
- end
- end
- gen2()
- loop = 1
- reset()
- -- Test 2 of 3
- while loop == 1 do
- rep = 9
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.purple)
- print("Test 2 of 3\n ")
- test = fs.open("test", "r")
- while rep > 0 do
- print(test.readLine())
- rep = rep - 1
- sleep(0.1)
- end
- print(" \nMake the program sleep for 2 seconds")
- print("Type \"help\" for a help or \"skip\" to skip")
- input = read()
- if input == "sleep(2)" then
- term.setTextColor(colors.lime)
- print("Good Job, that's the right command!")
- sleep(2)
- loop = 0
- elseif input == "help" then
- print("Check the monitor for the lesson")
- shell.run("section2")
- sleep(2)
- elseif input == "skip" then
- print("Skipping Test")
- loop = 0
- sleep(2)
- else
- print("That's not quite right. Try again")
- sleep(2)
- end
- end
- gen3()
- loop = 1
- reset()
- -- Test 3 of 3
- while loop == 1 do
- rep = 7
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.purple)
- print("Test 3 of 3\n ")
- test = fs.open("test", "r")
- while rep > 0 do
- print(test.readLine())
- rep = rep - 1
- sleep(0.1)
- end
- if prog == 0 then
- print("Make the program sleep for 3 seconds")
- input = read()
- if input == "sleep(3)" then
- term.setTextColor(colors.lime)
- print("Good Job, that's the right command!")
- sleep(2)
- prog = 1
- reset()
- gen3()
- elseif input == "help" then
- print("Check the monitor for the lesson")
- shell.run("section2")
- sleep(2)
- elseif input == "skip" then
- print("Skipping...")
- prog = 1
- gen3()
- reset()
- sleep(2)
- else
- print("That's not quite right. Try again")
- sleep(2)
- end
- else
- print("Make the computer shutdown")
- input = read()
- if input == "os.shutdown()" then
- term.setTextColor(colors.lime)
- print("Good Job, that's the right command!")
- sleep(2)
- loop = 0
- elseif input == "os.shutdown" then
- print("Close, but not quite. Try again")
- sleep(3)
- elseif input == "shutdown" then
- print("That works in the terminal, but not in the program.")
- print("Close, but not quite. Try again")
- sleep(4)
- elseif input == "help" then
- print("Check the monitor for the lesson")
- shell.run("section2")
- sleep(2)
- elseif input == "skip" then
- print("Skipping Test")
- loop = 0
- sleep(2)
- else
- print("That's not quite right. Try again")
- sleep(2)
- end
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.lime)
- print("Congrats, you have competed all three tests")
- sleep(3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement