diff --git a/index.css b/index.css index 0d65432..73d32a5 100644 --- a/index.css +++ b/index.css @@ -132,6 +132,10 @@ body.wide { margin-top: 1em; } +#puzzles { + width: 5em; +} + #copyarea { display: none; background-color: #1f2937; diff --git a/index.html b/index.html index ad0b48e..ac6b3c4 100644 --- a/index.html +++ b/index.html @@ -20,6 +20,10 @@
+ diff --git a/index.js b/index.js index e32d55d..e4b6bb5 100644 --- a/index.js +++ b/index.js @@ -33,12 +33,16 @@ function saveLocalStorage() { localStorage.setItem(LOCALSTORAGE_KEY, JSON.stringify(saveData)); } +const inputAmount = document.getElementById("puzzles"); + +const NUMBER_OF_WORDS = Number(inputAmount.value) || 4; const daysSinceEpoch = Math.floor(new Date()/8.64e7); const startDay = 19046; const daysSinceStart = daysSinceEpoch - startDay + 1; -const rng = mulberry32(daysSinceEpoch); +const rngSeed = NUMBER_OF_WORDS === 4 ? daysSinceEpoch : (daysSinceEpoch*daysSinceEpoch*NUMBER_OF_WORDS); +const rng = mulberry32(rngSeed); const chosenWords = []; -for (let i = 0; i < 4; i++) { +for (let i = 0; i < NUMBER_OF_WORDS; i++) { while (true) { const idx = Math.floor((rng() * words.length) % words.length); const chosen = words[idx]; @@ -51,13 +55,13 @@ for (let i = 0; i < 4; i++) { } const WORD_LENGTH = 5; -const MAX_GUESSES = 9; +const MAX_GUESSES = 5 + NUMBER_OF_WORDS; const URL = "https://studwww.informatik.kit.edu/~s_keller/qwörtle/"; const guessed = []; let input = ""; const data = []; const solutions = []; -const done = [false, false, false, false]; +const done = Array(NUMBER_OF_WORDS).fill(false); let shareText = ""; function gameOver() { @@ -66,6 +70,7 @@ function gameOver() { } const NUMBERS = "0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣"; const FAIL = "❌"; + const SOLVED = "✅"; const ANY = "⬜"; const POSITION = "🟨"; const CORRECT = "🟩"; @@ -73,9 +78,13 @@ function gameOver() { let text = ""; text += "Tägliches Qwörtle #" + daysSinceStart + "\n"; let summary = ""; - for (let i = 0; i < 4; i++) { + for (let i = 0; i < NUMBER_OF_WORDS; i++) { if (done[i]) { - summary += NUMBERS.slice(done[i] * 3, done[i] * 3 + 3); + if (done[i] <= 9) { + summary += NUMBERS.slice(done[i] * 3, done[i] * 3 + 3); + } else { + summary += SOLVED; + } } else { summary += FAIL; } @@ -86,7 +95,7 @@ function gameOver() { document.getElementById("summary").innerText = summary; document.getElementById("summary").style.display = "block"; text += summary + URL + "\n"; - for (let i = 0; i < 2; i++) { + for (let i = 0; i < NUMBER_OF_WORDS / 2; i++) { for (let j = 0; j < MAX_GUESSES; j++) { const rowA = data[2*i * MAX_GUESSES + j]; const rowB = data[(2*i+1) * MAX_GUESSES + j]; @@ -119,7 +128,7 @@ function gameOver() { } text += part1 + " " + part2 + "\n"; } - if (i === 0) { + if (i % 2 === 0) { text += "\n"; } } @@ -148,9 +157,12 @@ document.getElementById("share").addEventListener("click", () => { }); let keys = {}; -let characters = [{}, {}, {}, {}]; +let characters = []; +for (let i = 0; i < NUMBER_OF_WORDS; i++) { + characters.push({}); +} -function makeGradient(a, b, c, d) { +function makeGradient(a, b, c, d, allNope) { const CORRECT = "rgb(0 204 136)"; const POSITION = "rgb(255 204 0)"; const OTHER = "rgb(156, 163, 175)"; @@ -158,7 +170,7 @@ function makeGradient(a, b, c, d) { "correct": CORRECT, "position": POSITION }; - if (a === "nope" && b === "nope" && c === "nope" && d === "nope") { + if (allNope) { return "rgb(21 94 117)"; } const style = "conic-gradient(" + @@ -183,7 +195,7 @@ function processKey(e) { console.error("word not in list"); return; } - for (let pos = 0; pos < 4; pos++) { + for (let pos = 0; pos < NUMBER_OF_WORDS; pos++) { if (done[pos]) { for (let i = 0; i < WORD_LENGTH; i++) { const el = data[pos * MAX_GUESSES + guessed.length][i]; @@ -274,13 +286,23 @@ function processKey(e) { continue; } const c = char.toUpperCase(); - let anyNotNope = (characters[0][c] && characters[0][c] !== "nope") - || (characters[1][c] && characters[1][c] !== "nope") - || (characters[2][c] && characters[2][c] !== "nope") - || (characters[3][c] && characters[3][c] !== "nope"); + let anyNotNope = false; + for (let i = 0; i < NUMBER_OF_WORDS; i++) { + anyNotNope |= (characters[i][c] && characters[i][c] !== "nope"); + if (anyNotNope) { + break; + } + } if (anyNotNope || (characters[0][c] === "nope" && characters[1][c] === "nope" && characters[2][c] === "nope" && characters[3][c] === "nope")) { - keys[char].style.background = makeGradient(characters[0][c], characters[1][c], characters[2][c], characters[3][c]); - if (characters[0][c] === "nope" && characters[1][c] === "nope" && characters[2][c] === "nope" && characters[3][c] === "nope") { + let allNope = true; + for (let i = 0; i < NUMBER_OF_WORDS; i++) { + if (characters[i][c] !== "nope") { + allNope = false; + break; + } + } + keys[char].style.background = makeGradient(characters[0][c], characters[1][c], characters[2][c], characters[3][c], allNope); + if (allNope) { keys[char].style.color = "#fff"; keys[char].style.opacity = "0.5"; } else if (anyNotNope) { @@ -293,7 +315,7 @@ function processKey(e) { } return; } else if (e.key === "Backspace" && input.length > 0) { - for (let pos = 0; pos < 4; pos++) { + for (let pos = 0; pos < NUMBER_OF_WORDS; pos++) { data[pos * MAX_GUESSES + guessed.length][input.length - 1].innerText = ""; } input = input.substring(0, input.length - 1); @@ -310,7 +332,7 @@ function processKey(e) { console.error("input full"); return; } - for (let pos = 0; pos < 4; pos++) { + for (let pos = 0; pos < NUMBER_OF_WORDS; pos++) { if (done[pos]) { continue; } @@ -319,7 +341,7 @@ function processKey(e) { input += key; } const validGuess = input.length < 5 || validGuesses.indexOf(input) !== -1; - for (let pos = 0; pos < 4; pos++) { + for (let pos = 0; pos < NUMBER_OF_WORDS; pos++) { if (done[pos]) { continue; } @@ -329,6 +351,9 @@ function processKey(e) { data[pos * MAX_GUESSES + guessed.length][0].parentElement.className = "row"; } } + if (input === "GIGAQ") { + document.getElementById("secret-options").style.display = "block"; + } } document.addEventListener("keydown", processKey); @@ -360,7 +385,7 @@ for (let i = 0; i < 3; i++) { } function createGameGrid(container) { - for (let pos = 0; pos < 4; pos++) { + for (let pos = 0; pos < NUMBER_OF_WORDS; pos++) { container.appendChild(createWordle(chosenWords[pos])); } }