HTML and CSS Reference
In-Depth Information
5. We deine a funcion to quickly clear all the ingredients on hand if the player needs
to trash the sushi for selecing the wrong ingredients as given in the following code:
game.trashSushi = function() {
game.sushiOnHand.length = 0; // clear it
game.view.clearAllIngredients();
};
6. Let's move back to the view.js ile. There are some mouse interacion events for
the DOM user interface. The following internal funcion inside the view.js file sets
up the DOM elements for the clicking events:
function initDOMElements() {
var ingredients =
document.querySelectorAll('.ingredient');
for (var i=0, len=ingredients.length; i<len; i++) {
var element = ingredients[i];
element.onclick = ingredientOnClick;
};
// trash button
var deleteButton = document.getElementById
('delete-sushi-btn');
deleteButton.onclick = function(){
game.trashSushi();
};
// logic of clicking the ingredients
// reference of 3 layers in sushi board
// for the ingredientOnClick function to use
var others = document.getElementById('others');
var rices = document.getElementById('rices');
var seaweeds = document.getElementById('seaweeds');
var ingredientOnClick = function() {
var type = this.dataset.type;
// DATA
game.sushiOnHand.push(type);
game.sushiOnHand = game.sushiOnHand.sort();
addIngredientToScreen(type);
};
};
 
Search WWH ::




Custom Search