HTML and CSS Reference
In-Depth Information
10. We need to remove the first array element once the customer is served and he
or she leaves the queue:
game.removeFromQueue = function(index) {
game.queues[index].shift();
};
11. We create a imer interval to generate a new customer and put him/her in the queue:
game.tick = function() {
var durationForNewCustomer = 500;
if (cjs.Ticker.getTicks() % durationForNewCustomer ===
0) {
game.summonNewCustomer();
// queue 0
var customer = game.queues[0][0];
if (customer && !customer.hasShownUp) {
customer.showUp();
}
// queue 1
var customer = game.queues[1][0];
if (customer && !customer.hasShownUp) {
customer.showUp();
}
}
};
12. Now, we need a logic code to summon a new customer:
game.summonNewCustomer = function() {
// left or right?
var leftOrRight = 'left';
var queueIndex = 0;
if (Math.random() >= 0.5) {
leftOrRight = 'right';
queueIndex = 1;
}
var customer = new game.Customer(1, leftOrRight);
game.queues[queueIndex].push(customer);
if (leftOrRight === 'left') {
game.view.queueLeft.addChild(customer);
} else {
game.view.queueRight.addChild(customer);
}
};
 
Search WWH ::




Custom Search