@@ -26,6 +26,7 @@ GameManager.prototype.keepPlaying = function () {
26
26
this . actuator . continue ( ) ;
27
27
} ;
28
28
29
+ // Return true if the game is lost, or has won and the user hasn't kept playing
29
30
GameManager . prototype . isGameTerminated = function ( ) {
30
31
if ( this . over || ( this . won && ! this . keepPlaying ) ) {
31
32
return true ;
@@ -38,6 +39,7 @@ GameManager.prototype.isGameTerminated = function () {
38
39
GameManager . prototype . setup = function ( ) {
39
40
var previousState = this . storageManager . getGameState ( ) ;
40
41
42
+ // Reload the game from a previous game if present
41
43
if ( previousState ) {
42
44
this . grid = new Grid ( previousState . grid . size ,
43
45
previousState . grid . cells ) ; // Reload grid
@@ -100,6 +102,7 @@ GameManager.prototype.actuate = function () {
100
102
101
103
} ;
102
104
105
+ // Represent the current game as an object
103
106
GameManager . prototype . serialize = function ( ) {
104
107
return {
105
108
grid : this . grid . serialize ( ) ,
@@ -129,7 +132,7 @@ GameManager.prototype.moveTile = function (tile, cell) {
129
132
130
133
// Move tiles on the grid in the specified direction
131
134
GameManager . prototype . move = function ( direction ) {
132
- // 0: up, 1: right, 2:down, 3: left
135
+ // 0: up, 1: right, 2: down, 3: left
133
136
var self = this ;
134
137
135
138
if ( this . isGameTerminated ( ) ) return ; // Don't do anything if the game's over
@@ -195,10 +198,10 @@ GameManager.prototype.move = function (direction) {
195
198
GameManager . prototype . getVector = function ( direction ) {
196
199
// Vectors representing tile movement
197
200
var map = {
198
- 0 : { x : 0 , y : - 1 } , // up
199
- 1 : { x : 1 , y : 0 } , // right
200
- 2 : { x : 0 , y : 1 } , // down
201
- 3 : { x : - 1 , y : 0 } // left
201
+ 0 : { x : 0 , y : - 1 } , // Up
202
+ 1 : { x : 1 , y : 0 } , // Right
203
+ 2 : { x : 0 , y : 1 } , // Down
204
+ 3 : { x : - 1 , y : 0 } // Left
202
205
} ;
203
206
204
207
return map [ direction ] ;
0 commit comments