项目作者: victorkt

项目描述 :
A minesweeper flags game.
高级语言: JavaScript
项目地址: git://github.com/victorkt/minesweeper-flags.git
创建时间: 2015-08-03T00:47:32Z
项目社区:https://github.com/victorkt/minesweeper-flags

开源协议:MIT License

下载


Minesweeper Flags Build Status Dependency Status

A minesweeper flags game.

Installation

  1. npm install victorkohl/minesweeper-flags

Example

  1. import MinesweeperFlags from 'minesweeper-flags';
  2. let GameError = MinesweeperFlags.GameError;
  3. // creates a new Flags game
  4. let game = new MinesweeperFlags();
  5. // setup the event handlers
  6. game.on('new-game', (edge) => {
  7. console.log(`New Game (${edge}x${edge})`)
  8. });
  9. game.on('position-hit', (x, y, flagHit, flagsNearby) => {
  10. console.log(`Position Hit (${x},${y}) flagHit=${flagHit}; flagsNearby=${flagsNearby}`)
  11. });
  12. game.on('turn-changed', (playerId) => {
  13. console.log(`Turn Changed (id=${playerId})`)
  14. });
  15. game.on('points-changed', (playerId, points) => {
  16. console.log(`Points Changed (id=${playerId}, points=${points})`)
  17. });
  18. game.on('game-over', () => {
  19. console.log(`Game Over`)
  20. });
  21. // create player objects (it can be any object with an ID attribute)
  22. let player1 = { id: 1 };
  23. let player2 = { id: 2 };
  24. // add players to the game
  25. game.addPlayer(player1)
  26. .then(() => game.addPlayer(player2))
  27. // start the game with a 10x10 board
  28. .then(() => game.start(10))
  29. // hits the position 0, 0
  30. .then(() => game.hitPosition(player1, 0, 0))
  31. // catch errors that can be sent to the client
  32. .catch(GameError, console.log)
  33. // catch all other errors
  34. .catch(console.err);
  35. // A possible output:
  36. // New Game (10x10)
  37. // Turn Changed (id=1)
  38. // Position Hit (0,0) flagHit=false; flagsNearby=1
  39. // Turn Changed (id=2)

Events

The following events are emitted by MinesweeperFlags:

Event Arguments Description
new-game edge Emitted when a new game starts.
position-hit x, y, flagHit, flagsNearby Emitted when a position is hit.
points-changed playerId, points Emitted when a player’s points change.
turn-changed playerId Emitted when the turn is changed.
game-over Emitted when the game is over.

Testing

  1. npm test

License

MIT © Victor Kohl Tavares