Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local winned = false
- local time = ({...})[1] or 273
- local modemSide
- for _,side in pairs(rs.getSides()) do
- if peripheral.getType(side) == 'modem' then
- modemSide = side
- rednet.open(side)
- end
- end
- if not modemSide then
- print 'Please attach a rednet modem.'
- return
- end
- local function receive()
- while true do
- local id, msg = rednet.receive()
- if msg == '30sec_playing' then
- rednet.send(id, '30sec_playing')
- break
- end
- end
- end
- local function count()
- local colorList = {
- 'red',
- 'pink',
- 'orange',
- 'yellow',
- 'lime',
- 'green',
- 'blue',
- 'lightBlue'
- }
- term.setBackgroundColor(colors.black)
- term.clearLine()
- for i=1, time do
- local x, y = term.getCursorPos()
- local w, h = term.getSize()
- local pos = math.ceil((i/time)*w)
- local color = term.isColor()
- and colorList[math.ceil(i/time*#colorList)]
- or 'white'
- for i=1, pos do
- term.setCursorPos(i, y)
- term.setBackgroundColor(colors[color])
- write ' '
- end
- -- also send out broadcast
- -- to check for other players
- rednet.broadcast('30sec_playing')
- sleep(1)
- end
- winned = true
- end
- parallel.waitForAny(count, receive)
- rednet.close(modemSide)
- term.setBackgroundColor(colors.black)
- if winned then
- print 'Successful.'
- else
- print '\nYou lost.'
- end
Advertisement
Add Comment
Please, Sign In to add comment