This commit is contained in:
MrZ626
2020-08-29 22:59:24 +08:00
parent e370cc42ec
commit edfe100027
5 changed files with 235 additions and 2 deletions

View File

@@ -204,9 +204,13 @@ function keyDown.calculator(k)
elseif S.val==114514 then
S.reg=1919810
S.val=114514
elseif S.val==1145141919810 then
error("小鬼自裁请")
elseif S.val==123456789 then
S.reg=123456789
S.val=987654321
elseif S.val==152435 or S.val==81524 then
SCN.go("p15")
end
end
elseif k=="escape"then
@@ -218,6 +222,133 @@ function keyDown.calculator(k)
end
end
local function moveU(S,b,x,y)
if y<4 then
b[y][x],b[y+1][x]=b[y+1][x],b[y][x]
S.y=y+1
end
end
local function moveD(S,b,x,y)
if y>1 then
b[y][x],b[y-1][x]=b[y-1][x],b[y][x]
S.y=y-1
end
end
local function moveL(S,b,x,y)
if x<4 then
b[y][x],b[y][x+1]=b[y][x+1],b[y][x]
S.x=x+1
end
end
local function moveR(S,b,x,y)
if x>1 then
b[y][x],b[y][x-1]=b[y][x-1],b[y][x]
S.x=x-1
end
end
local function shuffleBoard(S,b)
for i=1,300 do
i=rnd()
if i<.25 then moveU(S,b,S.x,S.y)
elseif i<.5 then moveD(S,b,S.x,S.y)
elseif i<.75 then moveL(S,b,S.x,S.y)
else moveR(S,b,S.x,S.y)
end
end
end
local function checkBoard(b)
for i=4,1,-1 do
for j=1,4 do
if b[i][j]~=4*i+j-4 then return false end
end
end
return true
end
local function tapBoard(x,y,key)
local S=sceneTemp
if S.state<2 then
if not key then
sysFX.newRipple(.2,x,y,13)
x,y=int((x-320)/160)+1,int((y-40)/160)+1
end
local b=S.board
local moves=0
if S.x==x then
if y>S.y and y<5 then
for i=S.y,y-1 do
moveU(S,b,x,i)
moves=moves+1
end
elseif y<S.y and y>0 then
for i=S.y,y+1,-1 do
moveD(S,b,x,i)
moves=moves+1
end
end
elseif S.y==y then
if x>S.x and x<5 then
for i=S.x,x-1 do
moveL(S,b,i,y)
moves=moves+1
end
elseif x<S.x and x>0 then
for i=S.x,x+1,-1 do
moveR(S,b,i,y)
moves=moves+1
end
end
end
if moves>0 then
SFX.play("move")
S.move=S.move+moves
if S.state==0 then
S.state=1
S.startTime=Timer()
end
if checkBoard(b)then
S.state=2
S.time=Timer()-S.startTime
SFX.play("win")
end
end
end
end
function keyDown.p15(k)
local S=sceneTemp
local b=S.board
if k=="up"then
tapBoard(S.x,S.y+1,true)
elseif k=="down"then
tapBoard(S.x,S.y-1,true)
elseif k=="left"then
tapBoard(S.x+1,S.y,true)
elseif k=="right"then
tapBoard(S.x-1,S.y,true)
elseif k=="space"then
shuffleBoard(S,b)
S.state=0
S.time=0
S.move=0
elseif S.state==0 then
if k=="c"then
S.color=not S.color
elseif k=="h"then
S.blind=not S.blind
end
end
end
function mouseDown.p15(x,y,k)
tapBoard(x,y)
end
function mouseMove.p15(x,y)
tapBoard(x,y)
end
function touchDown.p15(id,x,y)
tapBoard(x,y)
end
function touchMove.p15(id,x,y,dx,dy)
tapBoard(x,y)
end
function keyDown.load(k)
if k=="a"then

View File

