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 use custom values to define Movement
. This enum contains the four directions in which the player can move. In case the user does not move, we use None
. We give the members a value:
export enum Movement { None...