-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGame.js
29 lines (26 loc) · 874 Bytes
/
Game.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import * as ActionCreators from './state/ActionCreators';
import Store from './state/Store';
import * as Words from './Words';
export async function createNewGameAsync(dispatch) {
dispatch(ActionCreators.clearGame());
let word = await Words.randomWordAsync();
return dispatch(ActionCreators.newGame(word));
}
export function wordContainsLetter(word, letter) {
return word.includes(letter);
}
export function allLettersGuessed(word, guessedLetterSet) {
// console.log("allLettersGuessed('" + word + "', " + JSON.stringify(guessedLetterSet) + ")");
for (let i = 0; i < word.length; i++) {
let c = word.substr(i, 1);
if (!/[A-Z0-9]/.test(c)) {
continue;
}
// console.log("Checking for letter: '" + c + "'");
if (!guessedLetterSet[c]) {
// console.log("Missing letter: '" + c + "'");
return false;
}
}
return true;
}