Skip to content

Commit

Permalink
improve comments in game manager
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielecirulli committed Mar 22, 2014
1 parent af683a7 commit 6cb3d71
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions js/game_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ GameManager.prototype.keepPlaying = function () {
this.actuator.continue();
};

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

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

};

// Represent the current game as an object
GameManager.prototype.serialize = function () {
return {
grid: this.grid.serialize(),
Expand Down Expand Up @@ -129,7 +132,7 @@ GameManager.prototype.moveTile = function (tile, cell) {

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

if (this.isGameTerminated()) return; // Don't do anything if the game's over
Expand Down Expand Up @@ -195,10 +198,10 @@ GameManager.prototype.move = function (direction) {
GameManager.prototype.getVector = function (direction) {
// Vectors representing tile movement
var map = {
0: { x: 0, y: -1 }, // up
1: { x: 1, y: 0 }, // right
2: { x: 0, y: 1 }, // down
3: { x: -1, y: 0 } // left
0: { x: 0, y: -1 }, // Up
1: { x: 1, y: 0 }, // Right
2: { x: 0, y: 1 }, // Down
3: { x: -1, y: 0 } // Left
};

return map[direction];
Expand Down

0 comments on commit 6cb3d71

Please sign in to comment.