@@ -198,6 +198,11 @@ local langList={
["/"]="/",
play="开始",
},
p15={
reset="重新开始",
color="颜色",
hide="",
},
main={
play="开始",
setting="设置",
@@ -669,6 +674,11 @@ local langList={
["/"]="/",
play="开始",
},
p15={
reset="重新开始",
color="颜色",
hide="",
},
main={
play="开始",
setting="设置",
@@ -1130,6 +1140,11 @@ local langList={
["/"]="/",
play="Play",
},
p15={
reset="Reset",
color="Color",
hide="Blind",
},
main={
play="Play",
setting="Settings",
@@ -1589,6 +1604,11 @@ local langList={
["/"]="/",
play="!!!",
},
p15={
reset="Reset",
color="Color",
hide="Blind",
},
main={
play="!!!",
setting="_?_",
@@ -2062,6 +2082,11 @@ local langList={
["/"]="/",
play="开始",
},
p15={
reset="Reset",
color="",
hide="",
},
main={
play="开始",
setting="设置",

View File

@@ -105,6 +105,65 @@ function Pnt.calculator()
if S.sym then setFont(50)gc.print(S.sym,126,150)end
if S.pass then setFont(40)mStr(S.tip,640,10)end
end
local cellColor={
color.lRed,color.lRed,color.lRed,color.lRed,
color.lBlue,color.lGreen,color.lGreen,color.lGreen,
color.lBlue,color.lYellow,color.lPurple,color.lPurple,
color.lBlue,color.lYellow,color.lPurple,color.lPurple,
}
local backColor={
color.dRed,color.dRed,color.dRed,color.dRed,
color.dBlue,color.dGreen,color.dGreen,color.dGreen,
color.dBlue,color.dYellow,color.dPurple,color.dPurple,
color.dBlue,color.dYellow,color.dPurple,color.dPurple,
}
function Pnt.p15()
local S=sceneTemp
setFont(40)
gc.print(format("%.3f",S.time),1000,50)
gc.print(S.move,1000,100)
if S.state==1 then gc.setColor(.9,.9,.9) --game
elseif S.state==0 then gc.setColor(.2,.8,.2)--ready
elseif S.state==2 then gc.setColor(.9,.9,0) --win
end
gc.setLineWidth(10)
gc.rectangle("line",313,33,654,654,18)
gc.setLineWidth(4)
local x,y=S.x,S.y
setFont(80)
for i=1,4 do
for j=1,4 do
if x~=j or y~=i then
local N=S.board[i][j]
if S.color and not(S.blind and S.state==1)then
gc.setColor(backColor[N])
gc.rectangle("fill",j*160+163,i*160-117,154,154,8)
gc.setColor(cellColor[N])
gc.rectangle("line",j*160+163,i*160-117,154,154,8)
else
gc.setColor(.3,.3,.3)
gc.rectangle("fill",j*160+163,i*160-117,154,154,8)
gc.setColor(1,1,1)
gc.rectangle("line",j*160+163,i*160-117,154,154,8)
end
if not(S.blind and S.state==1)then
gc.setColor(.1,.1,.1)
mStr(N,j*160+240,i*160-96)
mStr(N,j*160+242,i*160-98)
gc.setColor(1,1,1)
mStr(N,j*160+243,i*160-95)
end
end
end
end
gc.setColor(.3,.3,.3)
gc.setLineWidth(10)
gc.rectangle("line",x*160+173,y*160-107,134,134,50)
end
function Pnt.load()
local S=sceneTemp
gc.setLineWidth(4)

View File

@@ -16,6 +16,19 @@ function sceneInit.calculator()
tip=require("parts/getTip"),
}
end
function sceneInit.p15()
sceneTemp={
board={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}},
x=4,y=4,
startTime=0,
time=0,
move=0,
state=2,
color=true,
blind=false,
}
end
function sceneInit.load()
sceneTemp={
phase=1,--Loading stage

View File

@@ -118,6 +118,11 @@ local Widgets={
newKey({name="/", x=450,y=600,w=90, color="lBlue", font=50,code=pressKey("/")}),
newButton({name="play", x=640,y=600,w=180,h=90, color="lGreen", font=40,code=pressKey("space"),hide=function()return not sceneTemp.pass end}),
},
p15={
newButton({name="reset", x=160,y=100,w=180,h=100,color="white", font=40,code=pressKey("space")}),
newSwitch({name="color", x=200,y=240,w=60, color="white", font=40,disp=function()return sceneTemp.color end,code=pressKey("c"),hide=function()return sceneTemp.state>0 end}),
newSwitch({name="hide", x=200,y=340,w=60, color="white", font=40,disp=function()return sceneTemp.blind end,code=pressKey("h"),hide=function()return sceneTemp.state>0 end}),
},
main={
newButton({name="play", x=150,y=280,w=200,h=160,color="lRed", font=55,code=function()SCN.go("mode")end}),
newButton({name="setting", x=370,y=280,w=200,h=160,color="lBlue", font=45,code=function()SCN.go("setting_game")end}),
@@ -470,8 +475,8 @@ local Widgets={
newButton({name="back", x=1160, y=630,w=150,h=80,color="white",font=40,code=BACK}),
},
history={
newKey({name="prev", x=1155, y=170,w=180,h=180,color="white",font=65,code=pressKey("up"),hide=function()return sceneTemp.pos==1 end}),
newKey({name="next", x=1155, y=400,w=180,h=180,color="white",font=65,code=pressKey("down"),hide=function()return sceneTemp.pos==#sceneTemp.text end}),
newKey({name="prev", x=1155, y=170,w=180, color="white",font=65,code=pressKey("up"),hide=function()return sceneTemp.pos==1 end}),
newKey({name="next", x=1155, y=400,w=180, color="white",font=65,code=pressKey("down"),hide=function()return sceneTemp.pos==#sceneTemp.text end}),
newButton({name="back", x=1155, y=600,w=180,h=90,color="white",font=40,code=BACK}),
},
stat={