-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
38 lines (37 loc) · 1.37 KB
/
game.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// 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`
/**
* Game class that will create a playerBoard for the player move
* and a bombBoard of the same size that will contain the randomly generated
* bombs
* @param {int} numberOfRows number of rows for the board
* @param {int} numberOfColumns number of columns for the board
* @param {int} numberOfBombs number of bomb to put on the board
*/
import { Board } from './board';
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');
this._board.print();
} else {
if (!this._board.hasSafeTiles) {
console.log('You Win!');
} else {
console.log('Current Board:');
this._board.print();
}
}
}
}