qgame
by kevmus
HTML
<body ng-app="incremental">
<div ng-controller="IncCtrl">
<button ng-click="click()">click me for a free cookie</button>
<button ng-click="buyClicker()">Buy a clicker (cost {{clickerPrice()}} cookies)</button>
{{clickers}}
<hr>
<h1>Cookies: {{cookies}}</h1>
</div>
</body>
JavaScript
angular.module('incremental',[])
.controller('IncCtrl',['$scope','$document','$interval',function($scope,$document,$interval) {
$scope.cookies = 0;
$scope.clickers = 0;
$scope.click = function() {
$scope.cookies++;
}
$scope.clickerPrice = function(){
return (10 * Math.pow(1.1,$scope.clickers)).toFixed();
}
$scope.buyClicker = function() {
if ($scope.cookies >= $scope.clickerPrice()) {
$scope.cookies -= $scope.clickerPrice();
$scope.clickers++;
}
}
function update() {
$scope.cookies += $scope.clickers;
};
$document.ready(function(){
$interval(update,1000);
});
}]);