HTML and CSS Reference
In-Depth Information
We determine the current step by looping the stepsSeconds array and checking whether
the difference reaches the target number of seconds. When it reaches the last step, we mark
the construcion of the building as done.
The construcion states are put onto the data map. When the map redraws on every ick,
it will handle the visual changes and draw different stages of the building on the floor.
Generating coins and diamonds
In this task, we create the economy of the game by generaing the coins and diamonds.
Prepare for lift off
Before geing into the code, let's summarize how the buildings afect the coins and diamonds:
F The generaion of coins and diamonds depends on the number of buildings
F By default, each coin is generated within a ixed duraion
F More coin generators speed up the coin generaion process
F The merchant building trades 200 coins for a diamond once in a while, unless there
are not enough coins
F These buildings are where the populaion resides
F We count the number of power supplies to know the maximum populaion capacity
Engage thrusters
To generate coins and diamonds, perform the following steps:
1. First, we define the tickCountForMerchantDiamond and
coinsNeededForDiamond variables in the game seings:
game.setting = {
// existing game setting
tickCountForMerchantDiamond: 800,
coinsNeededForDiamond: 200
2. Let's create a funcion to increase the diamond count. We add it to the UI layer
because eventually a diamond sprite will pop up for the player to click on.
However, in this task, we will simply increase the count to make things simpler:
UILayer.prototype.popDiamond = function(building) { += 1;
Search WWH ::

Custom Search