整理代码,删掉多个goto

This commit is contained in:
MrZ626
2021-03-25 02:15:49 +08:00
parent ea0d699e1b
commit 390d2a42b8
4 changed files with 97 additions and 105 deletions

View File

@@ -224,37 +224,36 @@ return{
else
bn=P.holdQueue[1]and P.holdQueue[1].id or P.nextQueue[1]and P.nextQueue[1].id
end
if not bn then goto continue end
if bn then
for dir=0,dirCount[bn]do--Each dir
local cb=BLOCKS[bn][dir]
for cx=1,11-#cb[1]do--Each pos
local cy=#Tfield+1
for dir=0,dirCount[bn]do--Each dir
local cb=BLOCKS[bn][dir]
for cx=1,11-#cb[1]do--Each pos
local cy=#Tfield+1
--Move to bottom
while cy>1 and not ifoverlapAI(Tfield,cb,cx,cy-1)do
cy=cy-1
end
--Move to bottom
while cy>1 and not ifoverlapAI(Tfield,cb,cx,cy-1)do
cy=cy-1
end
--Simulate lock
for i=1,#cb do
local y=cy+i-1
if not Tfield[y]then Tfield[y]=getRow(0)end
local L=Tfield[y]
for j=1,#cb[1]do
if cb[i][j]then
L[cx+j-1]=1
--Simulate lock
for i=1,#cb do
local y=cy+i-1
if not Tfield[y]then Tfield[y]=getRow(0)end
local L=Tfield[y]
for j=1,#cb[1]do
if cb[i][j]then
L[cx+j-1]=1
end
end
end
local score=getScore(Tfield,cb,cy)
if score>best.score then
best={bn=bn,x=cx,dir=dir,hold=ifhold==1,score=score}
end
resetField(field_org,Tfield,cy)
end
local score=getScore(Tfield,cb,cy)
if score>best.score then
best={bn=bn,x=cx,dir=dir,hold=ifhold==1,score=score}
end
resetField(field_org,Tfield,cy)
end
end
::continue::
end
if not best.bn then return 1 end

View File

@@ -79,14 +79,14 @@ local loadingThread=coroutine.create(function()
{"rect","fill",10,4,-2,23},
{"poly","fill",10,4,24,10,10,16.5},
{"rect","fill",4,24,10,3},
}
}YIELD()
modeIcons.tsd=DOGC{64,64,
{"rect","fill",7,7,16,16},
{"rect","fill",7,41,16,16},
{"rect","fill",41,41,16,16},
{"move",.5,.5},
{"poly","line",7,24,56,24,56,39,39,39,39,56,24,56,24,39,7,39},
}
}YIELD()
modeIcons.infinite=DOGC{64,64,
{"wid",4},
{"circ","line",32,32,28},
@@ -97,7 +97,7 @@ local loadingThread=coroutine.create(function()
{"rect","fill",7,30,4,4},
{"rect","fill",52,30,4,4},
{"rect","fill",30,52,4,4},
}
}YIELD()
modeIcons.t49=DOGC{64,64,
{"wid",2},
{"rect","line",05,05,10,20},{"rect","line",49,05,10,20},
@@ -105,7 +105,7 @@ local loadingThread=coroutine.create(function()
{"rect","line",20,10,23,43},
{"rgb",1,1,1,.7},
{"rect","fill",20,10,23,43},
}
}YIELD()
modeIcons.t99=DOGC{64,64,
{"wid",2},
{"rect","line",02,02,6,12},{"rect","line",11,02,6,12},
@@ -119,7 +119,7 @@ local loadingThread=coroutine.create(function()
{"rect","line",20,10,23,43},
{"rgb",1,1,1,.7},
{"rect","fill",20,10,23,43},
}
}YIELD()
upFloor()
for i=1,#MODES do
@@ -248,19 +248,10 @@ function scene.update(dt)
if not locked then
if progress<25 then
local p=progress
::again::
if loadingThread then
repeat
assert(coroutine.resume(loadingThread))
else
return
end
if skip>0 then
if progress==p then
goto again
else
skip=skip-1
end
end
until not loadingThread or skip<=0 or progress~=p
if skip>0 then skip=skip-1 end
else
openTime=openTime+dt
if skip>0 then

View File

@@ -194,6 +194,15 @@ local baseRankColor={
{.85,.8,.3,.3},
{.4,.7,.4,.3},
}
local function drawModeShape(M,S,drawType)
if M.shape==1 then--Rectangle
gc.rectangle(drawType,M.x-S,M.y-S,2*S,2*S)
elseif M.shape==2 then--Diamond
gc.circle(drawType,M.x,M.y,S+12,4)
elseif M.shape==3 then--Octagon
gc.circle(drawType,M.x,M.y,S+6,8)
end
end
function scene.draw()
local _
gc.push("transform")
@@ -225,22 +234,11 @@ function scene.draw()
local rank=R[name]
local S=M.size
--Frame & fill
--Draw shapes on map
gc.setColor(baseRankColor[rank])
local drawType="fill"
::again::
if M.shape==1 then--Rectangle
gc.rectangle(drawType,M.x-S,M.y-S,2*S,2*S)
elseif M.shape==2 then--Diamond
gc.circle(drawType,M.x,M.y,S+12,4)
elseif M.shape==3 then--Octagon
gc.circle(drawType,M.x,M.y,S+6,8)
end
if drawType=="fill"then
gc.setColor(1,1,sel==name and 0 or 1)
drawType="line"
goto again
end
drawModeShape(M,S,"fill")
gc.setColor(1,1,sel==name and 0 or 1)
drawModeShape(M,S,"line")
--Icon
local icon=M.icon