<commit_before>'use strict';

// Games controller
angular.module('games').controller('GamesController', ['$scope', '$stateParams', '$location', 'Authentication', 'Games','Socket','$http',
	function($scope, $stateParams, $location, Authentication, Games,Socket,$http) {
		$scope.authentication = Authentication;
		$scope.player1Life=100;
		$scope.player2Life=100;

		// Create new Game
		$scope.create = function() {
			// Create new Game object
			var game = new Games ({
				player1: $scope.authentication.user._id
			});

			// Redirect after save
			game.$save(function(response) {
				$location.path('fight/' + response._id);

				// Clear form fields
				$scope.name = '';
			}, function(errorResponse) {
				$scope.error = errorResponse.data.message;
			});
		};
		$scope.games=[];
		$scope.getFightList=function(){
			Socket.on('games', function(game) {
					// console.log(game);
					$scope.games.push(game);

			});
		};

		// Remove existing Game
		$scope.remove = function(game) {
			if ( game ) {
				game.$remove();

				for (var i in $scope.games) {
					if ($scope.games [i] === game) {
						$scope.games.splice(i, 1);
					}
				}
			} else {
				$scope.game.$remove(function() {
					$location.path('games');
				});
			}
		};

		// Update existing Game
		$scope.update = function() {
			var game = $scope.game;

			game.$update(function() {
				$location.path('games/' + game._id);
			}, function(errorResponse) {
				$scope.error = errorResponse.data.message;
			});
		};

		// Find a list of Games
		$scope.find = function() {
			$scope.games = Games.query(function(response){
				console.log(response);
			});
		};

		$scope.viewHolograms=function(){
			Socket.on('holograms/', function(player) {
					 console.log(player);
					 if (player.player2) {
						$scope.player2=player.player2;

					 }
					 if (player.player1) {
						$scope.player1=player.player1;//si somos el player 1 escucharemos las acciones del player2
					 }
					 Socket.on('player1/', function(actions) {
						 console.log(actions);
						 $scope.player1Actions=actions

					 });
					 Socket.on('player2/', function(actions) {
						 console.log(actions);
						 $scope.player2Actions=actions

					 });

			});
		};

		$scope.player1Emit=function(){
			console.log('estoy enviando');
			// 			console.log($scope.emitir);
			// console.log(Socket);
			// 			Socket.emit('/holograms/',{player1:'affdf'},function(result){
			// 				console.log(result);
			// 			});
			console.log($scope.emitir);

			$scope.emitir=$scope.danmage();
			$scope.player2Life=$scope.player2Life-($scope.emitir*100);


			$http.post('/player1', {action:$scope.emitir}).success(function(response){
				console.log(response);
			});

		};

		$scope.player2Emit=function(){
			$scope.emitir=$scope.danmage();
			console.log($scope.emitir);

			$scope.player1Life=$scope.player1Life-($scope.emitir*100);
			$http.post('/player2', {action:$scope.emitir}).success(function(response){
				console.log(response);
			});

		};

		$scope.danmage=function(){
			var danmage,acert;
			// acert=Math.random();
			// if (acert>=.5) {
			danmage=Math.random();
			// }
			// console.log(acert);
			return danmage;
		};

		// Find existing Game
		$scope.player2={};
		$scope.player1={};
		$scope.findOne = function() {
			$scope.game = Games.get({
				gameId: $stateParams.gameId
			},function(response){

				if (response.player1._id+''==$scope.authentication.user._id) {
					Socket.on('player2/', function(actions) {
						console.log(actions);
						$scope.player1Life=$scope.player1Life-(actions*100);
					});
				}else {
					Socket.on('player1/', function(actions) {
						console.log(actions);
						$scope.player2Life=$scope.player2Life-(actions*100);

					});

				}

				console.log(response);
				Socket.on('figthRoom/'+$stateParams.gameId, function(player) {
						 console.log(player);
						 if (player.player2) {
						 	$scope.player2=player.player2;
						 }

				});
			});
		};

		$scope.mainView = function() {

		}

		$scope.battle = function() {

		}




		var stage, w, h, loader, manifest;
		var sky, grant, ground, hill, hill2;
		$scope.init=function() {
			//examples.showDistractor();<commit_msg>enviar accion en el socket<commit_after>'use strict';

// Games controller
angular.module('games').controller('GamesController', ['$scope', '$stateParams', '$location', 'Authentication', 'Games','Socket','$http',
	function($scope, $stateParams, $location, Authentication, Games,Socket,$http) {
		$scope.authentication = Authentication;
		$scope.player1Life=100;
		$scope.player2Life=100;

		// Create new Game
		$scope.create = function() {
			// Create new Game object
			var game = new Games ({
				player1: $scope.authentication.user._id
			});

			// Redirect after save
			game.$save(function(response) {
				$location.path('fight/' + response._id);

				// Clear form fields
				$scope.name = '';
			}, function(errorResponse) {
				$scope.error = errorResponse.data.message;
			});
		};
		$scope.games=[];
		$scope.getFightList=function(){
			Socket.on('games', function(game) {
					// console.log(game);
					$scope.games.push(game);

			});
		};

		// Remove existing Game
		$scope.remove = function(game) {
			if ( game ) {
				game.$remove();

				for (var i in $scope.games) {
					if ($scope.games [i] === game) {
						$scope.games.splice(i, 1);
					}
				}
			} else {
				$scope.game.$remove(function() {
					$location.path('games');
				});
			}
		};

		// Update existing Game
		$scope.update = function() {
			var game = $scope.game;

			game.$update(function() {
				$location.path('games/' + game._id);
			}, function(errorResponse) {
				$scope.error = errorResponse.data.message;
			});
		};

		// Find a list of Games
		$scope.find = function() {
			$scope.games = Games.query(function(response){
				console.log(response);
			});
		};

		$scope.viewHolograms=function(){
			Socket.on('holograms/', function(player) {
					 console.log(player);
					 if (player.player2) {
						$scope.player2=player.player2;

					 }
					 if (player.player1) {
						$scope.player1=player.player1;//si somos el player 1 escucharemos las acciones del player2
					 }
					 Socket.on('player1/', function(actions) {
						 console.log(actions);
						 $scope.player1Actions=actions

					 });
					 Socket.on('player2/', function(actions) {
						 console.log(actions);
						 $scope.player2Actions=actions

					 });

			});
		};

		$scope.player1Emit=function(){
			console.log('estoy enviando');
			// 			console.log($scope.emitir);
			// console.log(Socket);
			// 			Socket.emit('/holograms/',{player1:'affdf'},function(result){
			// 				console.log(result);
			// 			});
			$scope.actionSprite=0;
			console.log($scope.emitir);

			$scope.emitir=$scope.danmage();
			$scope.player2Life=$scope.player2Life-($scope.emitir*100);


			$http.post('/player1', {action:
				{
				danmage:$scope.emitir,
				action:$scope.actionSprite
				}
			}).success(function(response){
				console.log(response);
			});

		};

		$scope.player2Emit=function(){
			$scope.emitir=$scope.danmage();
			console.log($scope.emitir);
			$scope.actionSprite=0;
			$scope.player1Life=$scope.player1Life-($scope.emitir*100);
			$http.post('/player2', {action:	{
				danmage:$scope.emitir,
				action:$scope.actionSprite
				}
			}).success(function(response){
				console.log(response);
			});

		};

		$scope.danmage=function(){
			var danmage,acert;
			// acert=Math.random();
			// if (acert>=.5) {
			danmage=Math.random();
			// }
			// console.log(acert);
			return danmage;
		};

		// Find existing Game
		$scope.player2={};
		$scope.player1={};
		$scope.findOne = function() {
			$scope.game = Games.get({
				gameId: $stateParams.gameId
			},function(response){

				if (response.player1._id+''==$scope.authentication.user._id) {
					Socket.on('player2/', function(actions) {
						console.log(actions);
						$scope.player1Life=$scope.player1Life-(actions.danmage*100);
					});
				}else {
					Socket.on('player1/', function(actions) {
						console.log(actions);
						$scope.player2Life=$scope.player2Life-(actions.danmage*100);

					});

				}

				console.log(response);
				Socket.on('figthRoom/'+$stateParams.gameId, function(player) {
						 console.log(player);
						 if (player.player2) {
						 	$scope.player2=player.player2;
						 }

				});
			});
		};

		$scope.mainView = function() {

		}

		$scope.battle = function() {

		}




		var stage, w, h, loader, manifest;
		var sky, grant, ground, hill, hill2;
		$scope.init=function() {
			//examples.showDistractor();
{'fraction_non_alphanumeric': 0.1822637106184364, 'fraction_numerical': 0.01353558926487748, 'mean_word_length': 2.9643848288621646, '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': '6814079', 'n_tokens_mistral': 3750, 'n_tokens_neox': 2848, 'n_words': 419}