Skip to content

Commit

Permalink
setup eslint and finished refactoring of Game functionality into Scor…
Browse files Browse the repository at this point in the history
…eCard
  • Loading branch information
Sam authored and Sam committed Jul 8, 2017
1 parent 864848b commit fca3cd0
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 60 deletions.
20 changes: 14 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
module.exports = {
"extends": "standard",
"plugins": [
"standard",
"promise"
]
};
'extends': 'standard',
'plugins': [
'standard',
'promise'
],
'env': {
'browser': true,
'jasmine': true,
'node': true
},
'rules': {
'semi': [1, 'always']
}
};
37 changes: 11 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,27 @@ jasmine

## User stories

- As a player
so that I can play
I want to start a game of bowling
-[] I want to start a game of bowling

- As a player
so that I can score
I want to roll
-[] I want to roll

- As a player
I want to have two rolls per frame
-[] I want to have two rolls per frame

- As a player
I want to end a frame when I score 10 in first roll
-[] I want to end a frame when I score 10 in first roll

- As a player
I want to keep track of my score for each roll including skipped ones
-[] I want to keep track of my score for each roll including skipped ones

- As a player
I want to keep track of my score for each frame including bonuses
-[] I want to keep track of my score for each frame including bonuses

As a player
I want to add this frame to the last frame if it was a strike
-[] I want to add this frame to the last frame if it was a strike

As a player
I want to add the first roll to the last frame if it was a spare
-[] I want to add the first roll to the last frame if it was a spare

- As a player
I want the game to end after 10 frames

- As a player
I want the game to only continue past 10 frames when the frame is a strike

- As a player
I want the game to end after 13 frames if the last four frames are strikes.
-[] I want the game to end after 10 frames

-[] I want the game to only continue past 10 frames when the frame is a strike

-[] I want the game to end after 13 frames if the last four frames are strikes.



Expand Down
14 changes: 8 additions & 6 deletions spec/RollSpec.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
'use strict';

describe('Roll', function() {
describe('Roll', function () {
var roll;
beforeEach(function() {
beforeEach(function () {
roll = new Roll();
});
describe('randomInt', function() {

describe('randomInt', function () {
it('returns random number between 0 and the remaining pins for a frame',
function() {
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() {

describe('score', function () {
it('returns random number between 0 and the remaining pins for a frame',
function() {
function () {
expect(roll.score(10)).toBeLessThan(11);
});
});
Expand Down
21 changes: 11 additions & 10 deletions src/Game.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
'use strict';
var scoreCard;

function Game() {
function Game () {
this.scoreCard = [];
this.totalScore = 0;
this.MAX_FRAMES = 10;
this.currentFrame = null;
const scoreCard = new ScoreCard();
scoreCard = new ScoreCard();
}

Game.prototype.play = function() {
Game.prototype.play = function () {
this.roll();
this.checkFrame();
};

Game.prototype.checkGameEnd = function() {
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() {
Game.prototype.countFrames = function () {
return scorecard.length;
};

Game.prototype.checkFrame = function() {
Game.prototype.checkFrame = function () {
if (this.currentFrame === null) {
this.currentFrame = new Frame;
this.currentFrame = new Frame();
}
};

Game.prototype.roll = function() {
Game.prototype.roll = function () {
this.currentFrame.roll();
};

Gamr.prototype.endGame = function() {
return "Game over!";
Game.prototype.endGame = function () {
return 'Game over!';
};
6 changes: 3 additions & 3 deletions src/Roll.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

function Roll() {}
function Roll () {}

Roll.prototype.randomInt = function(remainder) {
Roll.prototype.randomInt = function (remainder) {
var max = Math.round(remainder);
return Math.round(Math.random() * (max));
};

Roll.prototype.score = function(remainder) {
Roll.prototype.score = function (remainder) {
return this.randomInt(remainder);
};
20 changes: 11 additions & 9 deletions src/ScoreCard.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
function ScoreCard() {
'use strict';

function ScoreCard () {
this.frames = [];
this.total = 0;
}

Game.prototype.getTotal = function() {
return this.totalScore;
ScoreCard.prototype.getTotal = function () {
return this.total;
};

Game.prototype.getFrames = function() {
return this.scoreCard;
ScoreCard.prototype.getFrames = function () {
return this.frames;
};

Game.prototype.updateTotal = function(subtotal) {
this.totalScore += subtotal;
ScoreCard.prototype.updateTotal = function (subtotal) {
this.total += subtotal;
};

Game.prototype.updateFrames = function(frame) {
this.scoreCard.push(frame);
ScoreCard.prototype.updateFrames = function (frame) {
this.frames.push(frame);
};

0 comments on commit fca3cd0

Please sign in to comment.