HP Prime для всех

English  Русский 
2048 games-app screenshot}}
Название 2048
Описание The game of 2048. Keyboard input only, no touch screen support.
Автор Francois Lanciault.

Исходный код (скачать):

Исходный код отформатирован программными средствами сайта

ADD_NUMBER(); SLEFTRIGHT(); SUPDOWN(); DRAW_BOARD(); CHECK_GAME_OVER(); //global_variables SCORE; NUMT; MOVED; AA; CC; DD; EXPORT HP_2048() BEGIN LOCAL W, R, C; CHOOSE(C, "▉ 2048 ▉", "New Game", "Resume Game"); RECT(RGB(255, 0, 0)); RECT_P(319-240, 0, 319, 240, RGB(200, 200, 255)); TEXTOUT_P(2048, 10, 4, 7, RGB(255, 255, 0), 100); TEXTOUT_P("SCORE", 10, 40, 4, RGB(255, 255, 255), 100); IF C == 1 THEN 0▶SCORE; 0▶NUMT; MAKEMAT(0, 4, 4)▶M1; DRAW_BOARD(); ADD_NUMBER()▶W; ADD_NUMBER()▶W; ELSE S▶SCORE; N▶NUMT; DRAW_BOARD(); END; REPEAT 0▶MOVED; WAIT()▶R; CASE IF R == 7 THEN 2▶AA; 4▶CC; −1▶DD; SLEFTRIGHT(); END; IF R == 8 THEN 3▶AA; 1▶CC; 1▶DD; SLEFTRIGHT(); END; IF R == 2 THEN 2▶AA; 4▶CC; −1▶DD; SUPDOWN(); END; IF R == 12 THEN 3▶AA; 1▶CC; 1▶DD; SUPDOWN(); END; IF R == 4 THEN NUMT▶N; SCORE▶S; RETURN "Game Saved"; END; END; IF MOVED == 0 THEN CONTINUE; END; DRAW_BOARD(); ADD_NUMBER()▶W; UNTIL W == 16 AND CHECK_GAME_OVER() == 1; TEXTOUT_P("Game", 10, 90, 5, RGB(255, 255, 225), 100); TEXTOUT_P("Over", 10, 110, 5, RGB(255, 255, 225), 100); FREEZE; END; SLEFTRIGHT() BEGIN LOCAL X, Y, V, DEST, DX; FOR Y FROM 1 TO 4 DO AA+DD▶X; REPEAT X−DD▶X; M1(Y, X)▶V; IF V ≠ 0 THEN X+DD▶DX; REPEAT M1(Y, DX)▶DEST; IF DEST ≠ 0 OR DX == AA+DD THEN BREAK; END; DX+DD▶DX; 1▶MOVED; UNTIL 1 == 2; CASE IF DEST == 0 THEN V▶M1(Y, DX); 0▶M1(Y, X); 1▶MOVED; END; IF DEST == V THEN2*V▶M1(Y, DX); 0▶M1(Y, X); SCORE+2*V▶SCORE; NUMT-1▶NUMT; 1▶MOVED; END; DEFAULT 0▶M1(Y, X); V▶M1(Y, DX-DD); END; END; UNTIL X == CC; FOR X FROM 1 TO 4 DO ABS(M1(Y, X))▶M1(Y, X); END; END; //End For Y END; //End Fonction SUPDOWN() BEGIN LOCAL X, Y, V, DEST, DY; FOR X FROM 1 TO 4 DO AA+DD▶Y; REPEAT Y−DD▶Y; M1(Y, X)▶V; IF V ≠ 0 THEN Y+DD▶DY; REPEAT M1(DY, X)▶DEST; IF DEST ≠ 0 OR DY == AA+DD THEN BREAK; END; DY+DD▶DY; 1▶MOVED; UNTIL 1 == 2; CASE IF DEST == 0 THEN V▶M1(DY, X); 0▶M1(Y, X); 1▶MOVED; END; IF DEST == V THEN2*V▶M1(DY, X); 0▶M1(Y, X); SCORE+2*V▶SCORE; NUMT-1▶NUMT; 1▶MOVED; END; DEFAULT 0▶M1(Y, X); V▶M1(DY-DD, X); END; END; UNTIL Y == CC; FOR Y FROM 1 TO 4 DO ABS(M1(Y, X))▶M1(Y, X); END; END; //End For X END; //End Fonction DRAW_BOARD() BEGIN LOCAL X, Y, PAPER, V; FOR Y FROM 1 TO 4 DO FOR X FROM 1 TO 4 DO M1(Y, X)▶V; IF V ≠ 0 THEN 255-LN((V+2)^25)▶PAPER; ELSE 255▶PAPER; END; RECT_P(319-240 + (X-1) * 60+2, (Y-1) * 60+2, 319-240 + (X-1) * 60+58, (Y-1) * 60+58, RGB(PAPER, PAPER, 255)); IF V ≠ 0 THEN TEXTOUT_P(V, 319-240 + (X-1) * 60+25-IP(LOG(V+.1)) * 6, (Y-1) * 60+19, 6, RGB(240, 0, 0), 100); END; END; END; TEXTOUT_P(SCORE, 10, 60, 3, RGB(255, 255, 255), 118, RGB(255, 0, 0)); END; CHECK_GAME_OVER() BEGIN LOCAL G_O, I, J; 1▶G_O; FOR J FROM 1 TO 4 DO FOR I FROM 1 TO 3 DO IF M1(J, I) == M1(J, I+1) THEN 0▶G_O; END; END; END; FOR I FROM 1 TO 4 DO FOR J FROM 1 TO 3 DO IF M1(J, I) == M1(J+1, I) THEN 0▶G_O; END; END; END; RETURN G_O; END; ADD_NUMBER() BEGIN LOCAL X, Y, PAPER, V; REPEAT RANDINT(1, 4)▶X; RANDINT(1, 4)▶Y; UNTIL M1(Y, X) == 0; NUMT+1▶NUMT; 2 * (RANDOM() > .9) + 2▶V; V▶M1(Y, X); 255-LN((V+2)^25)▶PAPER; FOR I FROM 1 TO 3 DO RECT_P(319-240 + (X-1) * 60+2, (Y-1) * 60+2, 319-240 + (X-1) * 60+58, (Y-1) * 60+58, RGB(0, 0, 0)); WAIT(3/50); RECT_P(319-240 + (X-1) * 60+2, (Y-1) * 60+2, 319-240 + (X-1) * 60+58, (Y-1) * 60+58, RGB(PAPER, PAPER, 255)); IF V ≠ 0 THEN TEXTOUT_P(V, 319-240 + (X-1) * 60+25-IP(LOG(V+.1)) * 6, (Y-1) * 60+19, 6, RGB(240, 0, 0), 100); END; WAIT(3/50); END; RETURN NUMT; END;

Комментарии