Skip to content

Instantly share code, notes, and snippets.

@jsloat
Created April 12, 2018 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsloat/0a1d98f83dbfb2a7433e0004c617a595 to your computer and use it in GitHub Desktop.
Save jsloat/0a1d98f83dbfb2a7433e0004c617a595 to your computer and use it in GitHub Desktop.
// To play Minesweeper, we will create instances of MineSweeperGame in command line.
// For example:
// In the command line, navigate to the lib directory and run `node`
// Run `.load game.js` to load the contents of this file.
// Then create a Game instance and run commands like so:
// let game = new Game(3, 3, 3);
// game.playMove(0, 1);
// game.playMove(1, 2);
// When done run `.exit`
import {Board} from './board';
export class Game {
constructor(numberOfRows,numberOfColumns,numberOfBombs) {
this._board = new Board(numberOfRows, numberOfColumns, numberOfBombs);
}
playMove(rowIndex,columnIndex) {
this._board.flipTile(rowIndex,columnIndex);
if (this._board.playerBoard[rowIndex][columnIndex] === 'B') {
console.log('Game over, you lose! Loser!');
this._board.print();
} else if (!this._board.hasSafeTiles()) {
console.log('Holy shit, you won! Nice fucking work!');
} else {
console.log('Current board:');
this._board.print();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment