DEV Community

Discussion on: 2048 game using react

Collapse
 
stillupgrade profile image
StillUpgrade • Edited

Hey, nice work! I really like the integration.
Congratz ;)

If you want some advice:

  • In your UI you should integrate the 4 keyboard arrow, to let the user know he has to use the keyboard navigation keys to play (in case he doesn't know :) ) and let him play with mouse if he wants to.

  • In your code, your methods 'swipeLeft' / 'swipeX'.. have some common parts, you should factorize per example the win check & history update
    Exemple block (first line) that can be factorized :

if (JSON.stringify(oldGrid) !== JSON.stringify(newArray)) {

You may also try to comment/name more efficiently your code (commenting Redo on top of onClickRedo is not very useful, constant a, b and c are not meaningful and need documentation to understand better) I found this link interesting about this concept here, but there are plenty others on the net . The global idea is: let the code speak by itself. If your naming is good, it will not need to be commented because it's readability is going to be excellent.

Collapse
 
itsmeab profile image
Abhilash Sadasivan Sakunthala

Thank you very much for your advice. I will keep this in mind and try to modify it.