<commit_before>'use strict';
import $ from 'jQuery';
import Grid from './grid';
import Level from './level';
let classToggler = require('./helpers.js');
const events = require('events');
const gameLifeCycle = new events.EventEmitter();

export default class Game {
  constructor(columns, rows) {
    this.currentLevel = 1;
    this.levelData = new Level(this.currentLevel).data; //sets level of rows and columns
    this.grid = new Grid({columns: this.levelData.columns, rows: this.levelData.rows});
    this.lives = this.resetLives();
    this.interval = null;
    this.clicks = 0;
  }

  resetLives(){ //creates the number of lives for user
    return [ "troll1", "troll2", "troll3" ];
  }

  callbackToChangeClickState(e, game){
    let el = e.target;
    game.clicks++;
      console.log('number of clicks' + ' = ' + game.clicks);
    classToggler(el, game, gameLifeCycle);
  }

  setupEvents(callback){
    let self = this;
    $('.game-table').on('click', 'td', function(e){
      return callback(e, self);
    });
    gameLifeCycle.on("end-game", function(outcome) {
      console.log(outcome);
      self.handleOutcome(outcome);
      self.restart();
    });
  }

  handleOutcome(outcome) {
    if (outcome === "win") {
      this.currentLevel++;
      $('#winGameModal').show();
    } else {
      $('#loseGameModal').show();
      this.playAgain();
    }
    console.log("this.currentLevel = " + this.currentLevel);
  }

    playAgain(){ // allows user to start game/level over with full life
      this.lives = this.resetLives();
      if (confirm("Well, you managed to loose.... Wanna try again?") === true) {
          //do nothing stay on currentLevel
      }
      else {
          this.currentLevel = 1;
      }
    }

  start(levelData=null){
    this.grid.buildGrid(levelData);//starts off a null then changes based on level
    this.interval = setInterval(this._assignClasses(), 500);
    this.setupEvents(this.callbackToChangeClickState);
  }

  restart() {
    this.end();
    this.start(this.levelData);
  }

  end() {
    clearInterval(this.interval);
    this.clicks = 0 //resets number of clicks to 0
    this.clearEvents();//*** > clearEvents including on-end
    this.levelData = new Level(this.currentLevel).data;
    $('.game-table').remove();
  }

  clearEvents() {
    gameLifeCycle.removeAllListeners('end-game');
  }

  isInvalidClick(el) {
    return this.levelData.invalidclicks.includes(el.className);
  }

  _assignClasses() {
    let grid = this.grid;
    return function() {
      var number = Math.floor((Math.random() * 7)); // 7 represents all available colors in main.css
      var cell = grid.cellArray[Math.floor(Math.random() * grid.cellArray.length)];
      var id = cell.id;
      var colors = "highlighted" + "-" + number;
      $("td" +"#" + id).attr('class', colors);
      console.log("going");
    };
  }
}


module.exports = Game;
<commit_msg>have score tracker<commit_after>'use strict';
import $ from 'jQuery';
import Grid from './grid';
import Level from './level';
let classToggler = require('./helpers.js');
const events = require('events');
const gameLifeCycle = new events.EventEmitter();

export default class Game {
  constructor(columns, rows) {
    this.currentLevel = 1;
    this.levelData = new Level(this.currentLevel).data; //sets level of rows and columns
    this.grid = new Grid({columns: this.levelData.columns, rows: this.levelData.rows});
    this.lives = this.resetLives();
    this.interval = null;
    this.clicks = 0;
  }

  scoreTracker(game){
    console.log('number of clicks' + ' = ' + game.clicks);
      return game.clicks ++;
  }

  resetLives(){ //creates the number of lives for user
    return [ "troll1", "troll2", "troll3" ];
  }

  callbackToChangeClickState(e, game){
    let el = e.target;
    game.scoreTracker(game);
    classToggler(el, game, gameLifeCycle);
  }

  setupEvents(callback){
    let self = this;
    $('.game-table').on('click', 'td', function(e){
      return callback(e, self);
    });
    gameLifeCycle.on("end-game", function(outcome) {
      console.log(outcome);
      self.handleOutcome(outcome);
      self.restart();
    });
  }

  handleOutcome(outcome) {
    if (outcome === "win") {
      this.currentLevel++;
      $('#winGameModal').show();
    } else {
      $('#loseGameModal').show();
      this.playAgain();
    }
    console.log("this.currentLevel = " + this.currentLevel);
  }

    playAgain(){ // allows user to start game/level over with full life
      this.lives = this.resetLives();
      if (confirm("Well, you managed to loose.... Wanna try again?") === true) {
          //do nothing stay on currentLevel
      }
      else {
          this.currentLevel = 1;
      }
    }

  start(levelData=null){
    this.grid.buildGrid(levelData);//starts off a null then changes based on level
    this.interval = setInterval(this._assignClasses(), 500);
    this.setupEvents(this.callbackToChangeClickState);
  }

  restart() {
    this.end();
    this.start(this.levelData);
  }

  end() {
    clearInterval(this.interval);
    this.clicks = 0; //resets number of clicks to 0
    this.clearEvents();//*** > clearEvents including on-end
    this.levelData = new Level(this.currentLevel).data;
    $('.game-table').remove();
  }

  clearEvents() {
    gameLifeCycle.removeAllListeners('end-game');
  }

  isInvalidClick(el) {
    return this.levelData.invalidclicks.includes(el.className);
  }

  _assignClasses() {
    let grid = this.grid;
    return function() {
      var number = Math.floor((Math.random() * 7)); // 7 represents all available colors in main.css
      var cell = grid.cellArray[Math.floor(Math.random() * grid.cellArray.length)];
      var id = cell.id;
      var colors = "highlighted" + "-" + number;
      $("td" +"#" + id).attr('class', colors);
      console.log("going");
    };
  }
}


module.exports = Game;

{'fraction_non_alphanumeric': 0.1570600272851296, 'fraction_numerical': 0.004433833560709414, 'mean_word_length': 2.9628378378378377, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5231757', 'n_tokens_mistral': 1897, 'n_tokens_neox': 1850, 'n_words': 421}