Matecho - HP 39gII
type: channel
link: https://matecho-dev.zapic.moe/tag/HP-39gII/
items: 用HP 39gII写一个简单的小游戏 (2048)

用HP 39gII写一个简单的小游戏 (2048)
type: item
date: 2020-10-04T13:04:00+00:00
description: 今天摸了一天的鱼,在计算器上写了一个小游戏.EXPORT ZM0; Flush() BEGIN BLIT_P(G0,G9); END; ClrG() BEGIN RECT_P(G9,130,5,246,121,0,3); LINE_P(G9,159,5,159,121,0); LINE_P(G9,188,5,188,121,0); LINE_P(G9,217,5,217,121,0); LINE_P(G9,130,34,246,34,0); LINE_P(G9,130,63,246,63,0); LINE_P(G9,130,92,246,92,0); RECT_P(G9,31,51,89,64,3,3); RECT_P(G9,31,81,89,94,3,3); END; DMain() BEGIN DIMGROB_P(G9,256,127); ClrG(); RECT_P(G9,30,35,90,95,0,3); RECT_P(G9,30,35,90,50,0,0); RECT_P(G9,30,65,90,80,0,0); RECT_P(G9,19,105,38,115,1,1); TEXTOUT_P("F6",G9,24,105,1,3); TEXTOUT_P("Save & Exit", G9,43,105,1 ); TEXTOUT_P("2048",G9,43,18,2,0); TEXTOUT_P("SCORE",G9,43,37,1,3); TEXTOUT_P("STEP",G9,48,67,1,3); END; DBlk(X,Y,N) BEGIN LOCAL Bc,Fc,Fx; IFTE(N<64,0,IFTE(N<1024,1,2))►Bc; IFTE(N<1024,3,0)►Fc; 101+29X►X; -24+29Y►Y; IFTE(N<10,11, IFTE(N<100,7, IFTE(N<1000,6, IFTE(N<10000,3,1) ) ) )►Fx; RECT_P(G9,X+1,Y+1,X+28,Y+28,3,Bc); TEXTOUT_P(N,G9,X+Fx, Y+IFTE(N<100,7,9), IFTE(N<100,2,1),Fc,26); END; PrB() BEGIN LOCAL E,P,L,X,Y; {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,4}►L; 0►P; 0►E; REPEAT FOR X FROM 1 TO 4 DO FOR Y FROM 1 TO 4 DO IF ZM0(X,Y)==0 THEN E+1►E; IF RANDOM(0,13)≤E THEN L(CEILING( RANDOM(1,SIZE(L)) ))►ZM0(X,Y); 1►P; BREAK; END; END; END; IF P THEN BREAK; END; END; UNTIL P OR E==0; END; MInit() BEGIN IFERR ZM0(5,4) THEN MAKEMAT(0,5,4)►ZM0; PrB(); PrB(); ELSE IF ZM0(5,3)==0 THEN MAKEMAT(0,5,4)►ZM0; PrB(); PrB(); END; END; 0►ZM0(5,3); END; CheckM() BEGIN LOCAL X,Y,M; IF ZM0(4,4)==0 THEN RETURN 1; END; FOR X FROM 1 TO 4 DO FOR Y FROM 1 TO 3 DO IF ZM0(X,Y)==0 OR ZM0(X,Y)==ZM0(X,Y+1) THEN 1►M; BREAK 2; END; END; END; IF M THEN RETURN M; END; FOR Y FROM 1 TO 4 DO FOR X FROM 1 TO 3 DO IF ZM0(X,Y)==0 OR ZM0(X,Y)==ZM0(X+1,Y) THEN 1►M; BREAK 2; END; END; END; RETURN M; END; ShowDie() BEGIN INVERT_P(G9); RECT_P(G9,82,47,172,77,2,2); RECT_P(G9,80,45,170,75,0,3); TEXTOUT_P("GAME OVER", G9,86,53,2 ); END; DrawM() BEGIN ClrG(); LOCAL X,Y; FOR X FROM 1 TO 4 DO FOR Y FROM 1 TO 4 DO ABS(ZM0(X,Y))►ZM0(X,Y); IF ZM0(X,Y)≠0 THEN DBlk(X,Y,Z…