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

Running the game

To start the game, we must call the game function with the default state, draw function, time handler, and event handler. In lib/game/index.ts, we write the following code to start the game:

import { game } from "../framework/game"; 
import { defaultState } from "./model"; 
import { draw } from "./view"; 
import { step } from "./step"; 
import { eventHandler } from "./event"; 
 
const canvas = <HTMLCanvasElement> document.getElementById("game"); 
game(canvas, document.body, 60, defaultState, draw, step, eventHandler);  

We can compile the game by executing gulp. You can play the game by opening static/index.html.

As you will see, nothing happens when you have eaten all of the dots, or when you get hit by an enemy. In the next section, we ...

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