Advertisement
Pinkishu

Untitled

Mar 24th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.00 KB | None | 0 0
  1. -- The grid was clicked
  2. function gridClicked(x, y, b)
  3.   if ((x > 0) and (y > 0) and (x <= w) and (y <= h)) then
  4.     if b == 1 then
  5.       local sweep = {}
  6.       local swept = {}
  7.       local function isSwept(x,y)
  8.         if swept[x] == nil or swept[x][y] == nil then return false end
  9.         return true
  10.       end
  11.       local function addSweep(x,y)
  12.         table.insert(sweep,{x,y})
  13.       end
  14.       local function addSwept(x,y)
  15.         if swept[x] == nil then swept[x] = {} end
  16.         swept[x][y] = true
  17.       end
  18.  
  19.       addSweep(x,y)
  20.  
  21.       while #sweep > 0 do
  22.         local x,y = unpack(table.remove(sweep,1))
  23.         addSwept(x,y)
  24.         if devoil[x][y] == 0 then
  25.           displaySquare(x, y)
  26.           if grille[x][y] == 0 then
  27.             for u = -1, 1 do
  28.               for v = -1, 1 do
  29.                 if not isSwept(x+u,y+v) then
  30.                   addSweep(x+u,y+v,1)
  31.                 end
  32.               end
  33.             end
  34.           end
  35.         end
  36.       end
  37.     end
  38.   end
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement