Giter Club home page Giter Club logo

minesweeper's Introduction

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

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.