<commit_before>'use strict'

var app = angular.module('gameApp', ['btford.socket-io', 'nywton.chessboard'])

var player;
var score = 0;


app.factory('mySocket', function (socketFactory) {
  console.log('factory!');
  return socketFactory();
})

app.controller('mainCtrl', function($scope, mySocket, $timeout) {

  $(document).ready(function () {
    
    var puzzle = getFen();
    
    var board = ChessBoard("board", { 
      draggable: true,
      dropOffBoard: "snapback",
      position: puzzle.fen1 
    });

    $scope.result;

    //check users answer and update users score
    $("#checkMove").click(function (e) {

      e.preventDefault();

      var userAnswer = board.fen();

      if(userAnswer == puzzle.fen2){

        $(".correct").removeClass("hidden");
        $(".wrong").addClass("hidden");
        $scope.userScore += 10;
        $scope.result = "Correct!";
        console.log("Correct!");

      } 

      else {
        $(".correct").addClass("hidden");
        $(".wrong").removeClass("hidden");
        console.log("Wrong!");
      }

      updateBoard();
    });


    //change puzzle
    $("#nextPuzzle").click(function (){
        updateBoard();
    });

    function updateBoard(){
      console.log("updateboard");
      puzzle = getFen();

      board = ChessBoard("board", { 
        draggable: true,
        dropOffBoard: "snapback",
        position: puzzle.fen1 
      });
     
    };


  });//closes document ready




  $scope.userScore=score;

  $scope.$on('socket:error',  function(ev, data) {
    console.log('socket error:', data);
  });

  mySocket.on('playerNum',  function(playerNum) {
    console.log('playerNum: ', playerNum);
    $scope.player = playerNum;
    $scope.waitText = 'Waiting for opponent';
  });

  mySocket.on('gameStart', () => {
    if($scope.player) {
      $scope.waitText= 'Press Start to Begin!';
    }
  });

  mySocket.on('winner', (winner) => {
    if(winner === 'draw') {
      $scope.waitText = 'You tied! No Pokemon caught';
    } else if(winner === score) {
      $scope.waitText = 'You caught a Pokemon!';
    } else {
      $scope.waitText = 'You lost! Missed that Pokemon!';
    }

  });

  $scope.startTimer = () => {
    console.log('timer!');
    
    $scope.waitText = 'Your timer has started! You have 20 seconds!'
    
    $timeout(function () {
    mySocket.emit('timeout', score);
    
    $scope.waitText='Your time is up! Waiting for oponent to finish.'
  }, 20000);
  }


});
<commit_msg>controllers<commit_after>'use strict'

var app = angular.module('gameApp', ['btford.socket-io', 'nywton.chessboard'])

var player;
var score = 0;


app.factory('mySocket', function (socketFactory) {
  console.log('factory!');
  return socketFactory();
})

app.controller('mainCtrl', function($scope, mySocket, $timeout) {

  $(document).ready(function () {

    var puzzle = getFen();

    var board = ChessBoard("board", {
      draggable: true,
      dropOffBoard: "snapback",
      position: puzzle.fen1
    });

    $scope.result;

    //check users answer and update users score
    $("#checkMove").click(function (e) {

      e.preventDefault();

      var userAnswer = board.fen();

      if(userAnswer == puzzle.fen2){

        $(".correct").removeClass("hidden");
        $(".wrong").addClass("hidden");
        $scope.userScore += 10;
        $scope.result = "Correct!";
        console.log("Correct!");

      }

      else {
        $(".correct").addClass("hidden");
        $(".wrong").removeClass("hidden");
        console.log("Wrong!");
      }

      updateBoard();
    });


    //change puzzle
    $("#nextPuzzle").click(function (){
        updateBoard();
    });

    function updateBoard(){
      console.log("updateboard");
      puzzle = getFen();

      board = ChessBoard("board", {
        draggable: true,
        dropOffBoard: "snapback",
        position: puzzle.fen1
      });

    };


  });//closes document ready


  $scope.userScore=score;

  $scope.$on('socket:error',  function(ev, data) {
    console.log('socket error:', data);
  });

  mySocket.on('playerNum',  function(playerNum) {
    console.log('playerNum: ', playerNum);
    $scope.player = playerNum;
    $scope.waitText = 'Waiting for opponent';
  });

  mySocket.on('gameStart', () => {
    if($scope.player) {
      $scope.waitText= 'Press Start to Begin!';
    }
  });

  mySocket.on('winner', (winner) => {
    if(winner === 'draw') {
      $scope.waitText = 'You tied! No Pokemon caught';
    } else if(winner === score) {
      $scope.waitText = 'You caught a Pokemon!';
    } else {
      $scope.waitText = 'You lost! Missed that Pokemon!';
    }

  });

  $scope.startTimer = () => {
    console.log('timer!');

    $scope.waitText = 'Your timer has started! You have 20 seconds!'

    $timeout(function () {
    mySocket.emit('timeout', score);

    $scope.waitText='Your time is up! Waiting for oponent to finish.'
  }, 20000);
  }


});

{'fraction_non_alphanumeric': 0.17864393016646365, 'fraction_numerical': 0.005278116118554608, 'mean_word_length': 2.652335063009637, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '7357592', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1527, 'n_words': 312}