Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function readData ( nFile )
- ak=fs.open(nFile,"r")
- nDat = ak:readAll()
- ak:close()
- return nDat
- end
- nComments = {
- "Keep that groove!", "That's right!", "You're doing great!", "Hell yeah!", "You're on FIRE!","Mhmm... mhmm...","Keep it up!","You can do it!"
- }
- nindex = math.random(#nComments)
- function returnLines ( nFile )
- ak=io.open(nFile,"r")
- nFileLines = {}
- for line in ak:lines() do
- nFileLines[#nFileLines+1] = line
- end
- ak:close()
- return nFileLines
- end
- function readSong ()
- dn = returnLines(".passbeat")
- nacs = {}
- for i=1, #dn do
- nacs[i]=tonumber(dn[i])
- end
- return nacs
- end
- function loadSettings ()
- if not fs.exists(".setx") then
- return 70
- else
- return tonumber(readData(".setx"))
- end
- end
- nSettin = loadSettings()
- function sntim ()
- while true do
- term.clear()
- term.setCursorPos(1,1)
- bufStr = tostring((tick-1)/5)
- if bufStr:len() == 1 then nindex = math.random(#nComments) bufStr = bufStr..".0" end
- cPrint(bufStr)
- cPrint(nComments[nindex])
- os.sleep(0.2)
- tick = tick + 1
- if (tick-1)/5 == 10 then
- break
- end
- end
- end
- function smtim ()
- while true do
- action = os.pullEvent("key")
- notes[tick] = notes[tick]+1
- end
- end
- function saveSong ( nNotes )
- ak=io.open(".passbeat","w")
- for i=1, 52 do
- if i < 52 then
- ak:write(tostring(nNotes[i]).."\n")
- else
- ak:write(tostring(nNotes[i]))
- end
- end
- ak:close()
- end
- os.pullEvent = os.pullEventRaw
- term.clear()
- term.setCursorPos(1,1)
- function cPrint ( nText )
- scrWid, scrHei = term.getSize()
- print(string.rep(" ",scrWid/2-nText:len()/2)..nText..string.rep(" ",scrWid/2-nText:len()/2))
- end
- function mode_a ()
- cPrint("Welcome!")
- cPrint("- Passbeat Security System -")
- print("")
- sleep(2)
- cPrint("Press any key to setup your beat!")
- os.pullEvent('key')
- term.clear()
- term.setCursorPos(1,1)
- cPrint("3")
- os.sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- cPrint("2")
- os.sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- cPrint("1")
- os.sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- cPrint("GO!")
- os.sleep(0.5)
- term.clear()
- term.setCursorPos(1,1)
- tick = 1
- notes = {}
- for i=1, 52 do
- notes[i] = 0
- end
- parallel.waitForAny( sntim, smtim )
- term.clear()
- term.setCursorPos(1,1)
- cEmpty = true
- for i=1, 52 do
- if notes[i] ~= 0 then cEmpty = false end
- end
- if cEmpty then
- cPrint(":( We didn't hear anything. Try again!")
- os.sleep(2)
- mode_a()
- end
- cPrint("-Thank You-")
- cPrint("We received your song data!")
- cPrint("Recorded into the pass system!")
- print("")
- cPrint("Saving data...")
- cPrint("Please wait!")
- saveSong(notes)
- while true do
- term.clear()
- term.setCursorPos(1,1)
- cPrint("We need more info!")
- cPrint("What should be the passing percent correct?")
- print("")
- write(" PERCENT: ")
- nPerc = tonumber(read())
- if nPerc == nil or nPerc > 89 or nPerc < 50 then
- cPrint("Sorry, that's invalid. Percentage needs to be 50-89%")
- sleep(2)
- else
- ak=io.open(".setx","w")
- ak:write(tostring(nPerc))
- ak:close()
- break
- end
- end
- term.clear()
- term.setCursorPos(1,1)
- cPrint("-Thank You-")
- cPrint("We received your song data!")
- cPrint("Recorded into the pass system!")
- print("")
- cPrint("Rebooting!")
- os.sleep(3)
- os.reboot()
- end
- function mode_b ()
- song = readSong()
- term.clear()
- term.setCursorPos(1,1)
- cPrint("-PASS SONG-")
- print("")
- os.sleep(2)
- cPrint("Press any key to start!")
- os.pullEvent('key')
- term.clear()
- term.setCursorPos(1,1)
- cPrint("3")
- cPrint(string.rep("-",45))
- os.sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- cPrint("2")
- cPrint(string.rep("-",45))
- os.sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- cPrint("1")
- cPrint(string.rep("-",45))
- os.sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- cPrint("GO!")
- cPrint(string.rep("-",45))
- os.sleep(0.5)
- term.clear()
- term.setCursorPos(1,1)
- tick = 1
- notes = {}
- for i=1, 52 do
- notes[i] = 0
- end
- parallel.waitForAny( sntim, smtim )
- term.clear()
- term.setCursorPos(1,1)
- cPrint("Analyzing...")
- sif=0
- for i=1, 52 do
- if notes[i] == song[i] then
- sif=sif+1
- end
- end
- isAble = false
- if sif/52 >= nSettin/100 then
- isAble = true
- end
- sig=0
- for i=1, 52 do
- if notes[i] == song[i-1] then
- sig=sig+1
- end
- end
- if sig/52 >= nSettin/100 then
- isAble = true
- end
- siq=0
- for i=1, 52 do
- if notes[i] == song[i+1] then
- siq=siq+1
- end
- end
- if siq/52 >= nSettin/100 then
- isAble = true
- end
- nMax = sif/52*100
- if sig/52*100 > nMax then nMax = sig/52*100 end
- if siq/52*100 > nMax then nMax = siq/52*100 end
- if isAble then
- term.clear()
- term.setCursorPos(1,1)
- cPrint("Access Granted!")
- print("")
- cPrint("Score: " .. tostring(nMax) .. "%" )
- print("")
- cPrint("Passing Grade: "..tostring(nSettin).."%")
- os.sleep(3)
- term.clear()
- term.setCursorPos(1,1)
- print("CraftOS")
- else
- term.clear()
- term.setCursorPos(1,1)
- cPrint("Access Denied!")
- print("")
- cPrint("Score: " .. tostring(nMax) .. "%" )
- print("")
- cPrint("Passing Grade: "..tostring(nSettin).."%")
- os.sleep(3)
- os.reboot()
- end
- end
- if not fs.exists(".passbeat") then
- mode_a()
- else
- if not fs.exists(".setx") then
- mode_a()
- else
- mode_b()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment