Compare commits
4 Commits
6aa9895174
...
master
Author | SHA1 | Date | |
---|---|---|---|
ba829f344f | |||
03c4fb9ea9 | |||
3913dfa1fa | |||
7214994e33 |
@ -138,6 +138,9 @@ up a letter faster.
|
||||
<br>
|
||||
<input type="radio" id="difficultyVeryHard" name="difficulty" value="really-hard">
|
||||
<label for="difficultyVeryHard">Very Hard (multiple words)</label>
|
||||
<br>
|
||||
<input type="radio" id="difficultySymbols" name="difficulty" value="symbols">
|
||||
<label for="difficultySymbols">(symbols)</label>
|
||||
</div>
|
||||
<br>
|
||||
<br>
|
||||
|
@ -40,7 +40,8 @@ const MORSE_MAP = {
|
||||
'!': '-.-.--',
|
||||
'=': '-...-',
|
||||
'+': '.-.-.',
|
||||
'-': '-....-'
|
||||
'-': '-....-',
|
||||
'clear': '........'
|
||||
};
|
||||
|
||||
const REVERSE_MORSE_MAP = function() {
|
||||
@ -51,6 +52,15 @@ const REVERSE_MORSE_MAP = function() {
|
||||
return reversed;
|
||||
}();
|
||||
|
||||
const SYMBOLS = [
|
||||
'.',
|
||||
'?',
|
||||
'!',
|
||||
'=',
|
||||
'+',
|
||||
'-'
|
||||
];
|
||||
|
||||
const COMMON_WORDS = {
|
||||
"description": "Common English words.",
|
||||
"commonWords":
|
||||
|
@ -125,6 +125,11 @@ function convertAsciiSentenceToMorse(asciiSentence) {
|
||||
return splitSentence.map(convertAsciiWordToMorse);
|
||||
}
|
||||
|
||||
function getRandomSymbol() {
|
||||
const randomIndex = Math.floor(Math.random() * SYMBOLS.length);
|
||||
return SYMBOLS[randomIndex];
|
||||
}
|
||||
|
||||
function getRandomLetter() {
|
||||
const randomIndex = Math.floor(Math.random() * 26);
|
||||
return Object.keys(MORSE_MAP)[randomIndex];
|
||||
@ -231,6 +236,10 @@ function getTarget() {
|
||||
case 'morse-hard':
|
||||
target = getRandomMorseWords();
|
||||
break;
|
||||
case 'symbols':
|
||||
target = getRandomSymbol();
|
||||
console.log(target);
|
||||
break;
|
||||
default:
|
||||
target = getRandomWords();
|
||||
break;
|
||||
@ -294,7 +303,7 @@ class ListeningGame {
|
||||
} else {
|
||||
const enteredWord = this.wordInput.value;
|
||||
// console.log('enteredWord: ', enteredWord, 'target: ', this.target);
|
||||
if (enteredWord.toUpperCase() == this.target) {
|
||||
if (enteredWord.trim().toUpperCase() == this.target.trim().toUpperCase()) {
|
||||
// If they got the word, show message and switch event listener.
|
||||
this.statusElement.textContent = 'Correct! Press enter to play a new round.';
|
||||
this.messageFound = true;
|
||||
@ -531,7 +540,11 @@ class InputGame {
|
||||
// TODO: handle letter being done.
|
||||
const currentLetterCombo = this.dotAndDashStack.join('');
|
||||
if (currentLetterCombo in REVERSE_MORSE_MAP) {
|
||||
if (REVERSE_MORSE_MAP[currentLetterCombo] == "clear") {
|
||||
this.letterStack = [];
|
||||
} else {
|
||||
this.letterStack.push(REVERSE_MORSE_MAP[currentLetterCombo]);
|
||||
}
|
||||
} else {
|
||||
// Push a question mark
|
||||
this.letterStack.push('?');
|
||||
@ -617,7 +630,7 @@ class InputGame {
|
||||
// console.log('target: \'' + this.target + '\'');
|
||||
// console.log('this.letterStack.join(\'\'): \'' + this.letterStack.join('') + '\'');
|
||||
// console.log(this.letterStack.join('') == this.target);
|
||||
if (this.letterStack.join('') == this.target) {
|
||||
if (this.letterStack.join('').toUpperCase() == this.target.toUpperCase()) {
|
||||
// console.log('match!');
|
||||
// Clear intervals
|
||||
clearTimeout(this.letterTimeout);
|
||||
|
Reference in New Issue
Block a user