en / es / ca / de

2048 Game

2048 is a single player sliding block game, originally designed by Gabriele Cirulli. The goal of the game is to slide numbered blocks on a grid to combine them, adding up their values until you get a single one with the number 2048.

Source code

Features

  • Two blocks with a value of 2 or 4 are initially generated randomly.
  • There's a better chance of a 2 than a 4.
  • The game is played with the arrows on the keyboard, which indicate the direction where blocks will join.
  • If two equal numbers match when sliding, they will be added together to form a single block with twice the value.
  • Every time you make a move, a new random block will appear.
  • The game ends when 2048 is achieved or no space is left.

What I learned

  • How to understand the logic and dynamics behind the game.
  • How to develop logic with JavaScript classes and prototypes.
  • How to separate the game logic from the DOM logic.
  • How to dynamically create HTML elements and classes.

Technologies

  • Front-end: JavaScript (ES6), HTML, CSS
  • Back-end: -