Creating the models
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.
Using enums
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 ...
Get TypeScript: Modern JavaScript Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.