Skip to content

Commit

Permalink
Description of project added
Browse files Browse the repository at this point in the history
  • Loading branch information
v-zagorovskii committed Nov 13, 2024
1 parent a541e2f commit 722d489
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 68 deletions.
79 changes: 16 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,69 +1,22 @@
# 2048 game

Hey! Are you ready for a real hard check of your JavaScript skills, ninja?
If you are still here, let's do it.
Project: 2048 Game
Description
This project is a web-based implementation of the popular 2048 game. Users can slide tiles on a grid to combine numbers, aiming to reach the 2048 tile.

In this task, you need to implement the 2048 game like in [this reference](https://play2048.co/)
Don't play for too long! We need you to write the code!
Technologies Used
JavaScript: Core game logic and interactions
SCSS: Styling and responsive design

Okay, what do we have?
1) HTML and CSS are already written. You can use it, or implement your own design if you want.
2) Base `Game` class structure is already written too. Extend it with your own methods. Obligatory methods (used in tests):
- constructor with `initialState` parameter (value is optional, defaults to the empty board)
- `getState()`
- `getScore()`
- `getStatus()`
- `moveLeft()`
- `moveRight()`
- `moveUp()`
- `moveDown()`
- `start()`
- `restart()`
How to Run Locally
Clone the Repository
git clone (https://github.com/v-zagorovskii/js_2048_game.git)
cd 2048-game
Install Dependencies (if applicable)

3) Reference.
Although this project mainly uses JavaScript and SCSS, if additional dependencies are needed, they should be installed here.
Run the Project

That's it!

Okay, okay. Also, we have some rules:
1) The game field is 4 x 4
2) Each cell can be empty or contain one of the numbers: 2, 4, 8 ... 2^n
3) The player can move cells with keyboard arrows
4) All the numbers should be moved in the selected direction until all empty cells are filled in
- 2 equal cells should be merged into a doubled number
- The merged cell can’t be merged twice during one move
5) The move is possible if at least one cell is changed after the move
6) After move 2 or 4 appears in a random empty cell. 4 probability is 10%
7) When 2048 value is displayed in any cell, win message should be shown.
8) The `game over` message should be shown if there are no more available moves.
9) Hide start message when game starts.
10) Change the `Start` button to `Restart` after the first move.
11) `Restart` button should reset the game to the initial state.
12) Increase score with each move. The score should be increased by the sum of all merged cells.
13) The game consists of 2 main parts:
- game logic written in `src/modules/Game.class.js` module that exports `Game` class
- game UI written in `src/index.html` with `main.js` script that need to use `Game` class instance

Hints:
- You have class `field-cell--%cell_value%`, for styling cell in the game.
- Use `hidden` class for hiding elements on page.
- Use `start`, `restart` classes for the main button for different styles.
- Use `field-cell--%cell_value%` class like additional class, don't replace the main class.
- Use `keydown` event and `event.key` property to handle arrow buttons presses
```js
document.addEventListener('keydown', event => console.log(event.key));
```
- Adding animation to the game is optional. It is a bit tricky, but you can try it if you want. Probably, you will need to extend the Game class with additional methods and create a separate board storage with Tile entities to operate their corresponding DOM elements' positions.
You can change the HTML/CSS layout if you need it.
![Preview](./src/images/reference.png)
## Deploy and Pull Request
1. Replace `<your_account>` with your Github username in the link
- [DEMO LINK](https://<your_account>.github.io/js_2048_game/)
2. Follow [this instructions](https://mate-academy.github.io/layout_task-guideline/)
- Run `npm run test` command to test your code;
- Run `npm run test:only -- -n` to run fast test ignoring linter;
- Run `npm run test:only -- -l` to run fast test with additional info in console ignoring linter.
Open index.html in your browser to play the game locally.

Check out the live demo.
-----> https://v-zagorovskii.github.io/js_2048_game/
9 changes: 4 additions & 5 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

// Uncomment the next lines to use your game instance in the browser
const Game = require('../modules/Game.class');
const game = new Game();

Expand All @@ -14,16 +13,16 @@ document.addEventListener('keydown', (e) => {
e.preventDefault();

switch (e.code) {
case 'ArrowLeft': // Left arrow
case 'ArrowLeft':
game.moveLeft();
break;
case 'ArrowUp': // Up arrow
case 'ArrowUp':
game.moveUp();
break;
case 'ArrowRight': // Right arrow
case 'ArrowRight':
game.moveRight();
break;
case 'ArrowDown': // Down arrow
case 'ArrowDown':
game.moveDown();
break;
default:
Expand Down

0 comments on commit 722d489

Please sign in to comment.