December 2016
Intermediate to advanced
841 pages
17h
English
In lib/game/model.ts, we will create the models for the game. These models will contain the state of the game, such as the location of the enemies, walls, and dots. The state must also contain the current movement of the player and the difficulty level, as the game will have multiple difficulties.
We start with several enums. We can store the difficulty with such an enum:
export enum Difficulty {
Easy,
Hard,
Extreme
}
The values of an enum are converted to numbers during compilation. TypeScript gives the first element zero as the value, the next item one, and so on. In this example, Easy is 0, Hard is 1, and Extreme is 2. However, you can also provide other values. For some applications, this can be useful. We will ...
Read now
Unlock full access