diff --git a/README.md b/README.md
index 5bb7712207..76c4d0cfcf 100644
--- a/README.md
+++ b/README.md
@@ -6,21 +6,21 @@ Bowling Challenge
To run tests type the following in your terminal:
-'''
-$ git clone https://github.com/sblausten/bowling-challenge.git
-$ cd bowling-challenge
-$ open SpecRunner.html
+'''bash
+git clone https://github.com/sblausten/bowling-challenge.git
+cd bowling-challenge
+open SpecRunner.html
'''
## User stories
-- As a player
+- As a player
so that I can play
I want to start a game of bowling
-- As a player
-so that I can score
-I want to roll
+- As a player
+so that I can score
+I want to roll
- As a player
I want to have two rolls per frame
@@ -28,28 +28,25 @@ I want to have two rolls per frame
- As a player
I want to end a frame when I score 10 in first roll
-- As a player
+- As a player
I want to keep track of my score for each roll including skipped ones
-- As a player
+- As a player
I want to keep track of my score for each frame including bonuses
-As a player
+As a player
I want to add this frame to the last frame if it was a strike
-As a player
+As a player
I want to add the first roll to the last frame if it was a spare
-As a player
+- As a player
I want the game to end after 10 frames
-As a player
-I want the game to continue after 10 frames if the last frame is a strike
-
-As a player
+- As a player
I want the game to only continue past 10 frames when the frame is a strike
-As a player
+- As a player
I want the game to end after 13 frames if the last four frames are strikes.
diff --git a/SpecRunner.html b/SpecRunner.html
index e2804e6d87..5d600cb6e3 100644
--- a/SpecRunner.html
+++ b/SpecRunner.html
@@ -1,5 +1,6 @@
+
Jasmine Spec Runner v2.6.1
@@ -26,4 +27,5 @@
+
diff --git a/package.json b/package.json
index 9895ea2fbc..8a042457cb 100644
--- a/package.json
+++ b/package.json
@@ -3,6 +3,10 @@
"version": "1.0.0",
"description": "bowlin-challenge",
"main": "index.js",
+ "scripts": {
+ "test": "jasmine-node spec",
+ "lint": "eslint ./src"
+ },
"directories": {
"doc": "docs"
},
@@ -12,11 +16,11 @@
"devDependencies": {
"eslint": "^3.19.0",
"eslint-config-standard": "^10.2.1",
+ "eslint-plugin-import": "^2.7.0",
+ "eslint-plugin-node": "^5.1.0",
"eslint-plugin-promise": "^3.5.0",
- "eslint-plugin-standard": "^3.0.1"
- },
- "scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
+ "eslint-plugin-standard": "^3.0.1",
+ "jasmine-node": "^1.14.5"
},
"repository": {
"type": "git",
diff --git a/spec/FrameSpec.js b/spec/FrameSpec.js
index 36e5a121e5..30044e5fe5 100644
--- a/spec/FrameSpec.js
+++ b/spec/FrameSpec.js
@@ -1,52 +1,52 @@
'use strict';
describe('Frame', function() {
- var frame;
- beforeEach(function() {
- frame = new Frame();
+ var frame;
+ beforeEach(function() {
+ frame = new Frame();
+ });
+ describe('roll', function() {
+ it('returns a number between 0 and 10', function() {
+ frame.roll();
+ expect(frame.getScore()[0]).toBeLessThan(11);
});
- describe('roll', function() {
- it('returns a number between 0 and 10', function() {
- frame.roll();
- expect(frame.getScore()[0]).toBeLessThan(11);
- });
- it('does not roll more than 2 times', function() {
- for (var i = 0; i < 3; i++) {
- frame.roll();
- }
- expect(frame.getScore().length).toBeLessThan(3);
- });
+ it('does not roll more than 2 times', function() {
+ for (var i = 0; i < 3; i++) {
+ frame.roll();
+ }
+ expect(frame.getScore().length).toBeLessThan(3);
});
- describe('isSpare', function() {
- it('sets this.spare to true when first and second score = 10', function() {
- spyOn(Math, "random").and.returnValues(0.51, 0.9);
- frame.roll();
- frame.roll();
- expect(frame.getScore()).toEqual([5, 5]);
- expect(frame.getSpare()).toBeTrue;
- });
- it('does not set spare to true when strike', function() {
- spyOn(Math, "random").and.returnValue(0.97);
- frame.roll();
- frame.roll();
- expect(frame.getScore()).toEqual([10, 0]);
- expect(frame.getSpare()).toBeFalse;
- });
+ });
+ describe('isSpare', function() {
+ it('sets this.spare to true when first and second score = 10', function() {
+ spyOn(Math, "random").and.returnValues(0.51, 0.9);
+ frame.roll();
+ frame.roll();
+ expect(frame.getScore()).toEqual([5, 5]);
+ expect(frame.getSpare()).toBeTrue;
});
- describe('isStrike', function() {
- it('sets this.strike to true when first score = 10', function() {
- spyOn(Math, "random").and.returnValues(0.95, 0.5);
- frame.roll();
- frame.roll();
- expect(frame.getScore()).toEqual([10, 0]);
- expect(frame.getStrike()).toBeTrue;
- });
- it('does not set strike to true when second roll is 10', function() {
- spyOn(Math, "random").and.returnValues(0, 0.97);
- frame.roll();
- frame.roll();
- expect(frame.getScore()).toEqual([0, 10]);
- expect(frame.getStrike()).toBeFalse;
- });
+ it('does not set spare to true when strike', function() {
+ spyOn(Math, "random").and.returnValue(0.97);
+ frame.roll();
+ frame.roll();
+ expect(frame.getScore()).toEqual([10, 0]);
+ expect(frame.getSpare()).toBeFalse;
});
-});
\ No newline at end of file
+ });
+ describe('isStrike', function() {
+ it('sets this.strike to true when first score = 10', function() {
+ spyOn(Math, "random").and.returnValues(0.95, 0.5);
+ frame.roll();
+ frame.roll();
+ expect(frame.getScore()).toEqual([10, 0]);
+ expect(frame.getStrike()).toBeTrue;
+ });
+ it('does not set strike to true when second roll is 10', function() {
+ spyOn(Math, "random").and.returnValues(0, 0.97);
+ frame.roll();
+ frame.roll();
+ expect(frame.getScore()).toEqual([0, 10]);
+ expect(frame.getStrike()).toBeFalse;
+ });
+ });
+});
diff --git a/spec/GameSpec.js b/spec/GameSpec.js
index 0a41abbf95..18acff5482 100644
--- a/spec/GameSpec.js
+++ b/spec/GameSpec.js
@@ -1,40 +1,42 @@
'use strict';
describe('Game', function() {
- var game;
- beforeEach(function() {
- game = new Game();
+ var game;
+ beforeEach(function() {
+ game = new Game();
+ });
+ describe('getScoreCard', function() {
+ it('returns each frame that has been started', function() {
+ for (var i = 0; i < 6; i++) {
+ game.play();
+ }
+ expect(game.getScoreCard().length).toEqual(6);
});
- describe('getScoreCard', function() {
- it('returns each frame that has been started', function() {
- for (var i = 0; i < 6; i++) {
- game.play();
- }
- expect(game.getScoreCard().length).toEqual(6);
- });
- xit('returns both rolls for each frame', function() {
- for (var i = 0; i < 6; i++) {
- game.play();
- }
- expect(game.getScoreCard()[1].length).toEqual(2);
- });
+ xit('returns both rolls for each frame', function() {
+ for (var i = 0; i < 6; i++) {
+ game.play();
+ }
+ expect(game.getScoreCard()[1].length).toEqual(2);
});
- describe('play', function() {
- it('rolls a ball and updates the frame score', function() {
- spyOn(Math, "random").and.returnValue(0.5);
- game.play();
- expect(game.getScoreCard()).toEqual([[5]]);
- });
+ });
+ describe('play', function() {
+ it('rolls a ball and updates the frame score', function() {
+ spyOn(Math, "random").and.returnValue(0.5);
+ game.play();
+ expect(game.getScoreCard()).toEqual([
+ [5]
+ ]);
});
- describe('getTotalScore', function() {
- it('returns total score', function() {
- spyOn(Math, "random").and.returnValues(0.5, 0.9, 0.1, 0.5);
- for (var i = 0; i < 5; i++) {
- game.play();
- console.log(game.getScoreCard()[i]);
- }
- expect(game.getTotalScore()).toEqual( );
- });
+ });
+ describe('getTotalScore', function() {
+ it('returns total score', function() {
+ spyOn(Math, "random").and.returnValues(0.5, 0.9, 0.1, 0.5);
+ for (var i = 0; i < 5; i++) {
+ game.play();
+ console.log(game.getScoreCard()[i]);
+ }
+ expect(game.getTotalScore()).toEqual();
});
+ });
-});
\ No newline at end of file
+});
diff --git a/spec/RollSpec.js b/spec/RollSpec.js
index ec71959ac1..3ef86bae10 100644
--- a/spec/RollSpec.js
+++ b/spec/RollSpec.js
@@ -1,23 +1,23 @@
'use strict';
describe('Roll', function() {
- var roll;
- beforeEach(function() {
- roll = new Roll();
- });
- describe('randomInt', function() {
- it('returns random number between 0 and the remaining pins for a frame',
- function () {
- expect(roll.randomInt(10)).toBeLessThan(11);
- expect(roll.randomInt(7)).toBeLessThan(8);
- expect(roll.randomInt(5)).toBeLessThan(6);
- expect(roll.randomInt(2)).toBeLessThan(3);
- });
- });
- describe('score', function() {
- it('returns random number between 0 and the remaining pins for a frame',
- function () {
- expect(roll.score(10)).toBeLessThan(11);
- });
- });
-});
\ No newline at end of file
+ var roll;
+ beforeEach(function() {
+ roll = new Roll();
+ });
+ describe('randomInt', function() {
+ it('returns random number between 0 and the remaining pins for a frame',
+ function() {
+ expect(roll.randomInt(10)).toBeLessThan(11);
+ expect(roll.randomInt(7)).toBeLessThan(8);
+ expect(roll.randomInt(5)).toBeLessThan(6);
+ expect(roll.randomInt(2)).toBeLessThan(3);
+ });
+ });
+ describe('score', function() {
+ it('returns random number between 0 and the remaining pins for a frame',
+ function() {
+ expect(roll.score(10)).toBeLessThan(11);
+ });
+ });
+});
diff --git a/src/Frame.js b/src/Frame.js
index 68dd0ac35e..eeae2ef6ac 100644
--- a/src/Frame.js
+++ b/src/Frame.js
@@ -1,41 +1,40 @@
'use strict';
function Frame() {
- this.score = [];
+ this.score = [];
}
Frame.prototype.roll = function() {
- if (this.rollCount() <= 1 && this.remainder() > 0) {
- var roll = new Roll().score(this.remainder());
- this.updateScore(roll);
- } else if (this.rollCount() <= 1) {
- this.updateScore(0);
- }
- this.checkEnd();
+ if (this.rollCount() <= 1 && this.remainder() > 0) {
+ var roll = new Roll().score(this.remainder());
+ this.updateScore(roll);
+ } else if (this.rollCount() <= 1) {
+ this.updateScore(0);
+ }
+ this.checkEnd();
};
Frame.prototype.rollCount = function() {
- return this.getScore().length;
+ return this.getScore().length;
};
Frame.prototype.checkEnd = function() {
- if (this.rollCount() === 2) {
- scoreCard.updateFrames(this.getScore());
- }
+ if (this.rollCount() === 2) {
+ scoreCard.updateFrames(this.getScore());
+ }
};
Frame.prototype.getScore = function() {
- return this.score;
+ return this.score;
};
Frame.prototype.updateScore = function(rollScore) {
- this.score.push(rollScore);
+ this.score.push(rollScore);
};
Frame.prototype.remainder = function() {
- if (this.rollCount() > 0) {
- return 10 - this.score[0];
- }
- return 10;
+ if (this.rollCount() > 0) {
+ return 10 - this.score[0];
+ }
+ return 10;
};
-
diff --git a/src/Game.js b/src/Game.js
index 7f6f4a50cd..ef71d6fb15 100644
--- a/src/Game.js
+++ b/src/Game.js
@@ -1,28 +1,40 @@
'use strict';
function Game() {
- this.scoreCard = [];
- this.totalScore = 0;
- this.turn = 0;
- this.MAX_TURNS = 10;
- this.currentFrame = null;
- const scoreCard = new ScoreCard();
+ this.scoreCard = [];
+ this.totalScore = 0;
+ this.MAX_FRAMES = 10;
+ this.currentFrame = null;
+ const scoreCard = new ScoreCard();
}
Game.prototype.play = function() {
- this.roll();
- this.checkFrame();
- this.updateScoreCard(frame.getScore());
+ this.roll();
+ this.checkFrame();
};
-Game.prototype.rollCount = function() {
- this.get
+Game.prototype.checkGameEnd = function() {
+ if (this.turn < this.MAX_TURNS ||
+ (scorecard[scorecard.length - 1][0] === 10 || scorecard.length < 14)) {
+ return;
+ }
+ this.endGame();
+};
+
+Game.prototype.countFrames = function() {
+ return scorecard.length;
+};
+
+Game.prototype.checkFrame = function() {
+ if (this.currentFrame === null) {
+ this.currentFrame = new Frame;
+ }
};
Game.prototype.roll = function() {
- if (this.currentFrame === null){
- this.currentFrame = new Frame;
- }
- this.currentFrame.roll();
+ this.currentFrame.roll();
};
+Gamr.prototype.endGame = function() {
+ return "Game over!";
+};
diff --git a/src/Roll.js b/src/Roll.js
index 4bb48765c8..aa331ea1ea 100644
--- a/src/Roll.js
+++ b/src/Roll.js
@@ -1,14 +1,12 @@
'use strict';
-function Roll() {
-}
+function Roll() {}
Roll.prototype.randomInt = function(remainder) {
- var max = Math.round(remainder);
- return Math.round(Math.random() * (max));
+ var max = Math.round(remainder);
+ return Math.round(Math.random() * (max));
};
Roll.prototype.score = function(remainder) {
- return this.randomInt(remainder);
+ return this.randomInt(remainder);
};
-
diff --git a/src/ScoreCard.js b/src/ScoreCard.js
index a191e7fde6..413729496d 100644
--- a/src/ScoreCard.js
+++ b/src/ScoreCard.js
@@ -1,22 +1,20 @@
-
function ScoreCard() {
- this.frames = [];
- this.total = 0;
+ this.frames = [];
+ this.total = 0;
}
Game.prototype.getTotal = function() {
- return this.totalScore;
+ return this.totalScore;
};
Game.prototype.getFrames = function() {
- return this.scoreCard;
+ return this.scoreCard;
};
Game.prototype.updateTotal = function(subtotal) {
- this.totalScore += subtotal;
+ this.totalScore += subtotal;
};
Game.prototype.updateFrames = function(frame) {
- this.scoreCard.push(frame);
+ this.scoreCard.push(frame);
};
-