Compare commits
9 Commits
926c748eea
...
master
Author | SHA1 | Date | |
---|---|---|---|
ba829f344f | |||
03c4fb9ea9 | |||
3913dfa1fa | |||
7214994e33 | |||
6aa9895174 | |||
6c4ed863cc | |||
4180fcca29 | |||
7c9d161719 | |||
c19c873b02 |
15
index.html
15
index.html
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<meta name="generator" content="Hugo 0.64.1">
|
<meta name="generator" content="Hugo 0.64.1">
|
||||||
<title>Little games to play with Morse Code in your browser · Caffeinspiration</title>
|
<title>Little games to play with Morse Code in your browser · Caffeinspiration</title>
|
||||||
<link rel="shortcut icon" href="https://alexanderell.is/images/favicon.ico">
|
<link rel="shortcut icon" href="">
|
||||||
<link rel="stylesheet" href="morse-code_files/style.css">
|
<link rel="stylesheet" href="morse-code_files/style.css">
|
||||||
<link rel="stylesheet" href="morse-code_files/highlight.css">
|
<link rel="stylesheet" href="morse-code_files/highlight.css">
|
||||||
|
|
||||||
@ -130,8 +130,17 @@ up a letter faster.
|
|||||||
<input type="radio" id="difficultyHard" name="difficulty" value="hard">
|
<input type="radio" id="difficultyHard" name="difficulty" value="hard">
|
||||||
<label for="difficultyHard">Hard (multiple short words)</label>
|
<label for="difficultyHard">Hard (multiple short words)</label>
|
||||||
<br>
|
<br>
|
||||||
|
<input type="radio" id="difficultyMorseEasy" name="difficulty" value="morse-easy">
|
||||||
|
<label for="difficultyMorseEasy">Morse easy (morse code shorthand)</label>
|
||||||
|
<br>
|
||||||
|
<input type="radio" id="difficultyMorseHard" name="difficulty" value="morse-hard">
|
||||||
|
<label for="difficultyMorseHard">Morse hard (multiple morse shorthand)</label>
|
||||||
|
<br>
|
||||||
<input type="radio" id="difficultyVeryHard" name="difficulty" value="really-hard">
|
<input type="radio" id="difficultyVeryHard" name="difficulty" value="really-hard">
|
||||||
<label for="difficultyVeryHard">Very Hard (multiple words)</label>
|
<label for="difficultyVeryHard">Very Hard (multiple words)</label>
|
||||||
|
<br>
|
||||||
|
<input type="radio" id="difficultySymbols" name="difficulty" value="symbols">
|
||||||
|
<label for="difficultySymbols">(symbols)</label>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
@ -153,10 +162,10 @@ up a letter faster.
|
|||||||
<br>
|
<br>
|
||||||
<legend>Use the Farnsworth method?</legend>
|
<legend>Use the Farnsworth method?</legend>
|
||||||
<div>
|
<div>
|
||||||
<input type="radio" id="yesFarnsworth" name="farnsworth" value="yes" checked="checked">
|
<input type="radio" id="yesFarnsworth" name="farnsworth" value="yes">
|
||||||
<label for="yesFarnsworth">Yes</label>
|
<label for="yesFarnsworth">Yes</label>
|
||||||
<br>
|
<br>
|
||||||
<input type="radio" id="noFarnsworth" name="farnsworth" value="no">
|
<input type="radio" id="noFarnsworth" name="farnsworth" value="no" checked="checked">
|
||||||
<label for="noFarnsworth">No</label>
|
<label for="noFarnsworth">No</label>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -39,8 +39,6 @@ function stopNotePlaying() {
|
|||||||
$("#beepLamp").removeClass("lamp-on")
|
$("#beepLamp").removeClass("lamp-on")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function sleep(ms) {
|
function sleep(ms) {
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
}
|
}
|
||||||
@ -127,6 +125,11 @@ function convertAsciiSentenceToMorse(asciiSentence) {
|
|||||||
return splitSentence.map(convertAsciiWordToMorse);
|
return splitSentence.map(convertAsciiWordToMorse);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRandomSymbol() {
|
||||||
|
const randomIndex = Math.floor(Math.random() * SYMBOLS.length);
|
||||||
|
return SYMBOLS[randomIndex];
|
||||||
|
}
|
||||||
|
|
||||||
function getRandomLetter() {
|
function getRandomLetter() {
|
||||||
const randomIndex = Math.floor(Math.random() * 26);
|
const randomIndex = Math.floor(Math.random() * 26);
|
||||||
return Object.keys(MORSE_MAP)[randomIndex];
|
return Object.keys(MORSE_MAP)[randomIndex];
|
||||||
@ -137,6 +140,11 @@ function getRandomWord() {
|
|||||||
return EASY_WORDS[randomIndex];
|
return EASY_WORDS[randomIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getRandomMorseWord() {
|
||||||
|
const randomIndex = Math.floor(Math.random() * MORSE_WORDS.length);
|
||||||
|
return MORSE_WORDS[randomIndex];
|
||||||
|
}
|
||||||
|
|
||||||
function getRandomEasyWords() {
|
function getRandomEasyWords() {
|
||||||
const totalLength = Math.floor(Math.random() * 3) + 2;
|
const totalLength = Math.floor(Math.random() * 3) + 2;
|
||||||
let finalSentence = ''
|
let finalSentence = ''
|
||||||
@ -149,11 +157,11 @@ function getRandomEasyWords() {
|
|||||||
return finalSentence;
|
return finalSentence;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRandomWords() {
|
function getRandomMorseWords() {
|
||||||
const totalLength = Math.floor(Math.random() * 4) + 2;
|
const totalLength = Math.floor(Math.random() * 4) + 2;
|
||||||
let finalSentence = ''
|
let finalSentence = ''
|
||||||
for (let i = 0; i < totalLength; i++) {
|
for (let i = 0; i < totalLength; i++) {
|
||||||
finalSentence += ALL_WORDS[Math.floor(Math.random() * ALL_WORDS.length)];
|
finalSentence += MORSE_WORDS[Math.floor(Math.random() * MORSE_WORDS.length)];
|
||||||
if (i < totalLength - 1) {
|
if (i < totalLength - 1) {
|
||||||
finalSentence += ' ';
|
finalSentence += ' ';
|
||||||
}
|
}
|
||||||
@ -222,6 +230,16 @@ function getTarget() {
|
|||||||
case 'hard':
|
case 'hard':
|
||||||
target = getRandomEasyWords();
|
target = getRandomEasyWords();
|
||||||
break;
|
break;
|
||||||
|
case 'morse-easy':
|
||||||
|
target = getRandomMorseWord();
|
||||||
|
break;
|
||||||
|
case 'morse-hard':
|
||||||
|
target = getRandomMorseWords();
|
||||||
|
break;
|
||||||
|
case 'symbols':
|
||||||
|
target = getRandomSymbol();
|
||||||
|
console.log(target);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
target = getRandomWords();
|
target = getRandomWords();
|
||||||
break;
|
break;
|
||||||
@ -285,7 +303,7 @@ class ListeningGame {
|
|||||||
} else {
|
} else {
|
||||||
const enteredWord = this.wordInput.value;
|
const enteredWord = this.wordInput.value;
|
||||||
// console.log('enteredWord: ', enteredWord, 'target: ', this.target);
|
// 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.
|
// If they got the word, show message and switch event listener.
|
||||||
this.statusElement.textContent = 'Correct! Press enter to play a new round.';
|
this.statusElement.textContent = 'Correct! Press enter to play a new round.';
|
||||||
this.messageFound = true;
|
this.messageFound = true;
|
||||||
@ -522,7 +540,11 @@ class InputGame {
|
|||||||
// TODO: handle letter being done.
|
// TODO: handle letter being done.
|
||||||
const currentLetterCombo = this.dotAndDashStack.join('');
|
const currentLetterCombo = this.dotAndDashStack.join('');
|
||||||
if (currentLetterCombo in REVERSE_MORSE_MAP) {
|
if (currentLetterCombo in REVERSE_MORSE_MAP) {
|
||||||
this.letterStack.push(REVERSE_MORSE_MAP[currentLetterCombo]);
|
if (REVERSE_MORSE_MAP[currentLetterCombo] == "clear") {
|
||||||
|
this.letterStack = [];
|
||||||
|
} else {
|
||||||
|
this.letterStack.push(REVERSE_MORSE_MAP[currentLetterCombo]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Push a question mark
|
// Push a question mark
|
||||||
this.letterStack.push('?');
|
this.letterStack.push('?');
|
||||||
@ -608,7 +630,7 @@ class InputGame {
|
|||||||
// console.log('target: \'' + this.target + '\'');
|
// console.log('target: \'' + this.target + '\'');
|
||||||
// console.log('this.letterStack.join(\'\'): \'' + this.letterStack.join('') + '\'');
|
// console.log('this.letterStack.join(\'\'): \'' + this.letterStack.join('') + '\'');
|
||||||
// console.log(this.letterStack.join('') == this.target);
|
// console.log(this.letterStack.join('') == this.target);
|
||||||
if (this.letterStack.join('') == this.target) {
|
if (this.letterStack.join('').toUpperCase() == this.target.toUpperCase()) {
|
||||||
// console.log('match!');
|
// console.log('match!');
|
||||||
// Clear intervals
|
// Clear intervals
|
||||||
clearTimeout(this.letterTimeout);
|
clearTimeout(this.letterTimeout);
|
||||||
|
Reference in New Issue
Block a user