Guest User

Untitled

a guest
Apr 20th, 2013
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.24 KB | None | 0 0
  1. function readData ( nFile )
  2. ak=fs.open(nFile,"r")
  3. nDat = ak:readAll()
  4. ak:close()
  5. return nDat
  6. end
  7.  
  8. nComments = {
  9. "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!"
  10. }
  11. nindex = math.random(#nComments)
  12.  
  13. function returnLines ( nFile )
  14. ak=io.open(nFile,"r")
  15. nFileLines = {}
  16. for line in ak:lines() do
  17. nFileLines[#nFileLines+1] = line
  18. end
  19. ak:close()
  20. return nFileLines
  21. end
  22.  
  23. function readSong ()
  24. dn = returnLines(".passbeat")
  25. nacs = {}
  26. for i=1, #dn do
  27. nacs[i]=tonumber(dn[i])
  28. end
  29. return nacs
  30. end
  31.  
  32. function loadSettings ()
  33. if not fs.exists(".setx") then
  34. return 70
  35. else
  36. return tonumber(readData(".setx"))
  37. end
  38. end
  39.  
  40. nSettin = loadSettings()
  41.  
  42. function sntim ()
  43. while true do
  44. term.clear()
  45. term.setCursorPos(1,1)
  46. bufStr = tostring((tick-1)/5)
  47. if bufStr:len() == 1 then nindex = math.random(#nComments) bufStr = bufStr..".0" end
  48. cPrint(bufStr)
  49. cPrint(nComments[nindex])
  50. os.sleep(0.2)
  51. tick = tick + 1
  52. if (tick-1)/5 == 10 then
  53. break
  54. end
  55. end
  56. end
  57.  
  58. function smtim ()
  59. while true do
  60. action = os.pullEvent("key")
  61. notes[tick] = notes[tick]+1
  62. end
  63. end
  64.  
  65. function saveSong ( nNotes )
  66. ak=io.open(".passbeat","w")
  67. for i=1, 52 do
  68. if i < 52 then
  69. ak:write(tostring(nNotes[i]).."\n")
  70. else
  71. ak:write(tostring(nNotes[i]))
  72. end
  73. end
  74. ak:close()
  75. end
  76.  
  77. os.pullEvent = os.pullEventRaw
  78. term.clear()
  79. term.setCursorPos(1,1)
  80.  
  81. function cPrint ( nText )
  82. scrWid, scrHei = term.getSize()
  83. print(string.rep(" ",scrWid/2-nText:len()/2)..nText..string.rep(" ",scrWid/2-nText:len()/2))
  84. end
  85.  
  86.  
  87.  
  88. function mode_a ()
  89. cPrint("Welcome!")
  90. cPrint("- Passbeat Security System -")
  91. print("")
  92. sleep(2)
  93. cPrint("Press any key to setup your beat!")
  94. os.pullEvent('key')
  95. term.clear()
  96. term.setCursorPos(1,1)
  97. cPrint("3")
  98. os.sleep(1)
  99. term.clear()
  100. term.setCursorPos(1,1)
  101. cPrint("2")
  102. os.sleep(1)
  103. term.clear()
  104. term.setCursorPos(1,1)
  105. cPrint("1")
  106. os.sleep(1)
  107. term.clear()
  108. term.setCursorPos(1,1)
  109. cPrint("GO!")
  110. os.sleep(0.5)
  111. term.clear()
  112. term.setCursorPos(1,1)
  113. tick = 1
  114. notes = {}
  115. for i=1, 52 do
  116. notes[i] = 0
  117. end
  118. parallel.waitForAny( sntim, smtim )
  119. term.clear()
  120. term.setCursorPos(1,1)
  121. cEmpty = true
  122. for i=1, 52 do
  123. if notes[i] ~= 0 then cEmpty = false end
  124. end
  125. if cEmpty then
  126. cPrint(":( We didn't hear anything. Try again!")
  127. os.sleep(2)
  128. mode_a()
  129. end
  130. cPrint("-Thank You-")
  131. cPrint("We received your song data!")
  132. cPrint("Recorded into the pass system!")
  133. print("")
  134. cPrint("Saving data...")
  135. cPrint("Please wait!")
  136. saveSong(notes)
  137. while true do
  138. term.clear()
  139. term.setCursorPos(1,1)
  140. cPrint("We need more info!")
  141. cPrint("What should be the passing percent correct?")
  142. print("")
  143. write(" PERCENT: ")
  144. nPerc = tonumber(read())
  145. if nPerc == nil or nPerc > 89 or nPerc < 50 then
  146. cPrint("Sorry, that's invalid. Percentage needs to be 50-89%")
  147. sleep(2)
  148. else
  149. ak=io.open(".setx","w")
  150. ak:write(tostring(nPerc))
  151. ak:close()
  152. break
  153. end
  154. end
  155. term.clear()
  156. term.setCursorPos(1,1)
  157. cPrint("-Thank You-")
  158. cPrint("We received your song data!")
  159. cPrint("Recorded into the pass system!")
  160. print("")
  161. cPrint("Rebooting!")
  162. os.sleep(3)
  163. os.reboot()
  164. end
  165.  
  166.  
  167.  
  168. function mode_b ()
  169. song = readSong()
  170. term.clear()
  171. term.setCursorPos(1,1)
  172. cPrint("-PASS SONG-")
  173. print("")
  174. os.sleep(2)
  175. cPrint("Press any key to start!")
  176. os.pullEvent('key')
  177. term.clear()
  178. term.setCursorPos(1,1)
  179. cPrint("3")
  180. cPrint(string.rep("-",45))
  181. os.sleep(1)
  182. term.clear()
  183. term.setCursorPos(1,1)
  184. cPrint("2")
  185. cPrint(string.rep("-",45))
  186. os.sleep(1)
  187. term.clear()
  188. term.setCursorPos(1,1)
  189. cPrint("1")
  190. cPrint(string.rep("-",45))
  191. os.sleep(1)
  192. term.clear()
  193. term.setCursorPos(1,1)
  194. cPrint("GO!")
  195. cPrint(string.rep("-",45))
  196. os.sleep(0.5)
  197. term.clear()
  198. term.setCursorPos(1,1)
  199. tick = 1
  200. notes = {}
  201. for i=1, 52 do
  202. notes[i] = 0
  203. end
  204. parallel.waitForAny( sntim, smtim )
  205. term.clear()
  206. term.setCursorPos(1,1)
  207. cPrint("Analyzing...")
  208. sif=0
  209. for i=1, 52 do
  210. if notes[i] == song[i] then
  211. sif=sif+1
  212. end
  213. end
  214. isAble = false
  215. if sif/52 >= nSettin/100 then
  216. isAble = true
  217. end
  218. sig=0
  219. for i=1, 52 do
  220. if notes[i] == song[i-1] then
  221. sig=sig+1
  222. end
  223. end
  224. if sig/52 >= nSettin/100 then
  225. isAble = true
  226. end
  227. siq=0
  228. for i=1, 52 do
  229. if notes[i] == song[i+1] then
  230. siq=siq+1
  231. end
  232. end
  233. if siq/52 >= nSettin/100 then
  234. isAble = true
  235. end
  236.  
  237. nMax = sif/52*100
  238. if sig/52*100 > nMax then nMax = sig/52*100 end
  239. if siq/52*100 > nMax then nMax = siq/52*100 end
  240.  
  241. if isAble then
  242. term.clear()
  243. term.setCursorPos(1,1)
  244. cPrint("Access Granted!")
  245. print("")
  246. cPrint("Score: " .. tostring(nMax) .. "%" )
  247. print("")
  248. cPrint("Passing Grade: "..tostring(nSettin).."%")
  249. os.sleep(3)
  250. term.clear()
  251. term.setCursorPos(1,1)
  252. print("CraftOS")
  253. else
  254. term.clear()
  255. term.setCursorPos(1,1)
  256. cPrint("Access Denied!")
  257. print("")
  258. cPrint("Score: " .. tostring(nMax) .. "%" )
  259. print("")
  260. cPrint("Passing Grade: "..tostring(nSettin).."%")
  261. os.sleep(3)
  262. os.reboot()
  263. end
  264. end
  265.  
  266. if not fs.exists(".passbeat") then
  267. mode_a()
  268. else
  269. if not fs.exists(".setx") then
  270. mode_a()
  271. else
  272. mode_b()
  273. end
  274. end
Advertisement
Add Comment
Please, Sign In to add comment