2048 is a popular single-player sliding block puzzle game. The objective is to slide numbered tiles on a grid to combine them and create a tile with the number 2048. This README provides an overview of the 2048 game implementation in TypeScript.
- Sliding tiles: Move tiles in four directions - up, down, left, and right.
- Combining tiles: When two tiles with the same number collide while moving, they merge into one tile with the sum of the two numbers.
- Winning condition: Achieve a tile with the number 2048 to win the game.
- Score tracking: Keep track of the current score and highest score achieved.
- New game: Start a new game anytime to reset the board and score.
- TypeScript: Programming language used to add interactivity and logic to the game.
- SCSS: Stylesheet language used for styling the game interface.
- Canvas Confetti: Library used to generate confetti effect upon winning.
-
Clone or download the repository to your local machine.
-
Open terminal and run npm install in the directory.
-
Then run "npm run dev".
-
Open the localhost link provided in the terminal.
-
Use the arrow keys to slide the tiles in the desired direction.
-
Combine tiles with the same number to create larger numbers.
-
Aim to achieve the 2048 tile to win the game.
-
Enjoy playing the 2048 game!
-
Live Demo : https://athishthayalan.github.io/2048/
- index.html: Main HTML file containing the game interface.
- style.scss: Main SCSS file that imports and compiles all other SCSS partials.
- main.ts: TypeScript file containing the logic for game operations.
- confetti: Library for generating confetti effect upon winning.
- README.md: Documentation file providing information about the 2048 game.
- Initial Setup: The game starts with two tiles randomly placed on a 4x4 grid. Each tile has a value of either 2 or 4.
- Combining Tiles: When two tiles with the same number collide while moving in a particular direction, they merge into one tile with the sum of the two numbers.
- Winning: The player wins the game when they achieve a tile with the number 2048. But can still continue to play to beat their high score.
- Score: The player's score increases with each successful combination of tiles.
- Game Over: If there are no valid moves left (i.e., no empty cells or adjacent cells with the same value), the game ends.
- Board Representation: The game board is represented as a 4x4 matrix.
- Movement: Tile movement is implemented using functions to shift and combine tiles in each direction.
- Random Tile Spawn: After each move, a new tile with either value 2 or 4 spawns randomly on an empty cell.
- Local Storage: The highest score achieved is stored in the local storage for persistence across sessions.
Enjoy playing the 2048 game!