Skip to content

Commit

Permalink
Added end game implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sblausten committed Jul 30, 2017
1 parent 47b55e2 commit d5180f9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions spec/features/playSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,33 @@ describe('Play', function () {
expect(scorecard.getCard().length).toEqual(10);
expect(game.getTotalScore()).toEqual(0);
});
it('ends after 10 frames if no strike on final frame', function () {
var game = new Game();
console.log = jasmine.createSpy('log');
spyOn(Math, 'random').and.returnValue(0);
for (var i = 0; i < 21; i++) {
game.play();
}
expect(console.log).toHaveBeenCalledWith('Game over!');
});
// it('ends after 11 frames if strike on 10th frame', function () {
// var game, scorecard;
// game = new Game();
//
// console.log = jasmine.createSpy('log');
// spyOn(Math, 'random').and.returnValue(0);
// for (var i = 0; i < 18; i++) {
// game.play();
// }
// Math.random.calls.reset();
// spyOn(Math, 'random').and.returnValues(10, 0);
// game.play();
// game.play();
// Math.random.calls.reset();
// spyOn(Math, 'random').and.returnValue(0);
// for (var i = 0; i < 3; i++) {
// game.play();
// }
// expect(console.log).toHaveBeenCalledWith('Game over!');
// });
});
1 change: 1 addition & 0 deletions src/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function Game () {

Game.prototype = {
play: function () {
if (this.checkGameEnd()) { console.log('Game over!'); return; }
this.getCurrentFrame().processRoll();
this.nextFrame();
},
Expand Down

0 comments on commit d5180f9

Please sign in to comment.