Skip to content

Commit

Permalink
track stage number
Browse files Browse the repository at this point in the history
  • Loading branch information
newagebegins committed Jun 22, 2012
1 parent 9a95b1b commit 5f15a1f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
6 changes: 6 additions & 0 deletions spec/UtilsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ describe("arrayRemove", function () {
expect(a).toEqual([1, 3]);
});
});

describe("String", function () {
it("#lpad", function () {
expect("1".lpad(" ", 2)).toEqual(" 1");
});
});
5 changes: 3 additions & 2 deletions src/GameScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ function GameScene(sceneManager) {
var self = this;
this._sceneManager = sceneManager;
this._curtain = new Curtain();
this._stageMessage = new StageMessage();
this._level = new Level(sceneManager);
this._stage = 1;
this._stageMessage = new StageMessage(this._stage);
this._level = new Level(sceneManager, this._stage);

this._script = new Script();
this._script.enqueue({update: function () {
Expand Down
6 changes: 3 additions & 3 deletions src/Level.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function Level(sceneManager) {
function Level(sceneManager, stageNumber) {
Gamefield.call(this, sceneManager);

this._visible = false;
this._stage = 1;
this._stage = stageNumber;

new PlayerTankControllerFactory(this._eventManager);

Expand Down Expand Up @@ -134,5 +134,5 @@ Level.prototype._drawFlag = function (ctx) {
ctx.drawImage(ImageManager.getImage('flag'), 464, 352);

ctx.fillStyle = "black";
ctx.fillText(this._stage, 482, 398);
ctx.fillText(("" + this._stage).lpad(" ", 2), 466, 398);
};
5 changes: 3 additions & 2 deletions src/StageMessage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function StageMessage() {
function StageMessage(stage) {
this._stage = stage;
this._visible = false;
}

Expand All @@ -15,5 +16,5 @@ StageMessage.prototype.draw = function (ctx) {
return;
}
ctx.fillStyle = "black";
ctx.fillText("STAGE 1", 195, 222);
ctx.fillText("STAGE " + ("" + this._stage).lpad(" ", 2), 195, 222);
};
7 changes: 7 additions & 0 deletions src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ function arrayRemove(arr, obj) {
function arrayRandomElement(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}

String.prototype.lpad = function(padString, length) {
var str = this;
while (str.length < length)
str = padString + str;
return str;
}

0 comments on commit 5f15a1f

Please sign in to comment.