Skip to content

Commit

Permalink
Price changed to Decimal
Browse files Browse the repository at this point in the history
Now can go beyond 1e308.
  • Loading branch information
angarg12 committed Jan 10, 2015
1 parent fe16432 commit 42fd8f1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
17 changes: 12 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@ <h2>Cash multiplier: {{(player.multiplier).toFixed(4)}}</h2>
<button ng-click="click()">Generate cash ${{player.cashPerClick}}</button>
<p>Cash: $<span ng-bind-html="currencyValue()"/></p>
<h3>Multiplier upgrades</h3>
<button ng-click="buyMultiplierUpgrade(0)" ng-disabled="player.currency.comparedTo(player.multiplierUpgradePrice[0]) < 0">+{{multiplierUpgradePower[0]}} (cost ${{player.multiplierUpgradePrice[0]}})</button>
<button ng-click="buyMultiplierUpgrade(1)" ng-disabled="player.currency.comparedTo(player.multiplierUpgradePrice[1]) < 0">+{{multiplierUpgradePower[1]}} (cost ${{player.multiplierUpgradePrice[1]}})</button>
<button ng-click="buyMultiplierUpgrade(2)" ng-disabled="player.currency.comparedTo(player.multiplierUpgradePrice[2]) < 0">+{{multiplierUpgradePower[2]}} (cost ${{player.multiplierUpgradePrice[2]}})</button>
<button ng-click="buyMultiplierUpgrade(3)" ng-disabled="player.currency.comparedTo(player.multiplierUpgradePrice[3]) < 0">+{{multiplierUpgradePower[3]}} (cost ${{player.multiplierUpgradePrice[3]}})</button>
<button ng-click="buyMultiplierUpgrade(4)" ng-disabled="player.currency.comparedTo(player.multiplierUpgradePrice[4]) < 0">+{{multiplierUpgradePower[4]}} (cost ${{player.multiplierUpgradePrice[4]}})</button>
<button ng-click="buyMultiplierUpgrade(0)" ng-disabled="player.currency.comparedTo(player.multiplierUpgradePrice[0]) < 0">+{{multiplierUpgradePower[0]}} (cost ${{player.multiplierUpgradePrice[0].toString()}})</button>
<br>
<button ng-click="buyMultiplierUpgrade(1)" ng-disabled="player.currency.comparedTo(player.multiplierUpgradePrice[1]) < 0">+{{multiplierUpgradePower[1]}} (cost ${{player.multiplierUpgradePrice[1].toString()}})</button>
<br>
<button ng-click="buyMultiplierUpgrade(2)" ng-disabled="player.currency.comparedTo(player.multiplierUpgradePrice[2]) < 0">+{{multiplierUpgradePower[2]}} (cost ${{player.multiplierUpgradePrice[2].toString()}})</button>
<br>
<button ng-click="buyMultiplierUpgrade(3)" ng-disabled="player.currency.comparedTo(player.multiplierUpgradePrice[3]) < 0">+{{multiplierUpgradePower[3]}} (cost ${{player.multiplierUpgradePrice[3].toString()}})</button>
<br>
<button ng-click="buyMultiplierUpgrade(4)" ng-disabled="player.currency.comparedTo(player.multiplierUpgradePrice[4]) < 0">+{{multiplierUpgradePower[4]}} (cost ${{player.multiplierUpgradePrice[4].toString()}})</button>
<h3>Click power upgrades</h3>
<button ng-click="buyClickUpgrade(0)" ng-disabled="player.multiplier.comparedTo(player.clickUpgradePrice[0]) < 0">+{{clickUpgradePower[0]}} (cost {{player.clickUpgradePrice[0]}} multiplier)</button>
<br>
<button ng-click="buyClickUpgrade(1)" ng-disabled="player.multiplier.comparedTo(player.clickUpgradePrice[1]) < 0">+{{clickUpgradePower[1]}} (cost {{player.clickUpgradePrice[1]}} multiplier)</button>
<br>
<button ng-click="buyClickUpgrade(2)" ng-disabled="player.multiplier.comparedTo(player.clickUpgradePrice[2]) < 0">+{{clickUpgradePower[2]}} (cost {{player.clickUpgradePrice[2]}} multiplier)</button>
<br>
<button ng-click="buyClickUpgrade(3)" ng-disabled="player.multiplier.comparedTo(player.clickUpgradePrice[3]) < 0">+{{clickUpgradePower[3]}} (cost {{player.clickUpgradePrice[3]}} multiplier)</button>
<hr>
</div>
Expand Down
32 changes: 14 additions & 18 deletions js/exponential.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ angular.module('incremental',[])
0,
0,
0],
multiplierUpgradePrice: [10,
100,
10000,
100000000,
10000000000000000],
multiplierUpgradePrice: [new Decimal(10),
new Decimal(100),
new Decimal(10000),
new Decimal(100000000),
new Decimal(10000000000000000)],
clickUpgradeLevel: [0,
0,
0,
Expand All @@ -28,21 +28,16 @@ angular.module('incremental',[])
};

var lastUpdate = 0;
var multiplierUpgradeBasePrice = [10,
100,
10000,
100000000,
10000000000000000];
var multiplierUpgradeBasePrice = [new Decimal(10),
new Decimal(100),
new Decimal(10000),
new Decimal(100000000),
new Decimal(10000000000000000)];
$scope.multiplierUpgradePower = [0.0001,
0.001,
0.01,
0.1,
1];
var clickUpgradeBasePrice = [10,
100,
10000,
100000000,
10000000000000000];
$scope.clickUpgradePower = [10,
1000,
100000,
Expand All @@ -61,9 +56,10 @@ angular.module('incremental',[])
$scope.player.currency = $scope.player.currency.minus($scope.player.multiplierUpgradePrice[number]);
$scope.player.multiplier = $scope.player.multiplier.plus($scope.multiplierUpgradePower[number]);
$scope.player.multiplierUpgradeLevel[number]++;
$scope.player.multiplierUpgradePrice[number] = (multiplierUpgradeBasePrice[number] *
Math.pow(2,Math.pow(1+0.2*(number+1),$scope.player.multiplierUpgradeLevel[number])))
.toFixed();
// The cost function is of the form 2^1.x^(upgradeLevel), where 1.x depends on the upgrade tier
var exponent = Decimal.pow(1+0.2*(number+1),$scope.player.multiplierUpgradeLevel[number]);
$scope.player.multiplierUpgradePrice[number] = multiplierUpgradeBasePrice[number].
times(Decimal.pow(2,exponent));
}
};

Expand Down

0 comments on commit 42fd8f1

Please sign in to comment.