Skip to content

Commit 6cb3d71

Browse files
improve comments in game manager
1 parent af683a7 commit 6cb3d71

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

js/game_manager.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ GameManager.prototype.keepPlaying = function () {
2626
this.actuator.continue();
2727
};
2828

29+
// Return true if the game is lost, or has won and the user hasn't kept playing
2930
GameManager.prototype.isGameTerminated = function () {
3031
if (this.over || (this.won && !this.keepPlaying)) {
3132
return true;
@@ -38,6 +39,7 @@ GameManager.prototype.isGameTerminated = function () {
3839
GameManager.prototype.setup = function () {
3940
var previousState = this.storageManager.getGameState();
4041

42+
// Reload the game from a previous game if present
4143
if (previousState) {
4244
this.grid = new Grid(previousState.grid.size,
4345
previousState.grid.cells); // Reload grid
@@ -100,6 +102,7 @@ GameManager.prototype.actuate = function () {
100102

101103
};
102104

105+
// Represent the current game as an object
103106
GameManager.prototype.serialize = function () {
104107
return {
105108
grid: this.grid.serialize(),
@@ -129,7 +132,7 @@ GameManager.prototype.moveTile = function (tile, cell) {
129132

130133
// Move tiles on the grid in the specified direction
131134
GameManager.prototype.move = function (direction) {
132-
// 0: up, 1: right, 2:down, 3: left
135+
// 0: up, 1: right, 2: down, 3: left
133136
var self = this;
134137

135138
if (this.isGameTerminated()) return; // Don't do anything if the game's over
@@ -195,10 +198,10 @@ GameManager.prototype.move = function (direction) {
195198
GameManager.prototype.getVector = function (direction) {
196199
// Vectors representing tile movement
197200
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
202205
};
203206

204207
return map[direction];

0 commit comments

Comments
 (0)