O'Reilly logo

TypeScript Blueprints by Ivo Gabe de Wolff

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required