August 2018
Intermediate to advanced
534 pages
11h 21m
English
Now that we have a board to receive items, we will create the game items' factory. The factory is a design pattern that allows us to create an object without exposing the creation logic to the caller. This factory can be seen as a helper class that will handle all the dirty tasks required when you want to create a new game item from JavaScript. Do you remember GameEntity.qml? It is the parent component of Apple.qml, Snake.qml, and Wall.qml. The factory will be able to create a specific entity for a given a type and coordinates. We will use the property type to identify an entity kind. Here is the factory pattern schema used in our snake game:
We can now create the factory.js file, which begins like this: ...
Read now
Unlock full access