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.
setup eslint and finished refactoring of Game functionality into Scor…
…eCard
- Loading branch information
Sam
authored and
Sam
committed
Jul 8, 2017
1 parent
864848b
commit fca3cd0
Showing
6 changed files
with
58 additions
and
60 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
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'] | ||
} | ||
}; |
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 |
---|---|---|
@@ -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!'; | ||
}; |
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,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); | ||
}; |
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,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); | ||
}; |