From d932a0a9903bde2cc12085e0ca1de310b94cd481 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Wed, 6 Oct 2021 22:27:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=A7=A3=E9=99=A4=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E5=9C=BA=E5=9C=B0=E7=BB=98=E5=88=B6=E9=AB=98?= =?UTF-8?q?=E5=BA=A6=E9=99=90=E5=88=B6=E5=90=8E=E5=87=BA=E7=8E=B0=E7=9A=84?= =?UTF-8?q?=E5=85=B6=E4=BB=96=E8=A1=8D=E7=94=9F=E9=97=AE=E9=A2=98=20?= =?UTF-8?q?=E2=80=9C=E8=87=AA=E5=AE=9A=E4=B9=89=E5=9C=BA=E5=9C=B0=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E2=80=9D=E4=BD=BF=E7=94=A8=E5=85=83=E8=A1=A8=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E8=87=AA=E5=8A=A8=E8=A1=A5=E5=85=85=E5=B0=BA=E5=AF=B8?= =?UTF-8?q?=EF=BC=88=E7=BC=96=E8=BE=91=E4=B9=8B=E5=90=8E=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E6=89=8B=E5=8A=A8=E6=B8=85=E7=A9=BA=E5=A4=9A=E4=BD=99=E7=A9=BA?= =?UTF-8?q?=E8=A1=8C=EF=BC=8C=E7=9B=AE=E5=89=8D=E4=BB=85=E4=B8=80=E5=A4=84?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- parts/data.lua | 33 ++++++++------------------------- parts/modes/custom_clear.lua | 13 +++++-------- parts/modes/custom_puzzle.lua | 4 ++-- parts/scenes/customGame.lua | 28 ++++------------------------ parts/scenes/custom_field.lua | 25 ++++++++++++++++++------- 5 files changed, 37 insertions(+), 66 deletions(-) diff --git a/parts/data.lua b/parts/data.lua index 462bdb02..d1425b56 100644 --- a/parts/data.lua +++ b/parts/data.lua @@ -60,32 +60,21 @@ function DATA.pasteSequence(str) return true end -function DATA.newBoard(f)--Generate a new board - if f then - return TABLE.shift(f) - else - local F={} - for i=1,20 do F[i]={0,0,0,0,0,0,0,0,0,0}end - return F +local fieldMeta={__index=function(self,h) + for i=#self+1,h do + self[i]={0,0,0,0,0,0,0,0,0,0} end + return self[h] +end} +function DATA.newBoard(f)--Generate a new board + return setmetatable(f and TABLE.shift(f)or{},fieldMeta) end function DATA.copyBoard(page)--Copy the [page] board local F=FIELD[page or 1] local str="" - local H=0 - - for y=20,1,-1 do - for x=1,10 do - if F[y][x]~=0 then - H=y - goto BREAK_topFound - end - end - end - ::BREAK_topFound:: --Encode field - for y=1,H do + for y=1,#F do local S="" local L=F[y] for x=1,10 do @@ -144,12 +133,6 @@ function DATA.pasteBoard(str,page)--Paste [str] data to [page] board p=p+1 end - for y=fY,20 do - for x=1,10 do - F[y][x]=0 - end - end - return true end diff --git a/parts/modes/custom_clear.lua b/parts/modes/custom_clear.lua index 35633c9f..2d91917f 100644 --- a/parts/modes/custom_clear.lua +++ b/parts/modes/custom_clear.lua @@ -4,15 +4,12 @@ return{ load=function() applyCustomGame() - for y=1,20 do - if notEmptyLine(FIELD[1][y])then - --Switch clear sprint mode on - GAME.modeEnv.dropPiece=require'parts.eventsets.checkClearBoard'.dropPiece - goto BREAK_clearMode - end + --Switch clear sprint mode on + if #FIELD[1]>0 then + GAME.modeEnv.dropPiece=require'parts.eventsets.checkClearBoard'.dropPiece + else + GAME.modeEnv.dropPiece=NULL end - GAME.modeEnv.dropPiece=NULL - ::BREAK_clearMode:: PLY.newPlayer(1) local AItype=GAME.modeEnv.opponent:sub(1,2) local AIlevel=tonumber(GAME.modeEnv.opponent:sub(-1)) diff --git a/parts/modes/custom_puzzle.lua b/parts/modes/custom_puzzle.lua index ac1fddbd..374aaf09 100644 --- a/parts/modes/custom_puzzle.lua +++ b/parts/modes/custom_puzzle.lua @@ -8,7 +8,7 @@ return{ dropPiece=function(P) local D=P.modeData local F=FIELD[D.finished+1] - for y=1,20 do + for y=1,#F do local L=P.field[y] for x=1,10 do local a,b=F[y][x],L and L[x]or 0 @@ -42,7 +42,7 @@ return{ local mark=TEXTURE.puzzleMark local F=FIELD[P.modeData.finished+1] gc_setColor(1,1,1) - for y=1,20 do for x=1,10 do + for y=1,#F do for x=1,10 do local T=F[y][x] if T~=0 then gc_draw(mark[T],30*x-30,600-30*y) diff --git a/parts/scenes/customGame.lua b/parts/scenes/customGame.lua index e016f0e0..18e3b00b 100644 --- a/parts/scenes/customGame.lua +++ b/parts/scenes/customGame.lua @@ -2,13 +2,6 @@ local gc,kb,sys=love.graphics,love.keyboard,love.system local int=math.floor local CUSTOMENV=CUSTOMENV -local function _notAir(L) - for i=1,10 do - if L[i]>0 then - return true - end - end -end local sList={ visible={"show","easy","slow","medium","fast","none"}, freshLimit={0,1,2,4,6,8,10,12,15,30,1e99}, @@ -30,22 +23,11 @@ local sList={ local scene={} local sure -local initField -local function _freshMiniFieldVisible() - initField=false - for y=1,20 do - if _notAir(FIELD[1][y])then - initField=true - return - end - end -end function scene.sceneInit() sure=0 destroyPlayers() BG.set(CUSTOMENV.bg) BGM.play(CUSTOMENV.bgm) - _freshMiniFieldVisible() end function scene.sceneBack() BGM.play() @@ -79,7 +61,7 @@ function scene.keyDown(key,isRep) end end if key=="return2"or kb.isDown("lalt","lctrl","lshift")then - if initField then + if #FIELD[1]>0 then FILE.save(CUSTOMENV,'conf/customEnv') loadGame('custom_puzzle',true) end @@ -97,7 +79,6 @@ function scene.keyDown(key,isRep) if sure>.3 then TABLE.cut(FIELD)TABLE.cut(BAG)TABLE.cut(MISSION) FIELD[1]=DATA.newBoard() - _freshMiniFieldVisible() TABLE.clear(CUSTOMENV) TABLE.complete(require"parts.customEnv0",CUSTOMENV) for _,W in next,scene.widgetList do W:reset()end @@ -135,7 +116,6 @@ function scene.keyDown(key,isRep) for i=4,#args do if args[i]:find("%S")and not DATA.pasteBoard(args[i],i-3)and i<#args then goto THROW_fail end end - _freshMiniFieldVisible() MES.new('check',text.importSuccess) do return end ::THROW_fail::MES.new('error',text.dataCorrupted) @@ -162,7 +142,7 @@ function scene.draw() end --Field content - if initField then + if #FIELD[1]>0 then gc.push('transform') gc.translate(330,240) gc.scale(.5) @@ -172,7 +152,7 @@ function scene.draw() local F=FIELD[1] local cross=TEXTURE.puzzleMark[-1] local texture=SKIN.lib[SETTING.skinSet] - for y=1,20 do for x=1,10 do + for y=1,#F do for x=1,10 do local B=F[y][x] if B>0 then gc.draw(texture[B],30*x-30,600-30*y) @@ -240,7 +220,7 @@ scene.widgetList={ WIDGET.newButton{name="copy", x=1070,y=300,w=310,h=70,color='lR',font=25,code=pressKey"cC"}, WIDGET.newButton{name="paste", x=1070,y=380,w=310,h=70,color='lB',font=25,code=pressKey"cV"}, WIDGET.newButton{name="clear", x=1070,y=460,w=310,h=70,color='lY',font=35,code=pressKey"return"}, - WIDGET.newButton{name="puzzle", x=1070,y=540,w=310,h=70,color='lM',font=35,code=pressKey"return2",hideF=function()return not initField end}, + WIDGET.newButton{name="puzzle", x=1070,y=540,w=310,h=70,color='lM',font=35,code=pressKey"return2",hideF=function()return #FIELD[1]==0 end}, WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,fText=TEXTURE.back,code=pressKey"escape"}, --Rule set diff --git a/parts/scenes/custom_field.lua b/parts/scenes/custom_field.lua index 752cba22..fc32637d 100644 --- a/parts/scenes/custom_field.lua +++ b/parts/scenes/custom_field.lua @@ -16,6 +16,12 @@ local penX,penY local demo--If show x local page +local function isEmpty(L) + for i=1,#L do + if L[i]~=0 then return end + end + return true +end local penKey={ ["1"]=1,["2"]=2,["3"]=3,["4"]=4,["5"]=5,["6"]=6,["7"]=7,["8"]=8, q=9,w=10,e=11,r=12,t=13,y=14,u=15,i=16, @@ -100,13 +106,19 @@ local function _pDraw() C=0 end + local F=FIELD[page] if C then for i=1,l do - FIELD[page][penPath[i][2]][penPath[i][1]]=C + F[penPath[i][2]][penPath[i][1]]=C end end penPath={} penMode=0 + + while #F>0 and isEmpty(F[#F])do + rem(F) + end + print(#F) end function scene.sceneInit() @@ -174,7 +186,7 @@ function scene.keyDown(key) end elseif key=="delete"then if sure>.3 then - for y=1,20 do for x=1,10 do FIELD[page][y][x]=0 end end + FIELD[page]=DATA.newBoard() sure=0 SFX.play('finesseError',.7) else @@ -187,19 +199,18 @@ function scene.keyDown(key) SFX.play('blip') elseif key=="l"then local F=FIELD[page] + local cleared=false for i=20,1,-1 do for j=1,10 do if F[i][j]<=0 then goto CONTINUE_notFull end end + cleared=true SYSFX.newShade(3,200,660-30*i,300,30) SYSFX.newRectRipple(3,200,660-30*i,300,30) rem(F,i) ::CONTINUE_notFull:: end - if #F~=20 then - repeat - F[#F+1]={0,0,0,0,0,0,0,0,0,0} - until#F==20 + if cleared then SFX.play('clear_3',.8) SFX.play('fall',.8) end @@ -279,7 +290,7 @@ function scene.draw() local cross=TEXTURE.puzzleMark[-1] local F=FIELD[page] local texture=SKIN.lib[SETTING.skinSet] - for y=1,20 do for x=1,10 do + for y=1,#F do for x=1,10 do local B=F[y][x] if B>0 then gc.draw(texture[B],30*x-30,600-30*y)