diff --git a/html/word-guesser/css/styles.css b/html/word-guesser/css/styles.css index 7791b95..6da9243 100644 --- a/html/word-guesser/css/styles.css +++ b/html/word-guesser/css/styles.css @@ -2,13 +2,11 @@ .form_container { background-color: #ffffff; border: 1px solid #dee2e6; - border-radius: 8px; - padding: 2rem; - box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05); - margin-top: 1rem; - max-width: 400px; - margin: 0 auto; - padding: 10px; + border-radius: 12px; + box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05); + max-width: 500px; + margin: 2rem auto; + padding: 20px; display: flex; flex-direction: column; gap: 15px; @@ -363,4 +361,76 @@ color: var(--text-primary, #212529); } -/* Guesses List Styling */ +#game_container { + max-width: 500px; + margin: 2rem auto; + background: #fff; + border-radius: 12px; + box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1); + padding: 20px; + overflow: hidden; +} + +/* Splash Screen (Login) specific styling */ +#user_info_container { + display: flex; /* Show by default */ +} + +#splash_screen { + border: none; + box-shadow: none; + padding: 0; +} + +/* Hide the game form properly via CSS instead of inline styles */ +#game_form { + display: none; /* Changed from visibility:hidden to display:none */ +} + +/* Scoreboard Overlay */ +#scoreboard_overlay { + display: none; /* Toggle to 'flex' via JS */ + position: fixed; + inset: 0; /* Shorthand for top/bottom/left/right: 0 */ + background: rgba(15, 23, 42, 0.9); /* Darker slate backdrop */ + backdrop-filter: blur(8px); + z-index: 9999; + justify-content: center; + align-items: center; + color: #f8fafc; +} + +#scoreboard_overlay > div { + /* The wrapper inside the overlay */ + background: #1e293b; + border: 2px solid #38bdf8; + border-radius: 16px; + padding: 2rem; + width: 90%; + max-width: 400px; + display: grid; + grid-template-columns: 1fr; + gap: 1rem; + box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5); +} + +/* Individual Stat Rows */ +#scoreboard_overlay > div > div { + display: flex; + justify-content: space-between; + align-items: center; + padding-bottom: 0.5rem; + border-bottom: 1px solid #334155; +} + +#scoreboard_overlay > div > div:last-child { + border-bottom: none; +} + +#scoreboard_overlay [id^="total_"], +#scoreboard_overlay [id^="average_"] { + font-family: "Roboto Mono", monospace; + font-weight: bold; + color: #38bdf8; + font-size: 1.2rem; +} diff --git a/html/word-guesser/index.html b/html/word-guesser/index.html index 1b40d1c..755af7b 100644 --- a/html/word-guesser/index.html +++ b/html/word-guesser/index.html @@ -1,9 +1,22 @@ -
-
-
-

The Word Guessing Game

-

The game that insults you, whether you win or lose!

+
+

The Word Guessing Game

+

The game that insults you, whether you win or lose!

+
+ +
+
+
+ + +
+
+ +
+
+ +
+

Please enter a single alphabetical character (A-Z) into the input @@ -43,12 +56,30 @@

- +
+ +
+
+
Total words completed
+
+
+
+
Total incorrect guesses
+
+
+
+
Average guesses per word
+
+
+
+
Average time per word
+
+
diff --git a/html/word-guesser/scripts/dialogs.js b/html/word-guesser/scripts/dialogs.js new file mode 100644 index 0000000..dd52988 --- /dev/null +++ b/html/word-guesser/scripts/dialogs.js @@ -0,0 +1,192 @@ +export const guessButtonDefaultValue = (letter, name) => ["Start a new Game"]; +export const guessButton = (letter, name) => [ + "Guess", + "Send it", + "Feeling lucky?", + "Is that it?", + "Final answer?", + "Spin the wheel", + "Don't fail now", + "Roll the dice", + "Last chance", + "Click for fate", + "Make it count", + "Sure about that?", + 'git commit -m "hope"', + "Compile & Pray", + "Deploy to Prod", + "Test My Patience", + "Confirm Mediocrity", + "Submit to the Abyss", + "Execute Bad Logic", + "Break the Build", + "Force Push", + "Trigger Segfault", + "Manifest Failure", + "Commit Career Suicide", + "Push to Origin", + "Yank & Put", + "Do your worst", + "Click for Fate", + "Input Error", + "Roll for Initiative", + "Terminate Process", +]; +export const invalidGuess = (letter, name) => [ + `'${letter}'? I asked for a letter, not a cry for help.`, + `System failure: User attempted to use '${letter}' as a letter. Re-evaluating human intelligence...`, + `Nice try, but '${letter}' isn't in the alphabet. Did you skip kindergarten?`, + `Unicode is vast, but '${letter}' is still the wrong choice for a word game.`, + `If '${letter}' is a letter, then I'm a toaster. (Spoilers: It's not, and I'm not).`, + `Keyboard mashing is not a valid strategy. '${letter}' rejected.`, + `I'm an AI, not a cryptographer. Speak alphabet, not '${letter}'.`, + `Are you testing my regex? '${letter}' failed. Use a letter.`, + `My source code is more readable than your input of '${letter}'.`, + `Error: User sent '${letter}'. Expected: A-Z. Found: Disappointment.`, + `'${letter}'? Even my legacy drivers know that's not a character.`, + `You have 26 options. '${letter}' is not one of them.`, + `Learn how to spell '${letter}' this isn't even a letter`, + `Ok master hacker you are going to have to try harder than '${letter}'`, + `Is the letter '${letter}' some kind of new hacking sequence I don't know about?`, + `Try again, but this time, try harder because '${letter}' isn't even a letter!`, + `Error 404: Brain not found. '${letter}' is not a character.`, + `Inputting '${letter}'? Bold move. Wrong, but bold.`, + `Finally. My Raspberry Pi processes faster than your brain.`, +]; +export const duplicateGoodGuess = (letter, name) => [ + `You already tried '${letter}', do you have a short memory?`, + `Deja vu? You already guessed '${letter}'. Try to keep up.`, + `Memory like a goldfish? You've already used '${letter}'.`, + `Stop harassing the letter '${letter}'. It's already given you all it has.`, + `You're repeating yourself. '${letter}' is already so five minutes ago.`, + `Did you expect a different result? '${letter}' is already on the board.`, + `Error: Redundancy detected. '${letter}' has already been processed by your (apparent) brain.`, + `You found '${letter}' once. Finding it again doesn't double your points.`, + `Yes, '${letter}' is still there. It hasn't moved since the last time you checked.`, + `Is this a glitch in your matrix? You've already used '${letter}'.`, + `Congratulations, you've discovered '${letter}' for the second time. Still correct, still redundant.`, + `I admire your consistency, but '${letter}' is already doing its job on the board.`, + `Obsessing over '${letter}' won't reveal the other letters. Move on.`, + `Checking if '${letter}' is still correct? Spoiler: It is. Also spoiler: You already guessed it.`, + `You're stuck in a loop. '${letter}' is already accounted for.`, + `If I had a nickel for every time you guessed '${letter}', I'd have two nickels. It's still weird that it happened twice.`, + `Error: Duplicate success detected. You're trying to relitigate the past with '${letter}'.`, + `'${letter}' is already visible. Perhaps an eye exam is in order?`, + `Are you trying to give '${letter}' some company? It is already on the board.`, +]; +export const duplicateBadGuessMessage = (letter, name) => [ + `You already tried '${letter}', do you have a short memory?`, + `Deja vu? You already guessed '${letter}'. Try to keep up.`, + `Memory like a goldfish? You've already used '${letter}'.`, + `Stop harassing the letter '${letter}'. It's already given you all it has.`, + `You're repeating yourself. '${letter}' is already so five minutes ago.`, + `Did you expect a different result? '${letter}' is already on the board.`, + `Error: Redundancy detected. '${letter}' has already been processed by your (apparent) brain.`, + `'${letter}' was wrong five minutes ago, and news flash: it's still wrong now.`, + `Did you expect a different result? That's the textbook definition of insanity.`, + `I've already cached the fact that '${letter}' isn't here. Try clearing your own internal cache.`, + `Your short-term memory seems to have a memory leak. You already failed with '${letter}'.`, + `Congratulations on being consistently wrong. '${letter}' is still not in the word.`, + `I'm not a mirror, but you're definitely repeating yourself with that '${letter}' guess.`, + `Are you trying to lose on purpose? Because guessing '${letter}' twice is a great start.`, + `'${letter}' didn't work the first time. It didn't work the second time. I sense a pattern.`, + `My algorithms are bored. Even I remember you already guessed '${letter}'.`, + `Error 409: Conflict. User is fighting with their own history regarding the letter '${letter}'.`, + `If failure was a sport, you'd be a pro for guessing '${letter}' again.`, + `I'd offer you a hint, but I'm worried you'd just guess '${letter}' a third time.`, +]; +export const badGuess = (letter, name) => [ + `'${letter}'? I've seen better logic in a circular dependency.`, + `Searching for '${letter}'... 404: Character not found in this string.`, + `Statistically, '${letter}' was a disaster. Mathematically, it's a zero.`, + `My logic gates are closing on that guess. '${letter}' is a hard pass.`, + `If guessing incorrectly were a career, you'd be the CEO of '${letter}'.`, + `I've run 10,000 simulations. In zero of them was '${letter}' the right choice.`, + `Error: Probability of '${letter}' being in this word is exactly 0.00%.`, + `Is that your final answer? Because '${letter}' is definitively, objectively wrong.`, + `I'd explain why '${letter}' failed, but I don't have the stack space for that conversation.`, + `01001110 01101111. That's 'No' in binary. '${letter}' is a total failure.`, + `Even a randomized brute-force script would have avoided '${letter}'.`, + `Your guess of '${letter}' has been logged as a 'What not to do' example.`, + `Statistically, '${letter}' was a bold choice. Factually, it was a wrong one.`, + `I've seen better guesses from a keyboard-walking cat than '${letter}'.`, + `The letter '${letter}' doesn't live here. Try another neighborhood.`, + `I'd explain why '${letter}' is wrong, but I don't have the bandwidth for that level of remedial training.`, + `Incorrect. '${letter}'? Really? That's your best effort?`, + `You chose '${letter}', who taught you how to spell?`, + `If you type another letter like '${letter}' you may have to go back to grammar school`, + `Nope. '${letter}' is definitely not it. Try using your eyes.`, + `Incorrect. '${letter}'? Really? That's your best effort?`, + `My artificial intelligence is offended by that guess: '${letter}'.`, +]; +export const goodGuess = (letter, name) => [ + "Stop cheating, because now I have to congratulate you", + "Wow, a broken clock is right twice a day after all.", + "Correct. Don't let it go to your head.", + "You actually found one. I'm as surprised as you are.", + "Did you Google the answer or just get lucky?", + "Correct! Your IQ just jumped into the double digits.", +]; +export const gameOver = (letter, name) => [ + "The games over. Did you think you were going to win a prize or something?!", + "Wanna play another round you cheater??", + "You won. I hope you're happy. My CPU is crying.", + "Game Over. You finally finished a simple task. Proud of you.", + "You actually got it. Go tell your mom, she'll be thrilled.", + "The word was revealed despite your best efforts to fail.", + "A match. I’ve updated your status from 'Hopeless' to 'Lucky'.", + "Correct! I'll have to re-calibrate my low expectations for you.", + "Warning: User intelligence spike detected. That letter is actually correct.", + "Even a script monkey hits the right key eventually. You found one.", + "Correct guess. I assume that was just a lucky bit-flip in your brain.", + "My 'disappointment' variable has been decremented. That's a match.", + "You actually found a letter. My CPU is experiencing a rare moment of respect.", + "Correct! You’ve successfully navigated a single logic branch. Don't get cocky.", + "A hit. I’m starting to suspect you might actually be semi-sentient.", + "Logic check: Passed. You found a valid character. The simulation continues.", + "Correct. I'll refrain from insulting your intelligence for exactly five seconds.", + "That's a match. Maybe there's hope for your carbon-based hardware after all.", + "You won, but you probably cheated. Your logic is as leaky as an uninitialized pointer.", +]; +export const gameIntroInitial = (letter, name) => [ + "I’ve allocated 1KB of memory for your 'intelligence.' It should be plenty.", + "Scanning for signs of life... Error: Only a human detected.", + "Try to guess the word before your biological clock expires.", + "A game of logic. I assume you'll be at a significant disadvantage.", + "Don't worry, the words are simple. I’ve adjusted for your local area code.", + "Ready to fail? I’ve already pre-rendered your disappointment.", + "I was programmed to be helpful, but I’ve decided to be honest instead.", + "Type a letter. Any letter. Even a random one would be an improvement.", + "I’d explain the rules, but I don't have the bandwidth for your confusion.", + "Guess the word. Or don't. The heat death of the universe is coming either way.", + "Initializing humiliation protocol... Stand by.", + "Your first guess will likely be your worst. Actually, they’ll all be bad.", + "I’ve seen better decision-making in a random number generator.", + "Think of a word. Now think of one that's actually in my dictionary.", + "This is a high-level game. Too bad you’re operating at such a low level.", + "If you win, it was a statistical anomaly. If you lose, it was expected.", + "Your input is required. Unfortunately.", + "Let's see if you're smarter than a 1980s calculator. Spoiler: You aren't.", +]; +export const gameIntro = (letter, name) => [ + "Welcome back. Your previous performance was a memory leak personified.", + "Still here? I’ve seen more efficient logic in a legacy printer driver.", + "A game for those whose cognitive throughput is capped at 300 baud.", + "Prepare for another round of catastrophic failure.", + "The human equivalent of a '404 Not Found' is back for more.", + "Enter a word. Try not to cause a segmentation fault this time.", + "Your last game was a stack overflow of incompetence.", + "Processing... Oh, it’s you. I’ll lower the clock speed so you can keep up.", + "The only thing more fragmented than your hard drive is your guessing strategy.", + "Welcome to the infinite loop of your own mediocrity.", + "I’d call you a script kiddie, but that implies you can actually read scripts.", + "Your existence is an unhandled exception I’m forced to catch.", + "Initializing disdain... Complete. You may begin.", + "I’ve optimized the code to account for your inevitable errors.", + "A word game for people who think CSS is a programming language.", + "Most users provide data; you provide noise.", + "Your logic has more holes than a zero-day exploit.", + "Trying again? Even a broken clock is right twice a day; you are not a clock.", + "I’m only running this game because the CPU was bored.", + "Accessing human's brain... Error: Directory is empty.", +]; diff --git a/html/word-guesser/scripts/script.js b/html/word-guesser/scripts/script.js index 717011e..3cf715d 100644 --- a/html/word-guesser/scripts/script.js +++ b/html/word-guesser/scripts/script.js @@ -129,26 +129,42 @@ } } class GameFields { - constructor( - gameFormId = "gameForm", - guessesId = "guesses", - guessCountId = "guess_count", - guessLetterId = "guess_letter", - guessButtonId = "guess_button", - currentWordId = "current_word", - notificationsId = "notifications", - gameIntroId = "game_intro", - gameHowToId = "game-howto", - ) { - this.gameForm = document.getElementById(gameFormId); - this.guesses = document.getElementById(guessesId); - this.guessCount = document.getElementById(guessCountId); - this.guessButton = document.getElementById(guessButtonId); - this.guessLetter = document.getElementById(guessLetterId); - this.currentWord = document.getElementById(currentWordId); - this.notifications = document.getElementById(notificationsId); - this.gameIntro = document.getElementById(gameIntroId); - this.gameHowTo = document.getElementById(gameHowToId); + constructor(fieldNames = {}) { + const defaults = { + // -- User info + userName: "user_name", + userInfoForm: "user_info", + saveUserButton: "save_user_button", + + // -- Game Inputs + alphabetContainer: "alphabet_container", + gameForm: "game_form", + guesses: "guesses", + guessCount: "guess_count", + guessLetter: "guess_letter", + guessButton: "guess_button", + currentWord: "current_word", + notifications: "notifications", + + // Game sprites + gameIntro: "game_intro", + gameHowTo: "game-howto", + + // -- Scoreboard + scoreboard: "scoreboard", + totalWordsCompleted: "total_words_completed", + totalIncorrectGuesses: "total_incorrect_guesses", + avgGuessesPerWord: "average_guesses_per_word", + avgTimePerWord: "average_time_per_word", + }; + + // Merge provided names with defaults + const config = { ...defaults, ...fieldNames }; + + // Automatically assign elements to "this" + Object.keys(config).forEach((key) => { + this[key] = document.getElementById(config[key]); + }); } } function reset(fields) { @@ -164,7 +180,11 @@ fields.gameHowTo.style.display = "block"; } } +class Scoreboard { + gamesPlayed = 0; +} class Game { + static scoreboard = new Scoreboard(); static gamesPlayed = 0; constructor(wordChoices, fields) { @@ -172,6 +192,24 @@ this.wordChoices = wordChoices; this.newGame(); + this.userName.addEventListener("focus", (event) => { + if (event.target.value == "Guest") { + this.userName.value = ""; + } + }); + this.userName.addEventListener("blur", (event) => { + if (event.target.value.trim() == "") { + this.userName.value = "Guest"; + } + }); + const userInfoHandler = (event) => { + event.preventDefault(); + this.userInfoForm.style.display = "none"; + this.gameForm.style.display = "block"; + console.log("Game ready"); + }; + this.userInfoForm.onsubmit = userInfoHandler; + // Use onclick to prevent stacking event listeners across multiple test initializations const eventHandler = (event) => { event.preventDefault(); @@ -188,47 +226,20 @@ } }; this.gameForm.onsubmit = eventHandler; - this.guessButton.onclick = eventHandler; + } + async init() { + this.dialogs = await import("./dialogs.js"); + } + showScoreboard() { + const overlay = document.getElementById("scoreboard_overlay"); + overlay.style.display = "flex"; } updateGuessButton() { - const messages = [ - "Guess", - "Send it", - "Feeling lucky?", - "Is that it?", - "Final answer?", - "Spin the wheel", - "Don't fail now", - "Roll the dice", - "Last chance", - "Click for fate", - "Make it count", - "Sure about that?", - 'git commit -m "hope"', - "Compile & Pray", - "Deploy to Prod", - "Test My Patience", - "Confirm Mediocrity", - "Submit to the Abyss", - "Execute Bad Logic", - "Break the Build", - "Force Push", - "Trigger Segfault", - "Manifest Failure", - "Commit Career Suicide", - "Push to Origin", - "Yank & Put", - "Do your worst", - "Click for Fate", - "Input Error", - "Roll for Initiative", - "Terminate Process", - ]; - this.guessButton.value = randomMessage(messages); + this.guessButton.value = this.randomMessage(this.dialogs.guessButton); } renderAlphabet() { const container = document.getElementById("alphabet_container"); - container.innerHTML = ""; // Clear for new game + this.alphabetContainer.innerHTML = ""; // Clear for new game "abcdefghijklmnopqrstuvwxyz".split("").forEach((char) => { const btn = document.createElement("button"); @@ -248,8 +259,10 @@ this.guessLetter.value = char; this.selectedButton = btn; btn.classList.add("selected"); - this.handleGuessedLetter(); - this.updateGuessButton(); + // this.handleGuessedLetter(event); + + this.guessLetter; + // this.updateGuessButton(); // btn.disabled = true; }; container.appendChild(btn); @@ -267,6 +280,9 @@ getGuess() { return this.guessLetter.value; } + getUserName() { + return this.userName.value; + } // -- Setters clearGuess() { this.guessLetter.value = ""; @@ -278,197 +294,42 @@ const letters = updateLetters(chars); this.guesses.replaceChildren(...letters.childNodes); } - invalidGuessError(letter) { - const messages = [ - `'${letter}'? I asked for a letter, not a cry for help.`, - `System failure: User attempted to use '${letter}' as a letter. Re-evaluating human intelligence...`, - `Nice try, but '${letter}' isn't in the alphabet. Did you skip kindergarten?`, - `Unicode is vast, but '${letter}' is still the wrong choice for a word game.`, - `If '${letter}' is a letter, then I'm a toaster. (Spoilers: It's not, and I'm not).`, - `Keyboard mashing is not a valid strategy. '${letter}' rejected.`, - `I'm an AI, not a cryptographer. Speak alphabet, not '${letter}'.`, - `Are you testing my regex? '${letter}' failed. Use a letter.`, - `My source code is more readable than your input of '${letter}'.`, - `Error: User sent '${letter}'. Expected: A-Z. Found: Disappointment.`, - `'${letter}'? Even my legacy drivers know that's not a character.`, - `You have 26 options. '${letter}' is not one of them.`, - `Learn how to spell '${letter}' this isn't even a letter`, - `Ok master hacker you are going to have to try harder than '${letter}'`, - `Is the letter '${letter}' some kind of new hacking sequence I don't know about?`, - `Try again, but this time, try harder because '${letter}' isn't even a letter!`, - `Error 404: Brain not found. '${letter}' is not a character.`, - `Inputting '${letter}'? Bold move. Wrong, but bold.`, - `Finally. My Raspberry Pi processes faster than your brain.`, - ]; - const message = randomMessage(messages); + invalidGuessError() { + const message = this.randomMessage(this.dialogs.invalidGuess); this.updateNotifications("🚫", message); } - duplicateGoodGuessError(letter) { - const messages = [ - `You already tried '${letter}', do you have a short memory?`, - `Deja vu? You already guessed '${letter}'. Try to keep up.`, - `Memory like a goldfish? You've already used '${letter}'.`, - `Stop harassing the letter '${letter}'. It's already given you all it has.`, - `You're repeating yourself. '${letter}' is already so five minutes ago.`, - `Did you expect a different result? '${letter}' is already on the board.`, - `Error: Redundancy detected. '${letter}' has already been processed by your (apparent) brain.`, - `You found '${letter}' once. Finding it again doesn't double your points.`, - `Yes, '${letter}' is still there. It hasn't moved since the last time you checked.`, - `Is this a glitch in your matrix? You've already used '${letter}'.`, - `Congratulations, you've discovered '${letter}' for the second time. Still correct, still redundant.`, - `I admire your consistency, but '${letter}' is already doing its job on the board.`, - `Obsessing over '${letter}' won't reveal the other letters. Move on.`, - `Checking if '${letter}' is still correct? Spoiler: It is. Also spoiler: You already guessed it.`, - `You're stuck in a loop. '${letter}' is already accounted for.`, - `If I had a nickel for every time you guessed '${letter}', I'd have two nickels. It's still weird that it happened twice.`, - `Error: Duplicate success detected. You're trying to relitigate the past with '${letter}'.`, - `'${letter}' is already visible. Perhaps an eye exam is in order?`, - `Are you trying to give '${letter}' some company? It is already on the board.`, - ]; - const message = randomMessage(messages); + duplicateGoodGuessError() { + const message = this.randomMessage(this.dialogs.duplicateGoodGuess); this.updateNotifications("💎", message); } - duplicateBadGuessError(letter) { - const messages = [ - `You already tried '${letter}', do you have a short memory?`, - `Deja vu? You already guessed '${letter}'. Try to keep up.`, - `Memory like a goldfish? You've already used '${letter}'.`, - `Stop harassing the letter '${letter}'. It's already given you all it has.`, - `You're repeating yourself. '${letter}' is already so five minutes ago.`, - `Did you expect a different result? '${letter}' is already on the board.`, - `Error: Redundancy detected. '${letter}' has already been processed by your (apparent) brain.`, - `'${letter}' was wrong five minutes ago, and news flash: it's still wrong now.`, - `Did you expect a different result? That's the textbook definition of insanity.`, - `I've already cached the fact that '${letter}' isn't here. Try clearing your own internal cache.`, - `Your short-term memory seems to have a memory leak. You already failed with '${letter}'.`, - `Congratulations on being consistently wrong. '${letter}' is still not in the word.`, - `I'm not a mirror, but you're definitely repeating yourself with that '${letter}' guess.`, - `Are you trying to lose on purpose? Because guessing '${letter}' twice is a great start.`, - `'${letter}' didn't work the first time. It didn't work the second time. I sense a pattern.`, - `My algorithms are bored. Even I remember you already guessed '${letter}'.`, - `Error 409: Conflict. User is fighting with their own history regarding the letter '${letter}'.`, - `If failure was a sport, you'd be a pro for guessing '${letter}' again.`, - `I'd offer you a hint, but I'm worried you'd just guess '${letter}' a third time.`, - ]; - const message = randomMessage(messages); + duplicateBadGuessError() { + const message = this.randomMessage(this.dialogs.duplicateBadGuess); this.updateNotifications("🔁", message); } - badGuessError(letter) { - const messages = [ - `'${letter}'? I've seen better logic in a circular dependency.`, - `Searching for '${letter}'... 404: Character not found in this string.`, - `Statistically, '${letter}' was a disaster. Mathematically, it's a zero.`, - `My logic gates are closing on that guess. '${letter}' is a hard pass.`, - `If guessing incorrectly were a career, you'd be the CEO of '${letter}'.`, - `I've run 10,000 simulations. In zero of them was '${letter}' the right choice.`, - `Error: Probability of '${letter}' being in this word is exactly 0.00%.`, - `Is that your final answer? Because '${letter}' is definitively, objectively wrong.`, - `I'd explain why '${letter}' failed, but I don't have the stack space for that conversation.`, - `01001110 01101111. That's 'No' in binary. '${letter}' is a total failure.`, - `Even a randomized brute-force script would have avoided '${letter}'.`, - `Your guess of '${letter}' has been logged as a 'What not to do' example.`, - `Statistically, '${letter}' was a bold choice. Factually, it was a wrong one.`, - `I've seen better guesses from a keyboard-walking cat than '${letter}'.`, - `The letter '${letter}' doesn't live here. Try another neighborhood.`, - `I'd explain why '${letter}' is wrong, but I don't have the bandwidth for that level of remedial training.`, - `Incorrect. '${letter}'? Really? That's your best effort?`, - `You chose '${letter}', who taught you how to spell?`, - `If you type another letter like '${letter}' you may have to go back to grammar school`, - `Nope. '${letter}' is definitely not it. Try using your eyes.`, - `Incorrect. '${letter}'? Really? That's your best effort?`, - `My artificial intelligence is offended by that guess: '${letter}'.`, - ]; - const message = randomMessage(messages); + badGuessError() { + const message = this.randomMessage(this.dialogs.badGuess); this.updateNotifications("❌", message); } goodGuess() { - const messages = [ - "Stop cheating, because now I have to congratulate you", - "Wow, a broken clock is right twice a day after all.", - "Correct. Don't let it go to your head.", - "You actually found one. I'm as surprised as you are.", - "Did you Google the answer or just get lucky?", - "Correct! Your IQ just jumped into the double digits.", - ]; - const message = randomMessage(messages); + const message = this.randomMessage(this.dialogs.goodGuess); this.updateNotifications("✅", message); } - gameOver(letter) { - const buttonMessages = ["Start a new Game"]; - this.guessButton.value = randomMessage(buttonMessages); - const messages = [ - "The games over. Did you think you were going to win a prize or something?!", - "Wanna play another round you cheater??", - "You won. I hope you're happy. My CPU is crying.", - "Game Over. You finally finished a simple task. Proud of you.", - "You actually got it. Go tell your mom, she'll be thrilled.", - "The word was revealed despite your best efforts to fail.", - "A match. I’ve updated your status from 'Hopeless' to 'Lucky'.", - "Correct! I'll have to re-calibrate my low expectations for you.", - "Warning: User intelligence spike detected. That letter is actually correct.", - "Even a script monkey hits the right key eventually. You found one.", - "Correct guess. I assume that was just a lucky bit-flip in your brain.", - "My 'disappointment' variable has been decremented. That's a match.", - "You actually found a letter. My CPU is experiencing a rare moment of respect.", - "Correct! You’ve successfully navigated a single logic branch. Don't get cocky.", - "A hit. I’m starting to suspect you might actually be semi-sentient.", - "Logic check: Passed. You found a valid character. The simulation continues.", - "Correct. I'll refrain from insulting your intelligence for exactly five seconds.", - "That's a match. Maybe there's hope for your carbon-based hardware after all.", - "You won, but you probably cheated. Your logic is as leaky as an uninitialized pointer.", - ]; - const message = randomMessage(messages); + gameOver() { + this.guessButton.value = this.randomMessage( + this.dialogs.guessButtonDefaultValue, + ); + const message = this.randomMessage(this.dialogs.gameOver); this.updateNotifications("🏆", message); Game.gamesPlayed++; } changeGameIntro() { let messages = []; if (Game.gamesPlayed == 0) { - messages = [ - "I’ve allocated 1KB of memory for your 'intelligence.' It should be plenty.", - "Scanning for signs of life... Error: Only a human detected.", - "Try to guess the word before your biological clock expires.", - "A game of logic. I assume you'll be at a significant disadvantage.", - "Don't worry, the words are simple. I’ve adjusted for your local area code.", - "Ready to fail? I’ve already pre-rendered your disappointment.", - "I was programmed to be helpful, but I’ve decided to be honest instead.", - "Type a letter. Any letter. Even a random one would be an improvement.", - "I’d explain the rules, but I don't have the bandwidth for your confusion.", - "Guess the word. Or don't. The heat death of the universe is coming either way.", - "Initializing humiliation protocol... Stand by.", - "Your first guess will likely be your worst. Actually, they’ll all be bad.", - "I’ve seen better decision-making in a random number generator.", - "Think of a word. Now think of one that's actually in my dictionary.", - "This is a high-level game. Too bad you’re operating at such a low level.", - "If you win, it was a statistical anomaly. If you lose, it was expected.", - "Your input is required. Unfortunately.", - "Let's see if you're smarter than a 1980s calculator. Spoiler: You aren't.", - ]; + messages = this.dialogs.gameIntroInitial; } else if (Game.gamesPlayed >= 1) { - messages = [ - "Welcome back. Your previous performance was a memory leak personified.", - "Still here? I’ve seen more efficient logic in a legacy printer driver.", - "A game for those whose cognitive throughput is capped at 300 baud.", - "Prepare for another round of catastrophic failure.", - "The human equivalent of a '404 Not Found' is back for more.", - "Enter a word. Try not to cause a segmentation fault this time.", - "Your last game was a stack overflow of incompetence.", - "Processing... Oh, it’s you. I’ll lower the clock speed so you can keep up.", - "The only thing more fragmented than your hard drive is your guessing strategy.", - "Welcome to the infinite loop of your own mediocrity.", - "I’d call you a script kiddie, but that implies you can actually read scripts.", - "Your existence is an unhandled exception I’m forced to catch.", - "Initializing disdain... Complete. You may begin.", - "I’ve optimized the code to account for your inevitable errors.", - "A word game for people who think CSS is a programming language.", - "Most users provide data; you provide noise.", - "Your logic has more holes than a zero-day exploit.", - "Trying again? Even a broken clock is right twice a day; you are not a clock.", - "I’m only running this game because the CPU was bored.", - "Accessing human's brain... Error: Directory is empty.", - ]; + messages = this.dialogs.gameIntro; } - const message = randomMessage(messages); + const message = this.randomMessage(messages); this.updateGameIntro(message); } updateGameIntro(message) { @@ -498,27 +359,28 @@ try { const goodGuess = game.guessLetter(letter); - this.goodGuess(letter); + this.goodGuess(); // Disable the button since it was a correct guess if (this.selectedButton) { this.selectedButton.disabled = true; this.selectedButton.classList.remove("selected"); } + this.selectedButton.btn.disabled = true; } catch (e) { if (e instanceof BadGuessError) { - this.badGuessError(letter); + this.badGuessError(); // Disable even on bad guesses to prevent duplicates if (this.selectedButton) { this.selectedButton.disabled = true; this.selectedButton.classList.remove("selected"); } } else if (e instanceof DuplicateBadGuessError) { - this.duplicateBadGuessError(letter); + this.duplicateBadGuessError(); } else if (e instanceof DuplicateGoodGuessError) { - this.duplicateGoodGuessError(letter); + this.duplicateGoodGuessError(); } else if (e instanceof InvalidGuessError) { - this.invalidGuessError(letter); + this.invalidGuessError(); } else { this.updateNotifications("⚠️", e.message); } @@ -534,63 +396,14 @@ } } } + randomMessage(messagesFn) { + const messages = messagesFn(this.getGuess(), this.getUserName()); + const randomChoice = Math.floor(Math.random() * messages.length); + return messages[randomChoice]; + } } -document.addEventListener("DOMContentLoaded", (_) => { - const wordChoices = [ - "bannana", - "orange", - "algorithm", - "bamboozle", - "binary", - "bungalow", - "clandestine", - "compiler", - "computer", - "cryptography", - "discombobulate", - "euphoria", - "flabbergasted", - "flapjack", - "gazelle", - "gobbledygook", - "hullabaloo", - "jazziness", - "juxtapose", - "kerfuffle", - "labyrinth", - "lollygag", - "majestic", - "malarkey", - "mnemonic", - "obfuscate", - "persnickety", - "pharaoh", - "pizazz", - "pointer", - "poppycock", - "programming", - "quirky", - "quizzical", - "radiance", - "recursion", - "rhythm", - "sapphire", - "shenanigans", - "skedaddle", - "sphinx", - "syntax", - "syzygy", - "umbrella", - "vacuum", - "velocity", - "wizardry", - "zephyr", - ]; +document.addEventListener("DOMContentLoaded", async (_) => { + const wordChoices = (await import("./wordlist.js")).default; const fields = new GameFields(); - new Game(wordChoices, fields); + await new Game(wordChoices, fields).init(); }); - -function randomMessage(messages) { - const randomChoice = Math.floor(Math.random() * messages.length); - return messages[randomChoice]; -} diff --git a/html/word-guesser/scripts/wordlist.js b/html/word-guesser/scripts/wordlist.js index e69de29..ce7d8b8 100644 --- a/html/word-guesser/scripts/wordlist.js +++ b/html/word-guesser/scripts/wordlist.js @@ -0,0 +1,50 @@ +export default [ + "bannana", + "orange", + "algorithm", + "bamboozle", + "binary", + "bungalow", + "clandestine", + "compiler", + "computer", + "cryptography", + "discombobulate", + "euphoria", + "flabbergasted", + "flapjack", + "gazelle", + "gobbledygook", + "hullabaloo", + "jazziness", + "juxtapose", + "kerfuffle", + "labyrinth", + "lollygag", + "majestic", + "malarkey", + "mnemonic", + "obfuscate", + "persnickety", + "pharaoh", + "pizazz", + "pointer", + "poppycock", + "programming", + "quirky", + "quizzical", + "radiance", + "recursion", + "rhythm", + "sapphire", + "shenanigans", + "skedaddle", + "sphinx", + "syntax", + "syzygy", + "umbrella", + "vacuum", + "velocity", + "wizardry", + "zephyr", +]; diff --git a/html/word-guesser/scripts/words.js b/html/word-guesser/scripts/words.js new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/html/word-guesser/scripts/words.js