diff --git a/html/word-guesser/css/styles.css b/html/word-guesser/css/styles.css index c7d03a2..7791b95 100644 --- a/html/word-guesser/css/styles.css +++ b/html/word-guesser/css/styles.css @@ -6,13 +6,20 @@ padding: 2rem; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05); margin-top: 1rem; + max-width: 400px; + margin: 0 auto; + padding: 10px; + display: flex; + flex-direction: column; + gap: 15px; } .game-header h2 { color: var(--accent-primary); border-bottom: 2px solid var(--accent-primary); display: inline-block; - margin-bottom: 1.5rem; + font-size: 1.4rem; + margin-bottom: 0; padding-bottom: 0.2rem; } @@ -22,38 +29,47 @@ font-size: 0.95rem; color: #6c757d; } +#game_intro { + font-size: 0.85rem; + opacity: 0.7; +} /* Word Board (Wheel of Fortune Style) */ #current_word { - display: flex !important; + display: flex; flex-direction: row !important; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; - gap: 8px; + gap: 5px; list-style: none; padding: 1rem 0; width: 100%; font-weight: bold; letter-spacing: 5px; font-size: 1.5rem; + list-style: none; + padding: 10px 0; } #current_word li { - width: 45px; - height: 60px; background-color: var(--bg-body); border: 2px solid var(--accent-primary); border-radius: 4px; display: flex; align-items: center; justify-content: center; - font-size: 2rem; - font-weight: 800; color: var(--accent-primary); box-shadow: 2px 2px 0px rgba(44, 62, 80, 0.2); text-transform: uppercase; + + width: 32px; + height: 42px; + display: flex; + border-bottom: 3px solid var(--border-medium); + font-weight: bold; + font-size: 1.4rem; } .word-display-field { display: block !important; /* Break out of the 2-column grid */ @@ -137,28 +153,44 @@ /* Guess History Pills */ #guesses { display: flex; - flex-wrap: wrap; - gap: 6px; + flex-wrap: nowrap; /* Keep them on one line */ + overflow-x: auto; /* Scroll if there are too many */ + gap: 5px; + padding: 5px 0; + margin: 0; list-style: none; + scrollbar-width: none; /* Hide scrollbar for clean UI */ +} + +#guesses::-webkit-scrollbar { + display: none; /* Hide scrollbar for Chrome/Safari */ } #guesses li { - background-color: #e3f2fd; +} +#guesses li { + background: var(--accent-secondary, #e9ecef); color: #1976d2; - padding: 2px 10px; + padding: 2px 8px; border-radius: 20px; font-size: 0.85rem; - font-family: "Courier New", Courier, monospace; + font-family: "Roboto Mono", monospace; + /* font-family: "Courier New", Courier, monospace; */ font-weight: bold; + flex-shrink: 0; border: 1px solid #bbdefb; + border-radius: 3px; } /* Notifications */ #notifications { text-align: center; font-weight: 600; - min-height: 1.5rem; margin-bottom: 1rem; + min-height: 1.2em; + color: #d9534f; + font-style: italic; + text-align: center; } .success-msg { @@ -174,83 +206,161 @@ padding: 1rem; margin: 0.5rem; } - - /* Shrink the tiles so long words don't wrap awkwardly */ - #current_word { - gap: 4px; - padding: 0.5rem 0; + #game_container { + top: 0px; + left: 0px; + position: fixed; + z-index: 1000; + } + #site-header, + footer, + #guesses, + #guess_letter_container { + display: none; + position: absolute; + z-index: -9999; } - #current_word li { - width: 30px; /* Reduced from 45px */ - height: 40px; /* Reduced from 60px */ - font-size: 1.2rem; /* Reduced from 2rem */ - border-width: 1px; - } + /* /1* Shrink the tiles so long words don't wrap awkwardly *1/ */ + /* #current_word { */ + /* gap: 4px; */ + /* padding: 0.5rem 0; */ + /* } */ - /* Stack the form fields vertically instead of 2-columns */ - .formField { - grid-template-columns: 1fr; - gap: 5px; - text-align: center; - } + /* #current_word li { */ + /* width: 30px; /1* Reduced from 45px *1/ */ + /* height: 40px; /1* Reduced from 60px *1/ */ + /* font-size: 1.2rem; /1* Reduced from 2rem *1/ */ + /* border-width: 1px; */ + /* } */ - /* Make the Alphabet Grid look like a keypad */ - .alphabet-grid { - display: grid; - grid-template-columns: repeat(auto-fill, minmax(35px, 1fr)); - gap: 5px; - margin-top: 1.5rem; - } + /* /1* Stack the form fields vertically instead of 2-columns *1/ */ + /* .formField { */ + /* grid-template-columns: 1fr; */ + /* gap: 5px; */ + /* text-align: center; */ + /* } */ - .letter-btn { - padding: 10px 0; - font-family: "Roboto Mono", monospace; - font-weight: bold; - background: var(--bg-tag); - border: 1px solid var(--border-medium); - border-radius: 4px; - cursor: pointer; - } + /* /1* Make the Alphabet Grid look like a keypad *1/ */ + /* .alphabet-grid { */ + /* display: grid; */ + /* grid-template-columns: repeat(auto-fill, minmax(35px, 1fr)); */ + /* gap: 5px; */ + /* margin-top: 1.5rem; */ + /* } */ - .letter-btn:disabled { - opacity: 0.4; - cursor: not-allowed; - } + /* .letter-btn { */ + /* padding: 10px 0; */ + /* font-family: "Roboto Mono", monospace; */ + /* font-weight: bold; */ + /* background: var(--bg-tag); */ + /* border: 1px solid var(--border-medium); */ + /* border-radius: 4px; */ + /* cursor: pointer; */ + /* } */ + + /* .letter-btn:disabled { */ + /* opacity: 0.4; */ + /* cursor: not-allowed; */ + /* } */ } .alphabet-grid { display: grid; - grid-template-columns: repeat( - 9, - 1fr - ); /* 9 columns fits 26 letters in ~3 rows */ - gap: 8px; - margin-top: 2rem; - padding: 10px; - background: var(--bg-tag); + grid-template-columns: repeat(9, 1fr); + gap: 4px; + background: #ebf3f9; + padding: 8px; border-radius: 8px; } .letter-btn { - background: #fff; - border: 1px solid var(--border-medium); - padding: 12px 0; - font-family: "Roboto Mono", monospace; - font-weight: bold; + aspect-ratio: 1 / 1.2; + padding: 0; font-size: 1.1rem; + font-weight: bold; + border: 1px solid #ced4da; border-radius: 4px; - cursor: pointer; - transition: background 0.1s; + background: #fff; + box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1); + transition: + transform 0.1s, + background 0.1s; } .letter-btn:active { - background: var(--accent-primary); - color: #fff; + transform: translateY(2px); + box-shadow: none; + background: #dee2e6; } .letter-btn:disabled { background: #e9ecef; color: #adb5bd; - cursor: not-allowed; + box-shadow: none; + border-color: transparent; } + +.game-footer { + display: flex; + justify-content: space-between; + align-items: center; + padding: 10px; + border-top: 1px solid #eee; + font-size: 0.9rem; +} + +#notifications { + min-height: 1.2em; + color: #d9534f; + font-style: italic; + text-align: center; +} + +#game_metrics { + display: flex; + justify-content: space-between; + align-items: flex-start; + gap: 15px; + padding: 10px; + background: var( + --bg-secondary, + #f8f9fa + ); /* Light background to define the area */ + border-radius: 8px; + margin: 10px 0; +} + +/* Individual Metric Groups */ +.formField.metric_group, +#game_metrics .formField { + flex: 1; + display: flex; + flex-direction: column; + gap: 4px; + min-width: 0; /* Critical for preventing flex items from overflowing */ +} + +/* Labels */ +#game_metrics .label { + font-size: 0.75rem; + font-weight: bold; + text-transform: uppercase; + color: var(--text-muted, #6c757d); + letter-spacing: 0.05em; +} + +/* Attempts Input Styling */ +#guess_count { + width: 100%; + padding: 8px; + border: 1px solid var(--border-light, #dee2e6); + border-radius: 4px; + background: #fff; + font-family: "Roboto Mono", monospace; + font-size: 1.1rem; + text-align: center; + color: var(--text-primary, #212529); +} + +/* Guesses List Styling */ diff --git a/html/word-guesser/index.html b/html/word-guesser/index.html index eb40e3e..1b40d1c 100644 --- a/html/word-guesser/index.html +++ b/html/word-guesser/index.html @@ -1,17 +1,24 @@ -
+

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 + box belowand and click "Guess" to see if the letter + exists in the hidden word.

