Kingdaro

4min33sec

Dec 6th, 2012
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. local winned = false
  2. local time = ({...})[1] or 273
  3.  
  4. local modemSide
  5. for _,side in pairs(rs.getSides()) do
  6.   if peripheral.getType(side) == 'modem' then
  7.     modemSide = side
  8.     rednet.open(side)
  9.   end
  10. end
  11.  
  12. if not modemSide then
  13.   print 'Please attach a rednet modem.'
  14.   return
  15. end
  16.  
  17. local function receive()
  18.   while true do
  19.     local id, msg = rednet.receive()
  20.     if msg == '30sec_playing' then
  21.       rednet.send(id, '30sec_playing')
  22.       break
  23.     end
  24.   end
  25. end
  26.  
  27. local function count()
  28.   local colorList = {
  29.     'red',
  30.     'pink',
  31.     'orange',
  32.     'yellow',
  33.     'lime',
  34.     'green',
  35.     'blue',
  36.     'lightBlue'
  37.   }
  38.  
  39.   term.setBackgroundColor(colors.black)
  40.   term.clearLine()
  41.   for i=1, time do
  42.     local x, y = term.getCursorPos()
  43.     local w, h = term.getSize()
  44.     local pos = math.ceil((i/time)*w)
  45.     local color = term.isColor()
  46.     and colorList[math.ceil(i/time*#colorList)]
  47.     or 'white'
  48.    
  49.     for i=1, pos do
  50.       term.setCursorPos(i, y)
  51.       term.setBackgroundColor(colors[color])
  52.       write ' '
  53.     end
  54.    
  55.     -- also send out broadcast
  56.     -- to check for other players
  57.     rednet.broadcast('30sec_playing')
  58.    
  59.     sleep(1)
  60.   end
  61.   winned = true
  62. end
  63.  
  64. parallel.waitForAny(count, receive)
  65.  
  66. rednet.close(modemSide)
  67.  
  68. term.setBackgroundColor(colors.black)
  69. if winned then
  70.   print 'Successful.'
  71. else
  72.   print '\nYou lost.'
  73. end
Advertisement
Add Comment
Please, Sign In to add comment