Advertisement
subzero22

slot machine

Nov 15th, 2014
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. disc = peripheral.wrap("bottom")
  2. mon = peripheral.wrap("top")
  3. mon.clear()
  4. mon.setCursorPos(1,1)
  5. side = "back"
  6.  
  7. function disk()
  8.   os.pullEvent("disk")
  9.  if disc.getLabel() == "SLOTS" and fs.exists("disk/.slots") == true then
  10.    local file = fs.open("disk/.slots", "r")
  11.   if file then
  12.     tokens = file.readLine()
  13.     file.close()
  14.   end
  15.  end
  16.   disc.eject()
  17.   mon.clear()
  18. end
  19.  
  20. term.clear()
  21. term.setCursorPos(1,1)
  22.  
  23. function won()
  24.  mon.write("YOU WON!!!")
  25. end
  26.  
  27. function lost()
  28.  mon.write("YOU LOST  ")
  29. end
  30.  
  31. c1 = colors.white
  32. c2 = colors.orange
  33. c3 = colors.magenta
  34. c4 = colors.lightBlue
  35. c5 = colors.yellow
  36. c6 = colors.lime
  37. c7 = colors.pink
  38. c8 = colors.gray
  39. c9 = colors.lightGray
  40. c10 = colors.cyan
  41. c11 = colors.purple
  42. c12 = colors.blue
  43. c13 = colors.brown
  44. c14 = colors.green
  45. c15 = colors.red
  46. c16 = colors.black
  47.  
  48. line1 = " =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
  49. line2 = " -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"
  50. line = 0
  51.  
  52. while true do
  53.   mon.clear()
  54.   mon.setCursorPos(1,1)
  55.   mon.write(line1)
  56.   mon.setCursorPos(1,17)
  57.   mon.write(line2)
  58.   mon.setCursorPos(2,2)
  59.   mon.write("Tokens: "..tokens.."     ")
  60.   mon.setCursorPos(5,9)
  61.   mon.write("PLEASE ENTER TOKENS TO PLAY")
  62.   disk()
  63.  for i=1,tokens do
  64.    sleep(1)
  65.    rs.setBundledOutput("back", 0)
  66.    mon.setCursorPos(2,2)
  67.    tokens = tokens - 1
  68.    mon.write("Tokens: "..tokens.."    ")
  69.  
  70.   for i=1,10 do
  71.     mon.setCursorPos(1,1)
  72.    if line == 0 then
  73.      mon.write(line1)
  74.      line = 1
  75.    else
  76.      mon.write(line2)
  77.      line = 0
  78.    end
  79.     mon.setCursorPos(1,17)
  80.    if line == 0 then
  81.      mon.write(line2)
  82.    else
  83.      mon.write(line1)
  84.    end
  85.  
  86.     a = math.random(8)
  87.     b = math.random(8)
  88.     c = math.random(8)
  89.  
  90.     mon.setCursorPos(10,9)
  91.     mon.write(a.." - "..b.." - "..c)
  92.     sleep(0.5)
  93.   end
  94.    sleep(0.5)
  95.    mon.setCursorPos(10,9)
  96.    mon.write(a.." - "..b.." - "..c)
  97.    mon.setCursorPos(10,7)
  98.  
  99.   if a == b and b == c then
  100.     won()
  101.    if b == 8 then
  102.      rs.setBundledOutput(side, c1)
  103.    elseif b == 7 then
  104.      rs.setBundledOutput(side, c2)
  105.    elseif b == 6 then
  106.      rs.setBundledOutput(side, c3)
  107.    elseif b == 5 then
  108.      rs.setBundledOutput(side, c4)
  109.    elseif b == 4 then
  110.      rs.setBundledOutput(side, c5)
  111.    elseif b == 3 then
  112.      rs.setBundledOutput(side, c6)
  113.    elseif b == 2 then
  114.      rs.setBundledOutput(side, c7)
  115.    elseif b == 1 then
  116.      rs.setBundledOutput(side, c8)
  117.    end
  118.   elseif a == b or b == c then
  119.     won()
  120.    if b == 8 then
  121.      rs.setBundledOutput(side, c9)
  122.    elseif b == 7 then
  123.      rs.setBundledOutput(side, c10)
  124.    elseif b == 6 then
  125.      rs.setBundledOutput(side, c11)
  126.    elseif b == 5 then
  127.      rs.setBundledOutput(side, c12)
  128.    elseif b == 4 then
  129.      rs.setBundledOutput(side, c13)
  130.    elseif b == 3 then
  131.      rs.setBundledOutput(side, c14)
  132.    elseif b == 2 then
  133.      rs.setBundledOutput(side, c15)
  134.    elseif b == 1 then
  135.      rs.setBundledOutput(side, c16)
  136.    end
  137.   else
  138.     lost()
  139.   end
  140.    sleep(2)
  141.  end
  142. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement