import { Component , AfterViewInit , ChangeDetectionStrategy , Input } from '@angular/core' ; import { Observable } from "rxjs/Observable" ; import { GameState } from "../../store/game.state" ; import { GameService } from "../../service/game.service" ; @ Component ( { selector : 'game-container' , templateUrl : 'game-container.component.html' , changeDetection : ChangeDetectionStrategy . OnPush } ) export class GameContainerComponent implements AfterViewInit { @ Input ( ) state : GameState ; height ; width ; constructor ( private game ) { } ngAfterViewInit ( ) { this . createGame ( ) ; /** Clone hero when space is clicked */ Observable . fromEvent ( document , 'keyup' ) . subscribe ( ( e ) => { if ( e . keyCode === 32 ) { this . game . addBot ( ) ; } } ) ; } createGame ( ) { this . height = 10 ; this . width = 12 ; this . game . newGame ( this . width , this . height ) ; } }