Created
April 11, 2018 09:45
-
-
Save jsloat/f0cf779346013dd1b5838d764405806d 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
'use strict'; | |
Object.defineProperty(exports, "__esModule", { | |
value: true | |
}); | |
exports.Game = undefined; | |
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | |
// 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` | |
var _board = require('./board'); | |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | |
var Game = exports.Game = function () { | |
function Game(numberOfRows, numberOfColumns, numberOfBombs) { | |
_classCallCheck(this, Game); | |
this._board = new _board.Board(numberOfRows, numberOfColumns, numberOfBombs); | |
} | |
_createClass(Game, [{ | |
key: 'playMove', | |
value: function 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(); | |
} | |
} | |
}]); | |
return Game; | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment