const Board = require('./board');
var $ = require('jquery');
var Messages = require('./messages');
var DisplayMessages = require('./display-message');
var Levels = require('./levels');
var Score = require('./score');
var Hint = require('./next-move');

function Game(){
  this.levelIndex = 0;

  this.levelGenerator = new Levels();
  this.score = new Score();
  this.displayMessage = new DisplayMessages();
  this.messages = new Messages();

  this.initBoard();
  this.bindEvents();
}

Game.prototype.bindEvents = function() {
  this.board.element.on('click', function(){
    this.processMove();
  }.bind(this));

  var self = this;
  $('#levels').on('click', '.level', function(){
    var selectedLevel = $(this).val();
    self.levelIndex = selectedLevel - 1;
    self.initBoard();
  });

  $('.hint').on('click', function() {
    this.showHint(this.board);
  }.bind(this));
};

Game.prototype.processMove = function() {
  this.score.incrementMoves();
  this.displayMessage.showScore(this.score.points);
  this.clearHint();
  if(this.gameIsWon()) {
    this.displayGameWon();
    this.incrementLevelIndex();
    this.initBoard();
    this.setMenu();
  }
};

Game.prototype.getHint = function(board) {
  var genHint = new Hint();
  return genHint.forBoard(board);
};

Game.prototype.showHint = function(board) {
  var nextMove = this.getHint(board);
  this.hintLight = this.board.lightGrid[nextMove[0]][nextMove[1]];
  alert("Top left is (0, 0), next move is (" + nextMove[0] +
    ", " + nextMove[1] + ")");
  this.cheated = true;
  this.hintLight.flipHinted().rerender();
  this.score.cheat();
  this.displayMessage.showScore(this.score.points);
};

Game.prototype.clearHint = function() {
  if(this.cheated) {
    this.hintLight.flipHinted().rerender();
    this.cheated = false;
  }
};

Game.prototype.displayGameWon = function() {
  this.displayMessage.showTitle(this.messages.win);
  alert("You won!");
};

Game.prototype.gameIsWon = function() {
  return this.board.countLights() === 0;
};

Game.prototype.initBoard = function() {
  this.setLevel();
  this.setScore();
  this.setBoard();
  this.displayMessage.showTitle(this.messages.title);
  this.displayMessage.showScore(this.score.points);
};

Game.prototype.setMenu = function() {
  var showIndex = this.levelIndex + 1;
  $('#level').val(showIndex);
};

Game.prototype.setScore = function() {
  this.score = new Score();
};

Game.prototype.setBoard = function() {
  this.board = new Board(this.level);
};

Game.prototype.setLevel = function() {
  this.level = this.levelGenerator.list[this.levelIndex];
};

Game.prototype.incrementLevelIndex = function() {
  if ( this.levelIndex < this.levelGenerator.list.length - 1 ) {
    this.levelIndex++;
  }
};

module.exports = Game;

@@ -518,28 +518,47 @@
 ction() %7B%0A  
-this
+var self = this;%0A  self
 .board.eleme
@@ -588,20 +588,20 @@
 ()%7B%0A    
-this
+self
 .process
@@ -615,41 +615,11 @@
 %0A  %7D
-.bind(this));%0A%0A  var self = this;
+);%0A
 %0A  $
@@ -815,20 +815,20 @@
 ) %7B%0A    
-this
+self
 .showHin
@@ -829,20 +829,20 @@
 howHint(
-this
+self
 .board);
@@ -845,16 +845,20 @@
 rd);%0A  %7D
+);//
 .bind(th

Move self def to top of bindEvents, remove bind(this)