forked from newagebegins/BattleCity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
018344e
commit 4f18ddf
Showing
10 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
describe("Lives", function () { | ||
it("should subscribe", function () { | ||
var eventManager = new EventManager(); | ||
spyOn(eventManager, 'addSubscriber'); | ||
var lives = new Lives(eventManager); | ||
expect(eventManager.addSubscriber).toHaveBeenCalledWith(lives, [Tank.Event.PLAYER_DESTROYED]); | ||
}); | ||
|
||
describe("#notify", function () { | ||
it("Tank.Event.PLAYER_DESTROYED", function () { | ||
var eventManager = new EventManager(); | ||
var lives = new Lives(eventManager); | ||
var tank = new Tank(eventManager); | ||
spyOn(lives, 'take'); | ||
lives.notify({'name': Tank.Event.PLAYER_DESTROYED, 'tank': tank}); | ||
expect(lives.take).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
it("#take", function () { | ||
var eventManager = new EventManager(); | ||
spyOn(eventManager, 'fireEvent'); | ||
var EVENT = {'name': Lives.Event.END}; | ||
var lives = new Lives(eventManager); | ||
lives.setCount(2); | ||
|
||
expect(lives.getCount()).toEqual(2); | ||
lives.take(); | ||
expect(lives.getCount()).toEqual(1); | ||
lives.take(); | ||
expect(lives.getCount()).toEqual(0); | ||
|
||
expect(eventManager.fireEvent).not.toHaveBeenCalledWith(EVENT); | ||
lives.take(); | ||
expect(lives.getCount()).toEqual(0); | ||
expect(eventManager.fireEvent).toHaveBeenCalledWith(EVENT); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function Lives(eventManager) { | ||
this._eventManager = eventManager; | ||
this._eventManager.addSubscriber(this, [Tank.Event.PLAYER_DESTROYED]); | ||
this._count = 2; | ||
} | ||
|
||
Lives.Event = {}; | ||
Lives.Event.END = 'Lives.Event.END'; | ||
|
||
Lives.prototype.notify = function (event) { | ||
if (event.name == Tank.Event.PLAYER_DESTROYED) { | ||
this.take(); | ||
} | ||
}; | ||
|
||
Lives.prototype.setCount = function (count) { | ||
this._count = count; | ||
}; | ||
|
||
Lives.prototype.getCount = function () { | ||
return this._count; | ||
}; | ||
|
||
Lives.prototype.take = function () { | ||
if (this._count == 0) { | ||
this._eventManager.fireEvent({'name': Lives.Event.END}); | ||
return; | ||
} | ||
this._count--; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
function LivesView(lives) { | ||
this._lives = lives; | ||
} | ||
|
||
LivesView.prototype.draw = function (ctx) { | ||
ctx.fillStyle = "#000000"; | ||
ctx.font = "16px prstart" | ||
|
||
ctx.drawImage(ImageManager.getImage('roman_one'), 468, 256); | ||
|
||
ctx.fillText("P", 482, 286 - 16); | ||
ctx.fillText(this._lives.getCount(), 482, 286); | ||
|
||
ctx.drawImage(ImageManager.getImage('lives'), 465, 272); | ||
}; |