Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.77 KB | None | 0 0
  1. securityId = 1
  2.  
  3. diskDrive = peripheral.wrap("bottom")
  4. monitor = peripheral.wrap("top")
  5. modem = peripheral.wrap("right")
  6.  
  7. rewardFile = fs.open("reward","r")
  8. if rewardFile then
  9. reward = rewardFile.readAll()
  10. rewardFile.close()
  11. else
  12. reward = "none"
  13. end
  14.  
  15. tokenFile = fs.open("token","r")
  16. if tokenFile then
  17. token = tokenFile.readAll()
  18. tokenFile.close()
  19. else
  20. token = "none"
  21. end
  22.  
  23. playSide = "left"
  24.  
  25. adminScreen = false
  26.  
  27. monitor.setTextScale(.5)
  28.  
  29. local function checkWins(values)
  30. local wins = 0
  31.  
  32. for i=1,3 do
  33. if (values[i] == "X" and values[i+3] == "X" and values[i+6] == "X") then
  34. wins = wins + 1
  35. end
  36. end
  37.  
  38. return wins
  39. end
  40.  
  41. local function doDisplay(values, wins, credits)
  42. monitor.clear()
  43.  
  44. monitor.setCursorPos(5,1)
  45.  
  46. if (wins == 0) then
  47. monitor.write("You Lose")
  48. else
  49. monitor.write("Win x"..wins.."!")
  50. end
  51.  
  52. monitor.setCursorPos(5,3)
  53. monitor.write("+-+-+-+")
  54. monitor.setCursorPos(5,4)
  55. monitor.write("|"..values[1].."|"..values[4].."|"..values[7].."|")
  56. monitor.setCursorPos(5,5)
  57. monitor.write("+-+-+-+")
  58. monitor.setCursorPos(5,6)
  59. monitor.write("|"..values[2].."|"..values[5].."|"..values[8].."|")
  60. monitor.setCursorPos(5,7)
  61. monitor.write("+-+-+-+")
  62. monitor.setCursorPos(5,8)
  63. monitor.write("|"..values[3].."|"..values[6].."|"..values[9].."|")
  64. monitor.setCursorPos(5,9)
  65. monitor.write("+-+-+-+")
  66.  
  67. monitor.setCursorPos(1,10)
  68. monitor.write("Credits :"..credits - 1)
  69. end
  70.  
  71. local function play(credits)
  72. local valuePool = {"O","O","O","O","O","O","X","X","X","X"}
  73.  
  74. local randomValues = {}
  75.  
  76. for i=1,10 do
  77. randomValues[i] = valuePool[math.random(1, 10)]
  78. end
  79.  
  80. wins = checkWins(randomValues)
  81.  
  82. doDisplay(randomValues, wins, credits)
  83.  
  84. if wins > 0 then
  85. turtle.turnRight(1)
  86. turtle.suck(wins)
  87. turtle.turnLeft(1)
  88. turtle.drop(wins)
  89. end
  90. end
  91.  
  92. local function screenSaver(credits)
  93. monitor.clear()
  94. monitor.setCursorPos(1,1)
  95. monitor.write("Token:")
  96. monitor.setCursorPos(1,2)
  97. i = string.find(token, ":")
  98. monitor.write(string.sub(token, i + 1))
  99.  
  100. monitor.setCursorPos(1,3)
  101. monitor.write("Reward:")
  102. monitor.setCursorPos(1,4)
  103. i = string.find(reward, ":")
  104. monitor.write(string.sub(reward, i + 1))
  105.  
  106. monitor.setCursorPos(3,6)
  107. monitor.write("Credits: "..credits, 0)
  108.  
  109. if (credits == 0) then
  110. monitor.setCursorPos(3,8)
  111. monitor.write("Add credits", 1)
  112. end
  113.  
  114. if (credits > 0) then
  115. monitor.setCursorPos(1,8)
  116. monitor.write("Pull the lever")
  117. monitor.setCursorPos(1,9)
  118. monitor.write("to play -->")
  119. end
  120. end
  121.  
  122. adminMenu = {
  123. "Collect Tokens",
  124. "Change Token",
  125. "Add Reward",
  126. "Change Reward",
  127. "Exit"
  128. }
  129.  
  130. selectedItem = 1;
  131.  
  132. local function showAdminMenu(selectedItem)
  133. for i=1,#adminMenu do
  134. if (i == selectedItem) then
  135. monitor.setTextColor(colors.yellow)
  136. end
  137. monitor.setCursorPos(1,2+i)
  138. monitor.write(adminMenu[i])
  139. monitor.setTextColor(colors.white)
  140. end
  141. end
  142.  
  143. local function showAdminScreen()
  144. monitor.clear()
  145. monitor.setCursorPos(2,1)
  146. monitor.write("Welcome Admin")
  147. monitor.setCursorPos(1,2)
  148.  
  149. showAdminMenu(selectedItem)
  150.  
  151. monitor.setCursorPos(1,9)
  152. monitor.write("Submit:")
  153. monitor.setCursorPos(1,10)
  154. monitor.write("Insert Card")
  155. end
  156.  
  157. local function addReward()
  158. turtle.suckDown()
  159. turtle.drop()
  160.  
  161. monitor.clear()
  162. monitor.setCursorPos(1,1)
  163. monitor.write("Add Reward:")
  164. monitor.setCursorPos(1,2)
  165. monitor.write(reward)
  166.  
  167. monitor.setCursorPos(1,4)
  168. monitor.write("Current Stock:")
  169. monitor.setCursorPos(1,5)
  170. monitor.write(rewardCount)
  171.  
  172. os.sleep(2)
  173. end
  174.  
  175. local function collect(tokenChest)
  176. turtle.turnRight(1)
  177.  
  178. if tokenChest then
  179. turtle.turnRight(1)
  180. end
  181.  
  182. max = 16
  183.  
  184. while max == 16 do
  185. for i=1,max do
  186. turtle.suck()
  187.  
  188. if turtle.getItemCount(i) ~= 0 and max ~= 16 then
  189. max = max + 1
  190. end
  191. end
  192.  
  193. turtle.turnLeft(1)
  194.  
  195. if tokenChest then
  196. turtle.turnLeft(1)
  197. end
  198.  
  199. emptySpace = turtle.getItemSpace()
  200.  
  201. for i=1,max do
  202. turtle.select(i)
  203. turtle.drop()
  204. end
  205.  
  206. max = emptySpace
  207.  
  208. turtle.select(1)
  209. end
  210. end
  211.  
  212. local function changeToken()
  213. turtle.suckDown()
  214. turtle.drop()
  215.  
  216. monitor.clear()
  217. monitor.setCursorPos(1,1)
  218. monitor.write("Change Token")
  219. monitor.setCursorPos(1,3)
  220. monitor.write("Drop the item")
  221.  
  222. monitor.setCursorPos(1,5)
  223. monitor.write("Current Token:")
  224. monitor.setCursorPos(1,6)
  225. monitor.write(token)
  226.  
  227. os.sleep(2)
  228. end
  229.  
  230. local function changeReward()
  231. turtle.suckDown()
  232. turtle.drop()
  233.  
  234. monitor.clear()
  235. monitor.setCursorPos(1,1)
  236. monitor.write("Change Reward")
  237. monitor.setCursorPos(1,3)
  238. monitor.write("Drop the item")
  239.  
  240. monitor.setCursorPos(1,5)
  241. monitor.write("Current Reward:")
  242. monitor.setCursorPos(1,6)
  243. monitor.write(reward)
  244.  
  245. os.sleep(2)
  246. end
  247.  
  248. local function addCredits()
  249. turtle.select(1)
  250. if (turtle.suck(64)) then
  251. item = turtle.getItemDetail(1)
  252.  
  253. print(item.name)
  254.  
  255. if (selectedItem == 2) and (item.name ~= "computercraft:disk") then
  256. tokenFile = fs.open("token",'w')
  257. tokenFile.write(item.name)
  258. tokenFile.close()
  259.  
  260. token = item.name
  261.  
  262. monitor.clear()
  263. monitor.setCursorPos(1,5)
  264. monitor.write("Token set:")
  265. monitor.setCursorPos(1,6)
  266. monitor.write(item.name)
  267.  
  268. os.sleep(2)
  269.  
  270. collect(true)
  271.  
  272. selectedItem = 1
  273. adminScreen = false
  274. elseif (selectedItem == 3) then
  275. if (item.name == "computercraft:disk") then
  276. selectedItem = 1
  277. adminScreen = false
  278. else
  279. turtle.turnRight(1)
  280. turtle.drop(64)
  281. turtle.turnLeft(1)
  282. end
  283. elseif (selectedItem == 4) and (item.name ~= "computercraft:disk") then
  284. rewardFile = fs.open("reward","w")
  285. rewardFile.write(item.name)
  286. rewardFile.close()
  287.  
  288. reward = item.name
  289.  
  290. monitor.clear()
  291. monitor.setCursorPos(1,5)
  292. monitor.write("Reward set:")
  293. monitor.setCursorPos(1,6)
  294. monitor.write(item.name)
  295.  
  296. os.sleep(2)
  297.  
  298. collect(false)
  299.  
  300. selectedItem = 1
  301. adminScreen = false
  302. elseif (item.name == token) then
  303. count = item.count
  304.  
  305. turtle.turnRight(1)
  306. turtle.turnRight(1)
  307. turtle.drop(64)
  308. turtle.turnLeft(1)
  309. turtle.turnLeft(1)
  310.  
  311. credits = credits + count
  312.  
  313. screenSaver(credits)
  314. elseif (item.name == "computercraft:disk") then
  315. turtle.dropDown()
  316. file = fs.open("disk/keycard", "r")
  317.  
  318. if file then
  319. password = file.readAll()
  320. file.close()
  321.  
  322. modem.open(714)
  323. modem.transmit(816, 714, securityId..": "..diskDrive.getDiskID().."="..password)
  324. event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  325.  
  326. if message then
  327. turtle.suckDown()
  328. turtle.drop()
  329.  
  330. if not adminScreen then
  331. showAdminScreen()
  332. adminScreen = true
  333. elseif selectedItem == 4 then
  334. changeReward()
  335. elseif selectedItem == 3 then
  336. addReward()
  337. elseif selectedItem == 2 then
  338. changeToken()
  339. elseif selectedItem == 1 then
  340. collect(true)
  341. else
  342. adminScreen = false
  343. selectedItem = 1
  344. end
  345. end
  346. end
  347.  
  348. turtle.suckDown()
  349. end
  350. turtle.drop()
  351. os.sleep(2)
  352. end
  353. end
  354.  
  355. local function main()
  356. credits = 0
  357.  
  358. if adminScreen then
  359. if rs.getInput("left") then
  360. if selectedItem == #adminMenu then
  361. selectedItem = 1
  362. else
  363. selectedItem = selectedItem + 1
  364. end
  365.  
  366. showAdminMenu(selectedItem)
  367. os.sleep(1)
  368. end
  369. else
  370. screenSaver(credits)
  371. end
  372.  
  373. addCredits()
  374.  
  375. while credits > 0 do
  376. if (turtle.suck()) then
  377. addCredits()
  378. end
  379.  
  380. os.pullEvent("redstone")
  381.  
  382. if (rs.getInput(playSide) and credits > 0) then
  383.  
  384. play(credits)
  385.  
  386. credits = credits - 1
  387.  
  388. if (credits == 0) then
  389. os.sleep(5)
  390. end
  391. end
  392.  
  393. if (credits == 0 and not adminScreen) then
  394. screenSaver(0)
  395. end
  396. end
  397. end
  398.  
  399. while true do
  400. main()
  401. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement