Coder Social home page Coder Social logo

minesweeper's Introduction

Minesweeper built with React, initialized with https://github.com/facebookincubator/create-react-app

See it live at: https://cscanlin.github.io/minesweeper/

To Run

git clone https://github.com/cscanlin/minesweeper.git
cd minesweeper
npm install
npm start

This project is divided into 6 components:

  • Game
    • Header
    • Grid
      • Cell
    • Options
      • OptionField

All of the state lives at the top level Game component. I decided not to use any kind of flux architecture for this app because it felt a little overkill, and holding the state in on component serves a similar enough purpose.

For the grid, I to only have one layer of sub-component (Cell) and skip any kind of row component layer. The cellData is a flat array of objects with each Cell having a set of x,y coordinates and some other data. Having x,y coordinates is convenient because it allows us to ignore array ordering if desired. As a side note, none of my code so far actually changes the initial array ordering, so I do have a function to perform a fast index lookup calculation ((numRows * y) + (x)). In most places, I elected to go with a slightly safer API that searches the array by coordinates, even at the cost of some speed.

Another important choice made is the that numAdjacent is set on each mine directly after the initial cell/mine data are planted. By calculating at the beginning, we can use the fast lookup mentioned above with full safety. It also marginally improves the responsiveness of each click, at the cost of a small initial delay.

The final major choice was the exploration algorithm that recursively calls itself on each surrounding cell when a blank cell is clicked.

The only major thing that I didn't have time to write is any tests, besides the default. I'm planning to spend some time tomorrow (Monday) getting at least some basic tests written.

Please let me know if you have any questions or issues running it!

minesweeper's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

mattdisipio

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.