Skip to content

Instantly share code, notes, and snippets.

@CheezItMan
Last active December 19, 2016 17:46
Show Gist options
  • Save CheezItMan/3034de6f979b27e36144bf14b1088018 to your computer and use it in GitHub Desktop.
Save CheezItMan/3034de6f979b27e36144bf14b1088018 to your computer and use it in GitHub Desktop.
// 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