Advertisement
ZNZNCOOP

Casino2

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