fork download
  1. MinesweeperGame.prototype.countMines = function() {
  2. return this._countCellsInDict(this._mines);
  3. };
  4.  
  5. MinesweeperGame.prototype.countFlags = function() {
  6. return this._countCellsInDict(this._flags);
  7. };
  8.  
  9. MinesweeperGame.prototype.countOpenCells = function() {
  10. return this._countCellsInDict(this._openCells);
  11. };
  12.  
  13. MinesweeperGame.prototype.hasMine = function(x, y) {
  14. return this._isCellInDict(x, y, this._mines);
  15. };
  16.  
  17. MinesweeperGame.prototype.hasOpened = function(x, y) {
  18. return this._isCellInDict(x, y, this._openCells);
  19. };
  20.  
  21. MinesweeperGame.prototype.hasFlag = function(x, y) {
  22. return this._isCellInDict(x, y, this._flags);
  23. };
  24.  
  25. MinesweeperGame.prototype._isCellInDict = function(x, y, dict) {
  26. if (dict[y]) {
  27. return dict[y][x];
  28. }
  29. return false;
  30. };
  31.  
  32. MinesweeperGame.prototype._countCellsInDict = function(dict) {
  33. var counter = 0;
  34. for (var y in dict) {
  35. if (!dict.hasOwnProperty(y)) continue;
  36. for (var x in dict[y]) {
  37. if (!dict[y].hasOwnProperty(x)) continue;
  38. counter++;
  39. }
  40. }
  41. return counter;
  42.  
  43. };
Runtime error #stdin #stdout #stderr 0.05s 44992KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
/home/y4eaQB/prog.js:1
(function (exports, require, module, __filename, __dirname) { MinesweeperGame.
                                                              ^
ReferenceError: MinesweeperGame is not defined
    at Object.<anonymous> (/home/y4eaQB/prog.js:1:63)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3