Book Image

HTML5 Game Development Hotshot

By : Seng Hin Mak, Makzan Makzan (Mak Seng Hin)
Book Image

HTML5 Game Development Hotshot

By: Seng Hin Mak, Makzan Makzan (Mak Seng Hin)

Overview of this book

Table of Contents (15 chapters)
HTML5 Game Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Making the sushi


In this task, we add the logic to composite the sushi by selecting the ingredients.

Prepare for lift off

The following figure shows the recipes of the sushi:

Engage thrusters

Follow the given steps to create the sushi:

  1. We need a function to compare two given arrays. The array is in one dimension only so we don't need any deep comparison. Put the following comparing function in the helpers.js file:

    game.helper.arrayIsEqual = function(array1, array2) {
      if (array1.length !== array2.length) {
        return false;
      }
      for (var i = 0, len=array1.length; i < len; i++) {
        if (array1[i] !== array2[i]) {
          return false;
        }
      }
      return true;
    };
  2. Then we need another helper function that clears all the children nodes inside a given DOM element. Defining the following function inside the helpers.js file helps us to keep a cleaner code base:

    game.helper.clearChildren = function(node) {
      while (node.lastChild) {
        node.removeChild(node.lastChild);
      }
    };
  3. We use three layers to...