+

+

    -
    -

    Guess what the word is

    +
    +

    Guess a letter:

    -
    -

    - Please enter a single alphabetical character (A-Z) into the input - box belowand and click "Guess" to see if the letter - exists in the hidden word.

    -

    +
    +
    + Attempts + +
    +
    + Guesses +
      +
      -
      - - -
      -
      - -
        -
        diff --git a/html/word-guesser/scripts/script.js b/html/word-guesser/scripts/script.js index f90de94..717011e 100644 --- a/html/word-guesser/scripts/script.js +++ b/html/word-guesser/scripts/script.js @@ -1,4 +1,3 @@ -// -- Determines if a letter is in a list of letters function charInChars(char, chars) { const indexes = charsAt(char, chars); return indexes !== false; @@ -12,25 +11,6 @@ } return indexes.length == 0 ? false : indexes; } -function createAlphabetGrid(gameInstance) { - const alphabet = "abcdefghijklmnopqrstuvwxyz".split(""); - const container = document.createElement("div"); - container.className = "alphabet-grid"; - - alphabet.forEach((char) => { - const btn = document.createElement("button"); - btn.innerText = char.toUpperCase(); - btn.className = "letter-btn"; - btn.onclick = () => { - gameInstance.fields.guessLetter.value = char; - gameInstance.handleGuessedLetter(); - btn.disabled = true; // Prevent double-clicking - }; - container.appendChild(btn); - }); - - document.getElementById("gameForm").appendChild(container); -} function updateLetters(chars) { const letters = document.createElement("ul"); // create a DOM element for each letter @@ -158,6 +138,7 @@ currentWordId = "current_word", notificationsId = "notifications", gameIntroId = "game_intro", + gameHowToId = "game-howto", ) { this.gameForm = document.getElementById(gameFormId); this.guesses = document.getElementById(guessesId); @@ -167,6 +148,7 @@ this.currentWord = document.getElementById(currentWordId); this.notifications = document.getElementById(notificationsId); this.gameIntro = document.getElementById(gameIntroId); + this.gameHowTo = document.getElementById(gameHowToId); } } function reset(fields) { @@ -175,9 +157,12 @@ fields.guessButton.value = "Guess"; fields.notifications.innerText = ""; fields.guessCount.value = "0"; - fields.guessLetter.value = ""; + // fields.guessLetter.value = ""; fields.guesses.replaceChildren(); fields.currentWord.replaceChildren(); + if (fields.gameHowTo) { + fields.gameHowTo.style.display = "block"; + } } class Game { static gamesPlayed = 0; @@ -189,65 +174,83 @@ // Use onclick to prevent stacking event listeners across multiple test initializations const eventHandler = (event) => { + event.preventDefault(); if (this.game.gameOver()) { - reset(this); + // reset(this); // this.gameIntro.innerText = // "The game that insults you, whether you win or lose!"; // this.guessButton.value = "Guess"; - this.game = new WordGuesser(this.wordChoices); + // this.game = new WordGuesser(this.wordChoices); + this.newGame(); } else { - 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.updateGuessButton(); this.handleGuessedLetter(event); } }; this.gameForm.onsubmit = eventHandler; this.guessButton.onclick = eventHandler; } + 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); + } renderAlphabet() { const container = document.getElementById("alphabet_container"); container.innerHTML = ""; // Clear for new game "abcdefghijklmnopqrstuvwxyz".split("").forEach((char) => { const btn = document.createElement("button"); + btn.type = "button"; btn.innerText = char.toUpperCase(); btn.className = "letter-btn"; + + // Custom attribute to find this button later by character + btn.dataset.char = char; + btn.onclick = () => { + // 1. Remove selection from previous button + if (this.selectedButton) { + this.selectedButton.classList.remove("selected"); + } + this.guessLetter.value = char; + this.selectedButton = btn; + btn.classList.add("selected"); this.handleGuessedLetter(); - btn.disabled = true; + this.updateGuessButton(); + // btn.disabled = true; }; container.appendChild(btn); }); @@ -256,9 +259,9 @@ reset(this); } newGame() { - this.renderAlphabet(); this.reset(); this.game = new WordGuesser(this.wordChoices); + this.renderAlphabet(); } // -- Getters getGuess() { @@ -488,14 +491,28 @@ if (game.guessCount() == 0) { this.changeGameIntro(); + if (this.gameHowTo) { + this.gameHowTo.style.display = "none"; + } } try { const goodGuess = game.guessLetter(letter); this.goodGuess(letter); + + // Disable the button since it was a correct guess + if (this.selectedButton) { + this.selectedButton.disabled = true; + this.selectedButton.classList.remove("selected"); + } } catch (e) { if (e instanceof BadGuessError) { this.badGuessError(letter); + // 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); } else if (e instanceof DuplicateGoodGuessError) { @@ -511,6 +528,7 @@ this.updateGuesses(game.getGuesses()); this.updateGuessCount(game.guessCount()); this.clearGuess(); + this.selectedButton = null; if (game.gameOver()) { this.gameOver(); }