Dev Vlog #9 — Added 2048 Game!
Hey everyone, welcome back to another WebOS update!
This time I made another popular game, 2048.
Some lines of code to make the tiles move and merge, like:
const moveRow = (row: number[]) => {
const filtered = row.filter((value) => value !== 0);
const result: number[] = [];
for (let i = 0; i < filtered.length; i++) {
if (filtered[i] === filtered[i + 1]) {
result.push(filtered[i] * 2);
i++;
} else {
result.push(filtered[i]);
}
}
while (result.length < 4) {
result.push(0);
}
return result;
};
I changed my mind at last to shift form minesweeper
It was pretty fun making 2048 and getting the tile movement and merging to work properly inside WebOS.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.