Last active
December 19, 2016 17:46
-
-
Save CheezItMan/3034de6f979b27e36144bf14b1088018 to your computer and use it in GitHub Desktop.
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
// player.js | |
import Scrabble from 'scrabble'; | |
import Backbone from 'backbone'; | |
const Player = Backbone.Model.extend({ | |
defaults: { | |
}, | |
initialize: function(options) { | |
this.name = options.name; | |
this.plays = []; | |
}, | |
hasWon: function() { | |
return this.totalScore() > 100; | |
}, | |
totalScore: function() { | |
var total = 0; | |
for (var i = 0; i < this.plays.length; i++){ | |
total += Scrabble.score(this.plays[i]); | |
} | |
return total; | |
}, | |
highestScoringWord: function() { | |
return Scrabble.highestScoreFrom(this.plays); | |
}, | |
highestWordScore: function() { | |
return Scrabble.score(Scrabble.highestScoreFrom(this.plays)); | |
}, | |
play: function(word) { | |
if (this.hasWon()){ | |
return false; | |
} else { | |
this.plays.push(word); | |
} | |
} | |
} | |
); | |
export default Player; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment