fork download
  1. MinesweeperGame.prototype.toggleFlag = function(x, y) {
  2. if (!this.hasFlag(x, y)) {
  3. this.setFlag(x, y);
  4. } else {
  5. this.removeFlag(x, y);
  6. }
  7. };
  8.  
  9. MinesweeperGame.prototype.setFlag = function(x, y) {
  10. if (!this._isCorrectCell(x, y)) {
  11. throw new MinesweeperGameException("Некорректные координаты.");
  12. } else if (this.hasOpened(x, y) ||
  13. this._flagsCounter < MinesweeperGame.MIN_FLAGS) {
  14. return false;
  15. }
  16. this._flags.addCell(x, y);
  17. this.dispatchEvent(new GameEvent(GameEvent.CELL_CHANGED, {"x": x, "y": y}));
  18. this._flagsCounter--;
  19. this.dispatchEvent(new GameEvent(GameEvent.FLAGS_COUNTER_CHANGED));
  20. };
  21.  
  22. MinesweeperGame.prototype.removeFlag = function(x, y) {
  23. if (!this._isCorrectCell(x, y)) {
  24. throw new MinesweeperGameException("Некорректные координаты.");
  25. }else if (this.hasOpened(x, y)) {
  26. return false;
  27. } else if (!this.hasFlag(x, y)) {
  28. throw new MinesweeperGame("Флаг отсутвует.");
  29. } else if (this._flagsCounter > this._mines) {
  30. throw new MinesweeperGameException("Что-то пошло не так...");
  31. }
  32. this._flags.deleteCell(x, y);
  33. this.dispatchEvent(new GameEvent(GameEvent.CELL_CHANGED, {"x": x, "y": y}));
  34. this._flagsCounter++;
  35. this.dispatchEvent(new GameEvent(GameEvent.FLAGS_COUNTER_CHANGED));
  36. };
  37.  
  38. DomController.prototype._setEvents = function() {
  39. this._domView.addRightMouseDownToFieldListener(this.toggleFlag.bind(this));
  40. };
  41.  
Runtime error #stdin #stdout #stderr 0.02s 589312KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
/home/nB42AB/prog.js:1
(function (exports, require, module, __filename, __dirname) { MinesweeperGame.prototype.toggleFlag = function(x, y) {
                                                              ^

ReferenceError: MinesweeperGame is not defined
    at Object.<anonymous> (/home/nB42AB/prog.js:1:63)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:420:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:535:3