Add secret option to unlock giga qwörtle

This commit is contained in:
Arne Keller 2022-02-25 14:12:42 +01:00
parent 153c97ae43
commit de6e7811cf
3 changed files with 55 additions and 22 deletions

View File

@ -132,6 +132,10 @@ body.wide {
margin-top: 1em; margin-top: 1em;
} }
#puzzles {
width: 5em;
}
#copyarea { #copyarea {
display: none; display: none;
background-color: #1f2937; background-color: #1f2937;

View File

@ -20,6 +20,10 @@
<label><input type="checkbox" id="wide">Breiter Modus</label> <label><input type="checkbox" id="wide">Breiter Modus</label>
<br> <br>
<label><input type="checkbox" id="count">Anzahl bei richtigen Buchstaben</label> <label><input type="checkbox" id="count">Anzahl bei richtigen Buchstaben</label>
<div id="secret-options" style="display: none">
<br>
<label>Anzahl Wörter: <input type="number" id="puzzles" value="4"></label>
</div>
</div> </div>
<textarea id="copyarea"></textarea> <textarea id="copyarea"></textarea>
</div> </div>

View File

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