You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.0 KiB
45 lines
1.0 KiB
console.log("loaded bro");
|
|
|
|
var game = {
|
|
guesses: null,
|
|
guessedLetters: [],
|
|
words: [],
|
|
currentWord: new Word(),
|
|
startGame: function (wordsArray) {
|
|
this.guesses = 10;
|
|
this.guessedLetters = [];
|
|
for( var i = 0; i < wordsArray.length; i++ ) {
|
|
this.words.push(wordsArray[i]);
|
|
};
|
|
var randomWord = this.words[Math.floor(Math.random() * this.words.length)];
|
|
this.currentWord.getLetters(randomWord);
|
|
},
|
|
guess: function (letter) {
|
|
if ( this.guessedLetters.indexOf(letter) === -1 ) {
|
|
var found = this.currentWord.try(letter);
|
|
if (!found) {
|
|
this.guesses--;
|
|
}
|
|
this.guessedLetters.push(letter);
|
|
}
|
|
},
|
|
isOver: function () {
|
|
return (this.guesses === 0) || (this.currentWord.isFound());
|
|
},
|
|
overMessage: function () {
|
|
if ( this.guesses === 0 ) {
|
|
return "You Lose"
|
|
}
|
|
else if ( this.currentWord.isFound() ) {
|
|
return "You Win"
|
|
}
|
|
return undefined;
|
|
},
|
|
render: function () {
|
|
return [
|
|
this.currentWord.render(),
|
|
"Guesses: " + this.guesses,
|
|
this.overMessage()
|
|
].join("\n");
|
|
}
|
|
}; |