improve comments in game manager
This commit is contained in:
+7
-4
@@ -26,6 +26,7 @@ GameManager.prototype.keepPlaying = function () {
|
|||||||
this.actuator.continue();
|
this.actuator.continue();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Return true if the game is lost, or has won and the user hasn't kept playing
|
||||||
GameManager.prototype.isGameTerminated = function () {
|
GameManager.prototype.isGameTerminated = function () {
|
||||||
if (this.over || (this.won && !this.keepPlaying)) {
|
if (this.over || (this.won && !this.keepPlaying)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -38,6 +39,7 @@ GameManager.prototype.isGameTerminated = function () {
|
|||||||
GameManager.prototype.setup = function () {
|
GameManager.prototype.setup = function () {
|
||||||
var previousState = this.storageManager.getGameState();
|
var previousState = this.storageManager.getGameState();
|
||||||
|
|
||||||
|
// Reload the game from a previous game if present
|
||||||
if (previousState) {
|
if (previousState) {
|
||||||
this.grid = new Grid(previousState.grid.size,
|
this.grid = new Grid(previousState.grid.size,
|
||||||
previousState.grid.cells); // Reload grid
|
previousState.grid.cells); // Reload grid
|
||||||
@@ -100,6 +102,7 @@ GameManager.prototype.actuate = function () {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Represent the current game as an object
|
||||||
GameManager.prototype.serialize = function () {
|
GameManager.prototype.serialize = function () {
|
||||||
return {
|
return {
|
||||||
grid: this.grid.serialize(),
|
grid: this.grid.serialize(),
|
||||||
@@ -195,10 +198,10 @@ GameManager.prototype.move = function (direction) {
|
|||||||
GameManager.prototype.getVector = function (direction) {
|
GameManager.prototype.getVector = function (direction) {
|
||||||
// Vectors representing tile movement
|
// Vectors representing tile movement
|
||||||
var map = {
|
var map = {
|
||||||
0: { x: 0, y: -1 }, // up
|
0: { x: 0, y: -1 }, // Up
|
||||||
1: { x: 1, y: 0 }, // right
|
1: { x: 1, y: 0 }, // Right
|
||||||
2: { x: 0, y: 1 }, // down
|
2: { x: 0, y: 1 }, // Down
|
||||||
3: { x: -1, y: 0 } // left
|
3: { x: -1, y: 0 } // Left
|
||||||
};
|
};
|
||||||
|
|
||||||
return map[direction];
|
return map[direction];
|
||||||
|
|||||||
Reference in New Issue
Block a user