Created
April 12, 2018 08:02
-
-
Save jsloat/0a1d98f83dbfb2a7433e0004c617a595 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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