NeonJ

Double or Nothing

Nov 9th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.55 KB | None | 0 0
  1. credits = 0
  2. creditswin = 0
  3. detectside = "back"
  4. monside = "left"
  5. dispenserside = "top"
  6. stopperside = "right"
  7.  
  8. mon = peripheral.wrap(monside)
  9. redstone.setOutput(stopperside,true)
  10. shell.run("clear",1)
  11.  
  12. mon.setCursorPos(1,1)
  13. mon.write("CREDITS")
  14. mon.setCursorPos(1,2)
  15. mon.write("  000  ")
  16. mon.setCursorPos(1,3)
  17. mon.write("*******")
  18. mon.setCursorPos(1,4)
  19. mon.write("INSERT ")
  20. mon.setCursorPos(1,5)
  21. mon.write(" CREDIT")
  22.  
  23. print("Hold Control + T to terminate Double or Nothing.")
  24.  
  25. function winner()
  26.     mon.setCursorPos(1,4)
  27.     mon.write("  YOU  ")
  28.     mon.setCursorPos(1,5)
  29.     mon.write("  WIN  ")
  30.     sleep(2)
  31.     if result == "WIN" then
  32.         creditswin = credits
  33.  
  34.         str = string.format("%03d", credits)
  35.         mon.setCursorPos(1,2)
  36.         mon.write("  "..str.."  ")
  37.     end
  38.     while creditswin > 0 do
  39.         credits = credits + 1
  40.         creditswin = creditswin - 1
  41.  
  42.         str = string.format("%03d", credits)
  43.         mon.setCursorPos(1,2)
  44.         mon.write("  "..str.."  ")
  45.  
  46.         sleep(0.2)
  47.     end
  48.     sleep(2)
  49.     mon.setCursorPos(1,4)
  50.     mon.write("PRESS  ")
  51.     mon.setCursorPos(1,5)
  52.     mon.write(" BUTTON")
  53.     redstone.setOutput(stopperside, true)
  54. end
  55.  
  56. function roll()
  57.     rollsdone = 0
  58.     temproll = 0
  59.     redstone.setOutput(stopperside, false)
  60.     result = math.random(1,2)
  61.     result = result - ".0"
  62.     if result == 1 then result = "WIN"
  63.     else result = "LOSE" end    
  64.     while rollsdone < 50 do
  65.         mon.setCursorPos(1,4)
  66.         if temproll == 0 then
  67.             mon.write("*  *  *")
  68.             mon.setCursorPos(1,5)
  69.             mon.write(" *  *  ")
  70.             temproll = 1
  71.         elseif temproll == 1 then
  72.             mon.write(" *  *  ")
  73.             mon.setCursorPos(1,5)
  74.             mon.write("*  *  *")
  75.             temproll = 2
  76.         elseif temproll == 2 then
  77.             mon.write("  *  * ")
  78.             mon.setCursorPos(1,5)
  79.             mon.write("  *  * ")
  80.             temproll = 0
  81.         end
  82.         rollsdone = rollsdone + 1
  83.         sleep(0.05)
  84.     end
  85.    
  86.     if result == "WIN" then
  87.         print("Detected win!")
  88.         winner()
  89.     else
  90.         print("Detected loss.")
  91.         mon.setCursorPos(1,4)
  92.         mon.write("  TRY  ")
  93.         mon.setCursorPos(1,5)
  94.         mon.write(" AGAIN ")
  95.  
  96.         while credits > 0 do
  97.             credits = credits - 1
  98.             str = string.format("%03d", credits)
  99.             mon.setCursorPos(1,1)
  100.             mon.write("CREDITS")
  101.             mon.setCursorPos(1,2)
  102.             mon.write("  "..str.."  ")
  103.             sleep(0.2)
  104.         end
  105.  
  106.         sleep(2)
  107.         mon.setCursorPos(1,4)
  108.         mon.write("INSERT ")
  109.         mon.setCursorPos(1,5)
  110.         mon.write(" CREDIT")
  111.         redstone.setOutput(stopperside, true)
  112.     end
  113. end
  114.  
  115. function payout()
  116.     sleep(2)
  117.     while credits > 0 do
  118.         redstone.setOutput(dispenserside, true)
  119.         sleep(0.2)
  120.         redstone.setOutput(dispenserside, false)
  121.         credits = credits - 1
  122.  
  123.         str = string.format("%03d", credits)
  124.         mon.setCursorPos(1,4)
  125.         mon.write("  PAY  ")
  126.         mon.setCursorPos(1,5)
  127.         mon.write("  OUT  ")
  128.         mon.setCursorPos(1,2)
  129.         mon.write("  "..str.."  ")
  130.         mon.setCursorPos(1,3)
  131.         mon.write("*******")
  132.     end
  133.  
  134.     mon.setCursorPos(1,4)
  135.     mon.write("INSERT ")
  136.     mon.setCursorPos(1,5)
  137.     mon.write(" CREDIT")
  138.     redstone.setOutput(stopperside, true)
  139. end
  140.  
  141. redstone.setOutput(stopperside, true)
  142.  
  143. rRunning = true
  144.  
  145. while rRunning do
  146.     sleep(0.05)
  147.     local rEvent, param = os.pullEvent()
  148.     redstone.setOutput(stopperside, true)
  149.     if rEvent == "redstone" then
  150.         if redstone.getBundledInput(detectside) then
  151.             if redstone.testBundledInput(detectside, colors.yellow) == true then
  152.                 credits = credits + 1
  153.  
  154.                 str = string.format("%03d", credits)
  155.                 mon.setCursorPos(1,1)
  156.                 mon.write("CREDITS")
  157.                 mon.setCursorPos(1,2)
  158.                 mon.write("  "..str.."  ")
  159.  
  160.                 mon.setCursorPos(1,4)
  161.                 mon.write("PRESS  ")
  162.                 mon.setCursorPos(1,5)
  163.                 mon.write(" BUTTON")
  164.             elseif redstone.testBundledInput(detectside, colors.red) == true then
  165.                 redstone.setOutput(stopperside, false)
  166.                 if credits > 0 then
  167.                     roll()
  168.                 else
  169.                     mon.setCursorPos(1,4)
  170.                     mon.write("1 COIN ")
  171.                     mon.setCursorPos(1,5)
  172.                     mon.write(" NEEDED")
  173.                     sleep(2)
  174.  
  175.                     mon.setCursorPos(1,4)
  176.                     mon.write("INSERT ")
  177.                     mon.setCursorPos(1,5)
  178.                     mon.write(" CREDIT")
  179.                     redstone.setOutput(stopperside, true)
  180.                 end
  181.             elseif redstone.testBundledInput(detectside, colors.orange) == true then
  182.                 redstone.setOutput(stopperside, false)
  183.                 if credits > 0 then
  184.                     payout()
  185.                 else
  186.                     mon.setCursorPos(1,4)
  187.                     mon.write("NONE   ")
  188.                     mon.setCursorPos(1,5)
  189.                     mon.write("   LEFT")
  190.                     sleep(2)
  191.  
  192.                     mon.setCursorPos(1,4)
  193.                     mon.write("INSERT ")
  194.                     mon.setCursorPos(1,5)
  195.                     mon.write(" CREDIT")
  196.                     redstone.setOutput(stopperside, true)
  197.                 end
  198.             end
  199.         end
  200.     end
  201. end
Advertisement
Add Comment
Please, Sign In to add comment