Skip to content

Commit

Permalink
fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
rainyear committed Jun 24, 2014
1 parent e9fa13e commit b5992d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
30 changes: 18 additions & 12 deletions Board.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ function Board( width, height )
self.map = {}
self.free = {}
self.ballSelected = nil -- which ball is selected
-- self.change = {}
self.randAdded = {}
-- self.scored = false
self.scoreLines = nil
self.scoreLines = {}

function initContainer( )
for i=1,self.SIZE do
Expand Down Expand Up @@ -55,12 +55,15 @@ function Board( width, height )
end
function self:checkClear()
print(self.scoreLines)
if not self.scoreLines then return end
for k,v in pairs(self.scoreLines) do
for _,g in pairs(v) do
self:removeBall(CCPoint(g[1], g[2]))
if #self.scoreLines == 0 then return end
for _,line in pairs(self.scoreLines) do
for k,v in pairs(line) do
for _,g in pairs(v) do
self:removeBall(CCPoint(g[1], g[2]))
end
end
end
self.scoreLines = { }
end

local function touchBall( e, x, y )
Expand All @@ -76,7 +79,7 @@ function Board( width, height )
self.ballSelected.pos = goalPos -- update ball's position
self:occupyBall(self.ballSelected) -- occupy new position

self.scoreLines = cll.find_line(goalPos, self.map, 5, samecolor_valid)
table.insert(self.scoreLines, cll.find_line(goalPos, self.map, 5, samecolor_valid))
self:moveBall(self.ballSelected, goalPos, path)

self.ballSelected = nil -- set unselected
Expand All @@ -99,11 +102,13 @@ function Board( width, height )
local pos = table.remove(self.free, randFree)

self:addBall( pos.x, pos.y, math.random(0, 4))
-- table.insert(self.change, pos)
return pos
-- table.insert(self.randAdded, pos)
end
function self:randAddThree()
for i=1,3 do
self:randAdd()
local pos = self:randAdd()
table.insert(self.scoreLines, cll.find_line(pos, self.map, 5, samecolor_valid))
end
end
function self:addBall( i, j, color)
Expand Down Expand Up @@ -158,19 +163,20 @@ function Board( width, height )
pa:addObject(ccl)

if self.scoreLines == nil then print("scorelines is nil") else print("#scorelines = ", #self.scoreLines) end
if self.scoreLines == nil or #self.scoreLines == 0 then
-- if self.scoreLines == nil or #self.scoreLines == 0 then
if #self.scoreLines == 0 then
local randomAdd = CCCallFunc:create(function() self:randAddThree() end)
pa:addObject(randomAdd)
pa:addObject(ccl)
self.scoreLines = nil
-- self.scoreLines = { }
end
-- local action = CCCardinalSplineBy:create(6, pa, 7)
-- local reverse = action:reverse()
local seq = CCSequence:create(pa)
-- local seq = CCSequence:create(pa)--, reverse)
-- ball:runAction(cb)
ball:runAction(seq)
self.scored = false
-- self.scored = false
end
function self:freeBall( ball )
self.map[ball.pos.x][ball.pos.y].ball = nil
Expand Down
2 changes: 1 addition & 1 deletion Clearline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ function find_line( pos, map, score, samecolor_valid )
table.insert(scoreLine, t)
end
end
return scoreLine
return #scoreLine > 0 and scoreLine or nil

end

0 comments on commit b5992d1

Please sign in to comment.