Book Image

TypeScript Blueprints

By : Ivo Gabe de Wolff
Book Image

TypeScript Blueprints

By: Ivo Gabe de Wolff

Overview of this book

TypeScript is the future of JavaScript. Having been designed for the development of large applications, it is now being widely incorporated in cutting-edge projects such as Angular 2. Adopting TypeScript results in more robust software - software that is more scalable and performant. It's scale and performance that lies at the heart of every project that features in this book. The lessons learned throughout this book will arm you with everything you need to build some truly amazing projects. You'll build a complete single page app with Angular 2, create a neat mobile app using NativeScript, and even build a Pac Man game with TypeScript. As if fun wasn't enough, you'll also find out how to migrate your legacy codebase from JavaScript to TypeScript. This book isn't just for developers who want to learn - it's for developers who want to develop. So dive in and get started on these TypeScript projects.
Table of Contents (16 chapters)
TypeScript Blueprints
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

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 will implement a menu. When the player wins or loses, we will show this menu.