Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- load the API
- os.loadAPI("ocs/apis/sensor")
- -- wrap the sensor
- local prox = sensor.wrap("right")
- local ChestPos='2,0,-1'
- function CountItems()
- -- get the targets
- local targets = prox.getTargets()
- if targets[ChestPos] then
- local Details = prox.getTargetDetails(ChestPos)
- local n=0
- for i=1,#(Details.Slots) do
- n=n+Details.Slots[i].Size
- end
- return n
- else
- return 0
- end
- end
- function GiveItems(n)
- local StartCount=CountItems()
- if n> StartCount then n=StartCount end
- local EndCount=StartCount-n
- while n>0 do
- rs.setOutput('top',n>1)
- rs.setOutput('bottom',n>0)
- sleep(0.2)
- n=CountItems()-EndCount
- end
- rs.setOutput('top',false)
- rs.setOutput('bottom',false)
- end
- local numb={
- [0]={0x00,0x3C,0x42,0x42,0x42,0x42,0x3C,0x00,c=colors.yellow},
- [1]={0x00,0x08,0x18,0x08,0x08,0x08,0x1C,0x00,c=colors.yellow},
- [2]={0x00,0x3C,0x42,0x02,0x3C,0x40,0x7E,0x00,c=colors.yellow},
- [3]={0x00,0x3C,0x42,0x0C,0x02,0x42,0x3C,0x00,c=colors.yellow},
- [4]={0x00,0x0C,0x14,0x24,0x44,0x7E,0x04,0x00,c=colors.yellow},
- [5]={0x00,0x7E,0x40,0x7C,0x02,0x42,0x3C,0x00,c=colors.yellow},
- [6]={0x00,0x3C,0x40,0x7C,0x42,0x42,0x3C,0x00,c=colors.yellow},
- [7]={0x00,0x7E,0x02,0x04,0x08,0x10,0x10,0x00,c=colors.red},
- [8]={0x00,0x3C,0x42,0x3C,0x42,0x42,0x3C,0x00,c=colors.yellow},
- [9]={0x00,0x3C,0x42,0x42,0x3E,0x02,0x3C,0x00,c=colors.yellow}
- }
- numb[10]=numb[0]
- wheel ={}
- function wheel:show()
- local l,c
- for i=0,7 do
- term.setCursorPos(self.X,self.Y+i)
- if i<self.shift then
- l=numb[self.pos+1][9+i-self.shift]
- c=numb[self.pos+1].c
- else
- l=numb[self.pos][1+i-self.shift]
- c=numb[self.pos].c
- end
- for j=1,8 do
- if bit.band(l,0x80)==0 then
- term.setBackgroundColor(colors.black)
- else
- term.setBackgroundColor(c)
- end
- term.write(' ')
- l=bit.blshift(l,1)
- end
- end
- term.setBackgroundColor(colors.black)
- end
- function wheel:rotation(_t)
- self.t=_t
- self.run=true
- return function()
- while self.run do
- for i=1,8 do
- sleep(self.t)
- self.shift=i
- if self.shift>7 then
- self.shift=0
- self.pos=self.pos+1
- end
- if self.pos>9 then self.pos=0 end
- self:show()
- end
- end
- end
- end
- function wheel:new(x,y,n)
- local obj={X = x, Y = y, run = false, pos = n, shift = 0, t = 0.1}
- setmetatable(obj,self)
- self.__index=self
- obj:show()
- return obj
- end
- bonus={2,20,200}
- function printTop(p)
- term.setCursorPos(1,1)
- term.setTextColor(colors.yellow)
- write('Bet -')
- for i=1,5 do
- if i==p then term.setTextColor(colors.white)
- else term.setTextColor(colors.yellow) end
- write(string.format('%5d',i))
- end
- print()
- for i=1,3 do
- term.setTextColor(colors.red)
- write(7)
- term.setTextColor(colors.yellow)
- write('x'..i..' -')
- for j=1,5 do
- if j==p then term.setTextColor(colors.white)
- else term.setTextColor(colors.yellow) end
- write(string.format('%5d',bonus[i]*j))
- end
- print()
- end
- term.setTextColor(colors.white)
- end
- banner={'\\ /',' \\/ ',' '}
- pb=1
- function printRight()
- for i=1,12 do
- term.setCursorPos(34,i)
- if pb>3 then pb=pb-3 end
- write(banner[pb])
- pb=pb+1
- end
- pb=pb-1
- end
- term.redirect(peripheral.wrap('back'))
- term.clear()
- A=wheel:new(8,5,7)
- B=wheel:new(16,5,7)
- C=wheel:new(24,5,7)
- function button()
- if rs.getInput('left') then return true end
- sleep(0.5)
- if rs.getInput('left') then return true end
- return false
- end
- function check()
- while button() do sleep(0.5) end
- sleep(3+math.random()*5)
- A.run=false
- sleep(1+math.random()*5)
- B.run=false
- sleep(1+math.random()*5)
- C.run=false
- end
- while true do
- StartItems=CountItems()
- bet=-1
- repeat
- Items=CountItems()-StartItems
- if Items~=bet then
- bet=Items
- if bet>5 then GiveItems(bet-5) bet=5 end
- printTop(bet)
- end
- if bet<5 then printRight() end
- sleep(0.2)
- until button() and bet~=0
- term.setCursorPos(1,12)
- term.clearLine()
- parallel.waitForAll(A:rotation(0.04),B:rotation(0.1),C:rotation(0.12),check)
- prize=0
- if A.pos==7 then prize=prize+1 end
- if B.pos==7 then prize=prize+1 end
- if C.pos==7 then prize=prize+1 end
- if prize>0 then
- prize=bonus[prize]*bet
- term.setCursorPos(1,12)
- write('Win '..prize)
- GiveItems(prize)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement