rdrey / reasonreact-mines

(WIP) A simple minesweeper clone written in ReasonML with ReasonReact

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ReasonReact Minesweeper

This is a simple Minesweeper game I'm making while roughly following along a ReasonReact tutorial. It's still very much WIP (I'm learning ReasonML & ReasonReact) and I don't recommend you copy any of my mistakes. I'll later use this to seek feedback/reviews from more experienced Reason devs.

This basic version of Minesweeper now "works" at ~320 Lines of Code (wow, such compact, much expressive!), but still needs to be refactored a little.

TODO

  • (Game) Better CSS / normalize
  • (Meta) Modularize code properly
  • (Meta) Probably make the Board module a stateful react component handling its own events
  • (Meta) Reduce the number of mutable fields/properties in the grid
  • (Game) Add "shortcut" move to reveal neighbours if a numbered cell is surrounded by the correct number of flags. (+45 LoC)

Run Project

npm install
npm start
# in another tab
npm run webpack

After you see the webpack compilation succeed (the npm run webpack step), open up build/index.html (no server needed!). Then modify whichever .re file in src and refresh the page to see the changes.

For more elaborate ReasonReact examples, please see https://github.com/reasonml-community/reason-react-example

Run Project with Server

To run with the webpack development server run npm run server and view in the browser at http://localhost:8000. Running in this environment provides hot reloading and support for routing; just edit and save the file and the browser will automatically refresh.

Note that any hot reload on a route will fall back to the root (/), so ReasonReact.Router.dangerouslyGetInitialUrl will likely be needed alongside the ReasonReact.Router.watchUrl logic to handle routing correctly on hot reload refreshes or simply opening the app at a URL that is not the root.

To use a port other than 8000 set the PORT environment variable (PORT=8080 npm run server).

Build for Production

npm run build
npm run webpack:production

This will replace the development artifact build/Index.js for an optimized version as well as copy src/index.html into build/. You can then deploy the contents of the build directory (index.html and Index.js).

If you make use of routing (via ReasonReact.Router or similar logic) ensure that server-side routing handles your routes or that 404's are directed back to index.html (which is how the dev server is set up).

To enable dead code elimination, change bsconfig.json's package-specs module from "commonjs" to "es6". Then re-run the above 2 commands. This will allow Webpack to remove unused code.

About

(WIP) A simple minesweeper clone written in ReasonML with ReasonReact


Languages

Language:Reason 87.9%Language:JavaScript 6.9%Language:C++ 3.0%Language:HTML 2.2%