(function(angular) { angular.module('ngGame', []).controller('ngGameController', function($scope) { $scope.pi = "3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912"; $scope.life = "❤️❤️❤️"; $scope.position = 2; $scope.value = "3."; $scope.score = 0; $scope.record = 0; $scope.numbers = ['0','1','2','3','4','5','6','7','8','9']; $scope.next = ''; $scope.color = '#101010'; $scope.keyPress = function(keyEvent) { $scope.game(keyEvent.key); } $scope.game = function(key){ if($scope.numbers.includes(key)){ $scope.next = ''; if($scope.pi.substring($scope.position,$scope.position+1) == key){ $scope.position = $scope.position+1; $scope.value = $scope.value + key; $scope.score = $scope.score+1; $scope.color = 'lawngreen'; if($scope.value.length == 10){ $scope.value = $scope.value.substring(1); } if($scope.score > $scope.record){ $scope.record = $scope.score; } }else{ if($scope.life == ""){ $scope.next = "NEXT NUMBERS: "+$scope.pi.substring($scope.position,$scope.position+6); reset(); }else{ $scope.life = $scope.life.substr(0, $scope.life.length - 2); $scope.color = 'orangered'; } } } } function reset(){ $scope.life = "❤️❤️❤️"; $scope.position = 2; $scope.value = "3."; $scope.score = 0; $scope.color = '#101010'; alert('gameover'); } }); })(window.angular);