HTML and CSS Reference
In-Depth Information
game.cash -= needCash;
game.view.refreshCash();
}
};
8. When any ingredient buton is clicked on, we reduce the amount of the ingredient:
if (game.amount[type] > 0) {
game.amount[type] -= 1;
game.view.refreshAmount(type);
} else {
return; // EXIT function if not enough amount.
}
9. Finally, let's move to the customer.js ile. When the customer inishes eaing
the sushi, we reward the player with money by adding the following code to the
customer-leaving condiion:
if (isEqual) {
...
// Existing code goes here
game.cash += 120;
game.view.refreshCash();
}
Objective complete - mini debriefing
We have created a cash flow and controlled the flow of the number of ingredients. A player
makes sushi to earn money and uses the money to refill ingredients. We used an array to
control the amount so that we can use the for-loop to control the enire amount at once.
The code is clear because we have separated the logic into diferent responsibiliies. We put
the buton events in the view component and the number of ingredients and cash control
into the data part. This makes our code easy to read and maintain.
Classified intel
We displayed the cash amount without formaing. There are code snippets or libraries to
format numbers if you want to display the cash in the accouning format with a comma
separaing the thousands. The following are two number-formaing libraries worth
checking out:
F accouning.js : http://josscrowcroft.github.io/accounting.js/
F Numeral.js : http://numeraljs.com
 
Search WWH ::




Custom Search