HTML and CSS Reference
In-Depth Information
Engage thrusters
Let's work on the following steps to add the customer and queue logic to our game:
1. In the view.js ile, we deine a funcion to set up the customer view:
function initCustomerView() {
// Canvas
game.canvas = document.getElementById('canvas');
game.stage = new cjs.Stage(game.canvas);
// add game.stage to ticker to make the stage update
cjs.Ticker.addEventListener('tick', game.stage);
cjs.Ticker.addEventListener('tick', game.tick);
game.view.queueLeft = new cjs.Container();
game.view.queueRight = new cjs.Container();
2. Then, we create a Customer class in a dedicated file called customer.js .
The constructor takes two parameters, namely, style number and queue choice:
function Customer(number, leftOrRight) {; // super call Container.
this.number = number;
// randomize a sushi
this.wants = randomWants() ;
// has eaten the sushi and leaving?
this.hasEaten = false;
// queued or was shown in front of the queue?
this.hasShownUp = false;
// how much time was wasted in waiting?
this.hasWaitForTicks = 0;
Search WWH ::

Custom Search