forked from makersacademy/bowling-challenge
-
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.
Bowling: scores a frame when the ball is thrown, add current frame fu…
…nctionality
- Loading branch information
1 parent
1da5754
commit e4e0ff2
Showing
5 changed files
with
39 additions
and
2 deletions.
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
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,18 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
describe('Frame', function() { | ||
|
||
var frame; | ||
|
||
beforeEach(function() { | ||
frame = new Frame(); | ||
}); | ||
it('can score two throws', function() { | ||
frame.score(5); | ||
frame.score(4); | ||
expect(frame.getFirstScore()).toBe(5); | ||
expect(frame.getSecondScore()).toBe(4); | ||
}); | ||
}); | ||
}()); |
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 |
---|---|---|
@@ -1,8 +1,15 @@ | ||
var Bowling = function() { | ||
this._pinsLeft = 10; | ||
this._frames = []; | ||
this._currentFrame = 0; | ||
}; | ||
Bowling.prototype.pinsLeft = function() { return this._pinsLeft; }; | ||
Bowling.prototype.throwBall = function(pinsHit) { this._pinsLeft -= pinsHit; }; | ||
Bowling.prototype.throwBall = function(pinsHit) { | ||
this._pinsLeft -= pinsHit; | ||
this.getCurrentFrame().score(pinsHit); | ||
}; | ||
Bowling.prototype.newFrame = function() { this._frames.push(new Frame()); }; | ||
Bowling.prototype.getFrames = function() { return this._frames; }; | ||
Bowling.prototype.getCurrentFrame = function() { | ||
return this._frames[this._currentFrame]; | ||
}; |
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 |
---|---|---|
@@ -1 +1,6 @@ | ||
var Frame = function() {}; | ||
var Frame = function() { | ||
this._score = []; | ||
}; | ||
Frame.prototype.score = function(pinsHit) { this._score.push(pinsHit); }; | ||
Frame.prototype.getFirstScore = function() { return this._score[0]; }; | ||
Frame.prototype.getSecondScore = function() { return this._score[1]; }; |