「2048」Realized via HTML + CSS + JavaScript
「2048」Realized via HTML + CSS + JavaScript
https://github.com/EnderMio/2048
Intro
This project is a stage test held by our BluePrint Association to test our JavaScript level.
2048 is a classic game, which contains chess board and lots of numbers.
The codes
What I really want to talk about is the move
function, because I wrote the movement of 4 directions into 1 function.
I find the mapping from column and row to number, via function numf
, can be changed according to directions.
Just to change colunm and row of a pieceBox
when calculating its number, and let the sequence of 4 directions respectively change into 1 direction.
So that 1 algorithm in 1 function can be suitable to 4 directions.
Summary
Well, the project better my JS level to some degrees, and I am proud to finish it. But I didn’t use those magic grammars of JavaScript.
It is a shame that I failed to add some animates.And the function isOver
can be more efficient.