In this task, we create the economy of the game by generating the coins and diamonds.
Before getting into the code, let's summarize how the buildings affect the coins and diamonds:
The generation of coins and diamonds depends on the number of buildings
By default, each coin is generated within a fixed duration
More coin generators speed up the coin generation process
The merchant building trades 200 coins for a diamond once in a while, unless there are not enough coins
These buildings are where the population resides
We count the number of power supplies to know the maximum population capacity
To generate coins and diamonds, perform the following steps:
First, we define the
tickCountForMerchantDiamond
andcoinsNeededForDiamond
variables in the game settings:game.setting = { ... // existing game setting tickCountForMerchantDiamond: 800, coinsNeededForDiamond: 200 };
Let's create a function to increase the diamond count. We add...