2048: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 3,885: | Line 3,885: | ||
Direction? |
Direction? |
||
</pre> |
</pre> |
||
=={{header|M2000 Interpreter}}== |
|||
<lang M2000 Interpreter> |
|||
Module Game2048 { |
|||
\\ 10% 4 and 90% 2 |
|||
Def GetTlleNumber()=If(Random(10)<2->4, 2) |
|||
\\ tile |
|||
Def Tile$(x)=If$(x=0->"[ ]", format$("[{0::-4}]", x)) |
|||
\\ empty board |
|||
BoardTileRight =lambda (x, y)->x+y*4 |
|||
BoardTileLeft=lambda (x, y)->3-x+y*4 |
|||
BoardTileUp=lambda (x, y)->x*4+y |
|||
BoardTileDown=lambda (x, y)->(3-x)*4+y |
|||
Dim Board(0 to 15) |
|||
Inventory EmptyTiles |
|||
\\ Score is a statement but we can use it as a variable too. |
|||
Score=0 |
|||
\\ Win is also a statement but we can use it as a variable too. |
|||
Win=False |
|||
'For i=0 to 15: Append EmptyTiles, i: next i |
|||
ExitNow=False |
|||
BoardDirection=BoardtileRight |
|||
Process(BoardDirection) |
|||
\\ Split Rem lines to insert start condition to check valid moves |
|||
Rem : board(0)=2 |
|||
Rem : board(1)=2, 2, 2 ' place to (1), (2), (3) |
|||
While len(EmptyTiles) { |
|||
NewTile() |
|||
DrawBoard() |
|||
Action=False |
|||
do { |
|||
a$=key$ |
|||
if len(a$)=2 then { |
|||
Action=true |
|||
Select case Asc(mid$(a$,2)) |
|||
Case 72 |
|||
BoardDirection=BoardTileUp |
|||
Case 75 |
|||
BoardDirection=BoardTileRight |
|||
Case 77 |
|||
BoardDirection=BoardTileLeft |
|||
Case 80 |
|||
BoardDirection=BoardTileDown |
|||
Case 79 ' End key |
|||
ExitNow=True |
|||
Else |
|||
Action=false |
|||
end select |
|||
} |
|||
} until Action |
|||
If ExitNow then exit |
|||
Process(BoardDirection) |
|||
} |
|||
If Win then { |
|||
Print "You Win" |
|||
} Else { |
|||
Print "You Loose" |
|||
} |
|||
End |
|||
Sub Process(Boardtile) |
|||
Inventory EmptyTiles |
|||
local what, i, j, k |
|||
For i=0 to 3 |
|||
Gravity() |
|||
k=boardtile(0,i) |
|||
For j=1 to 3 |
|||
where=boardtile(j,i) |
|||
if Board(where)<>0 then { |
|||
if board(k)=board(where) then { |
|||
board(k)*=2 : score+=board(where): board(where)=0 |
|||
if board(k)=2048 Then Win=True : ExitNow=true |
|||
} |
|||
} |
|||
k=where |
|||
Next j |
|||
Gravity() |
|||
For j=0 to 3 |
|||
where=boardtile(j,i) |
|||
if board(where)=0 then Append EmptyTiles, where |
|||
Next j |
|||
Next i |
|||
End Sub |
|||
Sub NewTile() |
|||
local m=EmptyTiles(Random(0, len(EmptyTiles)-1)!) |
|||
Board(m)=GetTlleNumber() |
|||
Delete EmptyTiles, m |
|||
End Sub |
|||
Sub DrawBoard() |
|||
Refresh 2000 |
|||
Cls |
|||
Cursor 0, 10 |
|||
Local Doc$, line$ |
|||
Document Doc$ |
|||
Doc$=Format$("Game 2048 Score {0}", score) |
|||
\\ Using Report 2 we use rendering as text, with center justify |
|||
Report 2, Doc$ |
|||
Doc$={ |
|||
} |
|||
Local i, j |
|||
For i=0 to 3 |
|||
line$="" |
|||
For j=0 to 3 |
|||
line$+=Tile$(Board(BoardTileRight(j, i))) |
|||
Next j |
|||
Print Over $(2), Line$ |
|||
Print |
|||
Doc$=Line$+{ |
|||
} |
|||
Next i |
|||
Report 2, "Next:Use Arrows | Exit: Press End" |
|||
Refresh |
|||
ClipBoard Doc$ |
|||
End Sub |
|||
Sub Gravity() |
|||
k=-1 |
|||
for j=0 to 3 { |
|||
where=boardtile(j,i) |
|||
if k=-1 then if board(where)=0 then k=j : continue |
|||
if board(where)=0 then continue |
|||
if k=-1 then continue |
|||
board(boardtile(k,i))=board(where) |
|||
board(where)=0 |
|||
k++ |
|||
} |
|||
End Sub |
|||
} |
|||
Game2048 |
|||
</lang> |
|||
Each move copied to clipboard |
|||
{{out}} |
|||
<pre> |
|||
Game 2048 Score 14 |
|||
[ 2][ 4][ 8][ 8] |
|||
[ ][ 2][ 2][ 2] |
|||
[ ][ ][ ][ ] |
|||
[ ][ ][ ][ ] |
|||
Game 2048 Score 24 |
|||
[ ][ 2][ 4][ 16] |
|||
[ ][ ][ 2][ 4] |
|||
[ ][ ][ ][ ] |
|||
[ ][ ][ 2][ ] |
|||
Game 2048 Score 26 |
|||
[ ][ ][ ][ ] |
|||
[ ][ ][ ][ ] |
|||
[ 2][ ][ 4][ 16] |
|||
[ ][ 2][ 4][ 4] |
|||
Game 2048 Score 30 |
|||
[ ][ ][ ][ ] |
|||
[ ][ ][ ][ ] |
|||
[ ][ 2][ ][ 16] |
|||
[ 2][ 2][ 8][ 4] |
|||
</pre> |
|||
=={{header|Maple}}== |
=={{header|Maple}}== |
||
This application requires a bunch of different components to properly run when being as close to the mobile game as possible. These components are: A math container for the grid, an arrow key for each direction, a restart button, a text box to display the game over/highscore/arrow key to start messages, labels for score and highscore, and textboxes for the highscore and score values. Once these are created, change the names to the ones in the main body of code, and include the proper procedures for the 4 arrows and the restart button. |
This application requires a bunch of different components to properly run when being as close to the mobile game as possible. These components are: A math container for the grid, an arrow key for each direction, a restart button, a text box to display the game over/highscore/arrow key to start messages, labels for score and highscore, and textboxes for the highscore and score values. Once these are created, change the names to the ones in the main body of code, and include the proper procedures for the 4 arrows and the restart button. |