GithubHelp home page GithubHelp logo

lanzhenw / 2048-react-redux Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lannywang009/2048-react-redux

0.0 0.0 0.0 668 KB

Using react and redux to make a 2048 game

Home Page: https://lannywang009.github.io/2048-react-redux/

HTML 2.64% CSS 6.68% JavaScript 90.68%

2048-react-redux's Introduction

2048 - React - Redux

This is a front-end project of the game 2048 (originally created by Gabriele Cirulli) using React and Redux technologies. To play my game, click here.

Live Demo

https://lannywang009.github.io/2048-react-redux/

How to play

The user will use arrowup, arrowdown, arrowright, and arrowleft to slide numbered tiles on a grid to combine them to create a tile with the number 2048. If all squares are occupied, the user loses the game.

  • For this game to be more intuitive to the user, animation and transition are necessary to indicate the movement direction and to help user identify the newly generated square at random location. My version haven't added these transitions, although I do show the keyboard movement with arrow signs above the board. I am not working on this project right now.

Techonology used

React, Redux, React-redux

Game Logic

How I break down the game logic and wrote reducer rules

Game Logic

  • Tighten rules: when a direction input is fired, there should be no empty tile in between tiles in the direction. All tiles move to that direction.

  • Movement rules: (1)movement has to be non-greedy: tiles can only merge once; (2) move direction priority: when multiple tiles can be merged, we prioritize the ones on the moving directions, so [2][2][2] (right move ->) creates [2][4].

  • Check for valid moves, if no changes (no tighten or merge) happen to tiles, it's an invalid move. Nothing changes.

  • If move is valid, check if the game is over, if it is not over, add a new [2] or [4] should be added to the empty space; if the game is over, show game end UI.

  • Win condition: 2048 is created

  • Lose condition: no empty space on board

2048-react-redux's People

Contributors

lannywang009 avatar lanzhenw avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.