fork download
  1. function Util() {}
  2.  
  3.  
  4. Util.shuffle = function(array) {
  5. if (!Array.isArray(array)) {
  6. throw new UtilException("Аргумент не массив.");
  7. }
  8. array.sort(function() {
  9. return Math.random() - 0.5;
  10. });
  11. return array;
  12. };
  13.  
  14. function Cell(x, y) {
  15. if (typeof x != "number" || y != "number") {
  16. throw new CellException("Аргументы не являются числами.");
  17. }
  18. this.x = x;
  19. this.y = y;
  20. this.nearMines = null;
  21. this.isMine = null;
  22. }
  23.  
  24. MinesweeperGame.prototype._createMines = function(firstClickedCell) {
  25. if (this._minesNumber > this._field.length) {
  26. throw new MinesweeperGameException("Мины > клетки.");
  27. }
  28. if (!(firstClickedCell instanceof Cell)) {
  29. throw new MinesweeperGameException("Аргумент firstClickedCell не Cell.");
  30. }
  31. var fieldCopy = this._field.slice();
  32. fieldCopy = Util.shuffle(fieldCopy);
  33. for (var i = 0, counter = 0; i < fieldCopy.length; i++) {
  34. if (counter == this._minesNumber) {
  35. break;
  36. } else if (fieldCopy.x == firstClickedCell.x &&
  37. fieldCopy.y == firstClickedCell.y) {
  38. continue;
  39. }
  40. fieldCopy.isMine = true;
  41. counter++;
  42. }
  43. if (counter != this._minesNumber) {
  44. throw new MinesweeperGameException("В создании мин что-то пошло не так..");
  45. }
  46. };
  47.  
Runtime error #stdin #stdout #stderr 0.06s 51128KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
/home/BRJ3Jc/prog.js:24
MinesweeperGame.prototype._createMines = function(firstClickedCell) {
^
ReferenceError: MinesweeperGame is not defined
    at Object.<anonymous> (/home/BRJ3Jc/prog.js:24:1)
    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