ZNZNCOOP

Casino3

Apr 24th, 2014
147
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- load the API
  2. os.loadAPI("ocs/apis/sensor")
  3. -- wrap the sensor
  4. local prox = sensor.wrap("top")
  5. local ChestPos='-1,-1,1'
  6.  
  7. function CountItems()
  8. -- get the targets
  9.   local targets = prox.getTargets()
  10.   if targets[ChestPos] then
  11.     local Details = prox.getTargetDetails(ChestPos)
  12.     local n=0
  13.     for i=1,#(Details.Slots) do
  14.       n=n+Details.Slots[i].Size
  15.     end
  16.     return n
  17.   else
  18.     return 0
  19.   end
  20. end
  21.  
  22. function GiveItems(n)
  23.   local StartCount=CountItems()
  24.   if n> StartCount then n=StartCount end
  25.   local EndCount=StartCount-n
  26.   while n>0 do
  27.     rs.setOutput('left',true)
  28.     sleep(0.2)
  29.     n=CountItems()-EndCount
  30.   end
  31.   rs.setOutput('left',false)
  32. end
  33.  
  34. local numb={
  35.       [0]={0x00,0x3C,0x42,0x42,0x42,0x42,0x3C,0x00,c=colors.yellow},
  36.       [1]={0x00,0x08,0x18,0x08,0x08,0x08,0x1C,0x00,c=colors.yellow},
  37.       [2]={0x00,0x3C,0x42,0x02,0x3C,0x40,0x7E,0x00,c=colors.yellow},
  38.       [3]={0x00,0x3C,0x42,0x0C,0x02,0x42,0x3C,0x00,c=colors.yellow},
  39.       [4]={0x00,0x0C,0x14,0x24,0x44,0x7E,0x04,0x00,c=colors.yellow},
  40.       [5]={0x00,0x7E,0x40,0x7C,0x02,0x42,0x3C,0x00,c=colors.yellow},
  41.       [6]={0x00,0x3C,0x40,0x7C,0x42,0x42,0x3C,0x00,c=colors.yellow},
  42.       [7]={0x00,0x7E,0x02,0x04,0x08,0x10,0x10,0x00,c=colors.red},
  43.       [8]={0x00,0x3C,0x42,0x3C,0x42,0x42,0x3C,0x00,c=colors.yellow},
  44.       [9]={0x00,0x3C,0x42,0x42,0x3E,0x02,0x3C,0x00,c=colors.yellow}
  45.       }
  46.   numb[10]=numb[0]
  47.  
  48. wheel ={}
  49. function wheel:show()
  50.   local l,c
  51.   for i=0,7 do
  52.     term.setCursorPos(self.X,self.Y+i)
  53.     if i<self.shift then
  54.       l=numb[self.pos+1][9+i-self.shift]
  55.       c=numb[self.pos+1].c
  56.     else
  57.       l=numb[self.pos][1+i-self.shift]
  58.       c=numb[self.pos].c
  59.     end
  60.     for j=1,8 do
  61.       if bit.band(l,0x80)==0 then
  62.         term.setBackgroundColor(colors.black)
  63.       else
  64.         term.setBackgroundColor(c)
  65.       end
  66.       term.write(' ')
  67.       l=bit.blshift(l,1)
  68.     end
  69.   end
  70.   term.setBackgroundColor(colors.black)
  71. end
  72.  
  73. function wheel:rotation(_t)
  74.   self.t=_t
  75.   self.run=true
  76.   return function()
  77.     while self.run do
  78.       for i=1,8 do
  79.         sleep(self.t)
  80.         self.shift=i
  81.         if self.shift>7 then
  82.           self.shift=0
  83.           self.pos=self.pos+1
  84.         end
  85.         if self.pos>9 then self.pos=0 end
  86.         self:show()
  87.       end
  88.     end
  89.   end
  90. end
  91.  
  92. function wheel:new(x,y,n)
  93.   local obj={X = x, Y = y, run = false, pos = n, shift = 0, t = 0.1}
  94.   setmetatable(obj,self)
  95.   self.__index=self
  96.   obj:show()
  97.   return obj
  98. end
  99.  
  100. bonus={2,20,200}
  101. function printTop(p)
  102.   term.setCursorPos(1,1)
  103.   term.setTextColor(colors.yellow)
  104.   write('Bet-')
  105.   for i=1,5 do
  106.     if i==p then term.setTextColor(colors.white)
  107.     else term.setTextColor(colors.yellow) end
  108.     term.write(string.format('%5d',i))
  109.   end
  110.   print()
  111.   for i=1,3 do
  112.     term.setTextColor(colors.red)
  113.     write(7)
  114.     term.setTextColor(colors.yellow)
  115.     write('x'..i..'-')
  116.     for j=1,5 do
  117.       if j==p then term.setTextColor(colors.white)
  118.       else term.setTextColor(colors.yellow) end
  119.       term.write(string.format('%5d',bonus[i]*j))
  120.     end
  121.     print()
  122.   end
  123.   term.setTextColor(colors.white)
  124. end
  125.  
  126. --term.redirect(peripheral.wrap('right'))
  127. term.clear()
  128. A=wheel:new(3,5,7)
  129. B=wheel:new(11,5,7)
  130. C=wheel:new(19,5,7)
  131.  
  132. function button()
  133.   if rs.getInput('bottom') then return true end
  134.   sleep(0.5)
  135.   if rs.getInput('bottom') then return true end
  136.   return false
  137. end
  138.  
  139. function check()
  140.   while button() do sleep(0.5) end
  141.   sleep(3+math.random()*5)
  142.   A.run=false
  143.   sleep(1+math.random()*5)
  144.   B.run=false
  145.   sleep(1+math.random()*5)
  146.   C.run=false
  147. end
  148.  
  149. sleep(3)
  150. while true do
  151.   StartItems=CountItems()
  152.   bet=-1
  153.   repeat
  154.     Items=CountItems()-StartItems
  155.     if Items~=bet then
  156.       bet=Items
  157.       if bet>5 then GiveItems(bet-5) bet=5 end
  158.       printTop(bet)
  159.     end
  160. --    if bet<5 then printRight() end
  161.     sleep(0.2)
  162.   until button() and bet~=0
  163.   term.setCursorPos(1,12)
  164.   term.clearLine()
  165.   parallel.waitForAll(A:rotation(0.04),B:rotation(0.1),C:rotation(0.12),check)
  166.  
  167.   prize=0
  168.   if A.pos==7 then prize=prize+1 end
  169.   if B.pos==7 then prize=prize+1 end
  170.   if C.pos==7 then prize=prize+1 end
  171.   if prize>0 then
  172.     prize=bonus[prize]*bet
  173.     term.setCursorPos(1,12)
  174.     write('Win '..prize)
  175.     GiveItems(prize)
  176.   end
  177. end
RAW Paste Data