Skip to content

The most complete minesweeper game built with React, Redux and Immutable.js.

License

Notifications You must be signed in to change notification settings

kevin940726/minesweeper

Repository files navigation

minesweeper

The most complete minesweeper game built with React, Redux and Immutable.js.

Play Now!

screenshot


Features

  • Custom game board and three different major difficulty.
  • Counting Time.
  • Mines left.
  • Set flags.
  • Quick mode and mode switch.
  • Settings save in cookie.
  • Generate non-guessing game.

How to Play

Seriously !?

Build

git clone this project, then.

cd minesweeper
npm install
npm start

Head to localhost:8000.

API

You can find the logic of the game in ./src/minesweeper.js. If you don't like the UI or you want to make a enhancement, import it to your custom UI.

import Minesweeper, { Block, BlockRecord } from './src/minesweeper.js';

Block:

An immutable Record store in each block. Check out immutable.js for methods.

const Block = Record({
    type: 'normal',
    mines: 0,
    hidden: true,
    flag: false
});

BlockRecord:

An immutable Record indicate the row and column of the block.

const BlockRecord = Record({
	row: 0,
	col: 0
});

Blocks:

An immutable Map represent the whole game board blocks, with BlockRecord as keys and Block as values.

Minesweeper():

Create the game board, load initial data. There are some game data you can get:

  • rows: (Int) Game board rows.
  • cols: (Int) Game board columns.
  • mines: (Int) Game board mines.
  • minesRemaining: (Int) How many mines left without flagged.
  • blocks: (Immutable Map) An immutable Map data for each blocks in the game board.
  • status: (String)
    • ready: Ready to play the game before first click.
    • playing: Playing the game after first click.
    • win: Clear the game board without hitting mines.
    • lose: Hit a mine.
  • timePass: (Int) Current time pass in the game.
  • mode: (String)
    • regular: Regular game mode. Single click to reveal the block, right click to set a flag.
    • quick: Quick mode. Single click to set a flag, while right click will reveal the block.
  • flagMode: (Boolean) Quick mode for the game or not.
  • checkIsSolvable: (Boolean) Generate non-guessing game or not.
const game = Minesweeper();

Minesweeper::reset(rows, cols, mines, quickMode):

Clear the game board and reset the config settings. Return blocks.

Minesweeper::init(rows, cols, mines, quickMode, exclude):

Reset and start the game. The exclude take an array of BlockRecord to exclude from being mine. Return blocks.

Minesweeper::singleClick(BlockRecord):

Perform a single click on a block. Set a flag if mode === quick, else reveal the block. Return a Promise with blocks as argument.

Minesweeper::rightClick(BlockRecord):

Perform a right click on a block. Reveal the block if mode === quick, else set a flag. Return a Promise with blocks as argument.

TODO

  • Record high score.
  • Cleverly first click init.
  • Mobile friendly.
  • Game solver (hard, for non-guessing game).
  • Completely switch to Immutable.js.
  • Increase solver speed.
  • Cover up loading screen.
  • Write some tests.
  • Generate hints by solver.

Contribute

Issues, PRs, and all the advise and discussion are very welcome!

Special Thanks

License

MIT

About

The most complete minesweeper game built with React, Redux and Immutable.js.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published