HTML and CSS Reference
In-Depth Information
6. A customer isn't displayed immediately when he or she is created. We only display
the irst customer in the queue. Therefore, the game ick funcion in the game.js
file will display the customer in front of the sushi stand. We define the following
method to display the customer:
Customer.prototype.showUp = function() {
this.graphics = new lib['Customer'+this.number]();
this.graphics.gotoAndStop('normal'); // normal state at first
this.graphics.on('click', customerOnClick.bind(this));
this.addChild(this.graphics);
// bubble that shows what sushi the customer wants.
var bubble = new lib.Bubble();
bubble.x = -40;
bubble.y = -120;
this.addChild(bubble);
// set the type
bubble.sushiType.gotoAndStop(this.wants);
this.hasShownUp = true; // mark the flag
};
7. Make sure to export the Customer deiniion to the game scope for other logic to
access it:
game.Customer = Customer;
8. When a customer is clicked on, we send the sushi in hand to the customer. If the
sushi in hand matches the sushi request, the customer leaves happily:
function customerOnClick() {
// check if is what customer wants
var isEqual =
game.helper.arrayIsEqual(game.sushiOnHand,
game.receipes[this.wants]);
if (isEqual) {
this.hasEaten = true;
}
game.trashSushi();
}
9. Let's move to queue management. We define two arrays to store customer queues:
game.queues = [];
game.queues[0] = [];
game.queues[1] = [];
 
Search WWH ::




Custom Search