HTML and CSS Reference
In-Depth Information
3. When iniializing the game, we add two more variables. The irst one is the
countdown unil we get the next coin. The second one is the count so far:
game.coinGenerationCountdown = 90;
game.coinGenerationCount = 0;
4. The number of coin generators will affect the countdown to generate a new coin.
We deine the following funcion in the game scope that calculates and applies the
building's effects:
game.calculateBuildingsEffects = function(){
// refresh population and power supplies based on the building
list.
game.powerSupplies = 10;
game.populations = 0;
game.coinGenerationCountdown = 90; // default value, will be
affected by coins generators
for (var i=0, len=game.buildingsList.length;
i<len; i++) {
var b = game.buildingsList[i];
var data = game.BuildingsData[b.name];
evaluatePopulation(data.needPopulations);
if (b.isConstructionDone) {
// only count power after it is built.
evaluatePowerSupply(data.power);
if (b.name === 'CoinsGenerator') {
evaluateCoinsGeneration();
}
if (b.name === 'Merchant') {
evaluateMerchant(b);
}
}
}
};
5. We called four funcions in the previous task. These are evaluatePopulation ,
evaluatePowerSupply , evaluateCoinsGeneration , and evaluateMerchant .
Let's add them one by one ater our calculateBuildingsEffects method:
function evaluatePopulation(value){
game.populations += value;
}
 
Search WWH ::




Custom Search