Compare commits
2 Commits
1cb51dd802
...
374be205b7
| Author | SHA1 | Date | |
|---|---|---|---|
| 374be205b7 | |||
| 2e3c937b99 |
@@ -11,60 +11,66 @@
|
|||||||
<h1>Flashcards Generator</h1>
|
<h1>Flashcards Generator</h1>
|
||||||
</header>
|
</header>
|
||||||
<div class="main-wrapper">
|
<div class="main-wrapper">
|
||||||
<div class="section-title" id="title">
|
<div id="startScreen">
|
||||||
<div class="content">
|
<div class="section-title" id="title">
|
||||||
<label for="inputText" class="inputText">Sende deine Wortliste an ChatGPT mit folgender Anweisung:</label>
|
|
||||||
</div>
|
|
||||||
<div id="aufgabe_fuer_gpt">
|
|
||||||
<pre id="formatText">
|
|
||||||
Bitte formatiere meine Wortliste exakt nach folgendem Schema.
|
|
||||||
Jeder Eintrag muss durch eine Leerzeile getrennt sein.
|
|
||||||
|
|
||||||
Englisches Wort
|
|
||||||
[IPA-Transkription]
|
|
||||||
Beispielsatz auf Englisch
|
|
||||||
Deutsche Übersetzung des Wortes
|
|
||||||
Beispielsatz auf Deutsch
|
|
||||||
</pre>
|
|
||||||
<button id="copyButton" style="position: absolute; top: 5px; right: 5px; cursor: pointer;">📋</button>
|
|
||||||
</div>
|
|
||||||
<div id="inputHinweis">
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<label for="inputText" class="section-title">Füge deinen Text hier ein:</label>
|
<label for="inputText" class="inputText">Sende deine Wortliste an ChatGPT mit folgender Anweisung:</label>
|
||||||
<textarea id="inputText" placeholder="Hier Text einfügen..."></textarea>
|
</div>
|
||||||
|
<div id="aufgabe_fuer_gpt">
|
||||||
|
<pre id="formatText">
|
||||||
|
Bitte formatiere meine Wortliste exakt nach folgendem Schema.
|
||||||
|
Jeder Eintrag muss durch eine Leerzeile getrennt sein.
|
||||||
|
|
||||||
|
Englisches Wort
|
||||||
|
[IPA-Transkription]
|
||||||
|
Beispielsatz auf Englisch
|
||||||
|
Deutsche Übersetzung des Wortes
|
||||||
|
Beispielsatz auf Deutsch
|
||||||
|
</pre>
|
||||||
|
<button id="copyButton" style="position: absolute; top: 5px; right: 5px; cursor: pointer;">📋</button>
|
||||||
|
</div>
|
||||||
|
<div id="inputHinweis">
|
||||||
|
<div class="content">
|
||||||
|
<label for="inputText" class="section-title">Füge deinen Text hier ein:</label>
|
||||||
|
<textarea id="inputText" placeholder="Hier Text einfügen..."></textarea>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="button-wrapper">
|
||||||
|
<button id="kartenErstellen">Karten erstellen</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="button-wrapper">
|
|
||||||
<button id="kartenErstellen">Karten erstellen</button>
|
<div id="modusAuswahlSeite" style="display:none;">
|
||||||
</div>
|
|
||||||
<div id="modusAuswahlSeite" style="display:none">
|
|
||||||
<h2>Wählt einen Modus:</h2>
|
<h2>Wählt einen Modus:</h2>
|
||||||
<button class="modus-btn" data-modus="druck">📄 PDF erstellen</button>
|
<button class="modus-btn" data-modus="druck">📄 PDF erstellen</button>
|
||||||
<button class="modus-btn" data-modus="training_einfach">🃏 Online-Training</button>
|
<button class="modus-btn" data-modus="training_einfach">🃏 Online-Training</button>
|
||||||
<button class="modus-btn" data-modus="statistik">📊 Statistik</button>
|
<button class="modus-btn" data-modus="statistik">📊 Statistik</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="pdfPages" class="modus-view">
|
<div id="pdfPages">
|
||||||
<div id="kartenContainer"></div>
|
<div id="kartenContainer"></div>
|
||||||
<div class="button-wrapper">
|
<div class="button-wrapper">
|
||||||
<button id="druckenBtn" style="display:none;">Drucken</button>
|
<button id="druckenBtn" style="display:none;">Drucken</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="onlineTraining" class="modus-view">
|
<div id="onlineTraining">
|
||||||
|
|
||||||
<div id="trainingLevels">
|
<div id="trainingLevels" class="training-view">
|
||||||
<h3>Wählt einen Schwierigkeitsgrad:</h3>
|
<h3>Wählt einen Schwierigkeitsgrad:</h3>
|
||||||
<button class="level-btn" data-level="leicht">🟢 Leicht</button>
|
<button class="level-btn" data-level="leicht">🟢 Leicht</button>
|
||||||
<button class="level-btn" data-level="mittel">🟡 Mittel</button>
|
<button class="level-btn" data-level="mittel">🟡 Mittel</button>
|
||||||
<button class="level-btn" data-level="schwer">🔴 Schwer</button>
|
<button class="level-btn" data-level="schwer">🔴 Schwer</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="trainingLeicht" class="training-view modus-view"></div>
|
<div id="trainingLeicht" class="training-view"></div>
|
||||||
<div id="trainingMittel" class="training-view"></div>
|
<div id="trainingMittel" class="training-view" style="display:none;"></div>
|
||||||
<div id="trainingSchwer" class="training-view"></div>
|
<div id="trainingSchwer" class="training-view"></div>
|
||||||
|
|
||||||
|
<div class="button-wrapper">
|
||||||
|
<button id="checkBtn" style="display:none;" onclick="pruefeRunde()">Überprüfen</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="trainingContainer" style="display:none; text-align:center; margin-top:30px;"></div>
|
<div id="trainingContainer" style="display:none; text-align:center; margin-top:30px;"></div>
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
let parsedArray = [];
|
let parsedArray = [];
|
||||||
|
|
||||||
|
// Mischt ein Array zufällig mit dem Fisher-Yates-Algorithmus
|
||||||
|
// und gibt das gemischte Array zurück.
|
||||||
|
function mischeArray(array) {
|
||||||
|
for (let i = array.length - 1; i > 0; i--) {
|
||||||
|
const j = Math.floor(Math.random() * (i + 1));
|
||||||
|
[array[i], array[j]] = [array[j], array[i]];
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById('copyButton').addEventListener('click', () => {
|
document.getElementById('copyButton').addEventListener('click', () => {
|
||||||
const text = document.getElementById('formatText').innerText;
|
const text = document.getElementById('formatText').innerText;
|
||||||
|
|
||||||
@@ -10,6 +20,7 @@ document.getElementById('copyButton').addEventListener('click', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Analysiert den eingegebenen Text und wandelt ihn in ein Array von Wort-Objekten um.
|
||||||
function parseWordText(inputText) {
|
function parseWordText(inputText) {
|
||||||
const wortBlocks = inputText.trim().split("\n\n");
|
const wortBlocks = inputText.trim().split("\n\n");
|
||||||
const wortListe = [];
|
const wortListe = [];
|
||||||
@@ -23,6 +34,7 @@ function parseWordText(inputText) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const wortObj = {
|
const wortObj = {
|
||||||
|
id: crypto.randomUUID(),
|
||||||
englisch: lines[0],
|
englisch: lines[0],
|
||||||
ipa: lines[1],
|
ipa: lines[1],
|
||||||
beispielEN: lines[2],
|
beispielEN: lines[2],
|
||||||
@@ -36,6 +48,7 @@ function parseWordText(inputText) {
|
|||||||
return wortListe;
|
return wortListe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Gibt beide Seiten als Objekt zurück.
|
||||||
function createPagePair() {
|
function createPagePair() {
|
||||||
const frontPage = document.createElement("div");
|
const frontPage = document.createElement("div");
|
||||||
frontPage.className = "page page-front";
|
frontPage.className = "page page-front";
|
||||||
@@ -62,26 +75,12 @@ button.addEventListener("click", () => {
|
|||||||
|
|
||||||
alert("Karten erfolgreich erstellt!");
|
alert("Karten erfolgreich erstellt!");
|
||||||
|
|
||||||
showView("modusAuswahlSeite");
|
|
||||||
|
|
||||||
document.getElementById("title").style.display = "none";
|
document.getElementById("startScreen").style.display = "none";
|
||||||
button.style.display = "none";
|
|
||||||
|
|
||||||
document.getElementById("modusAuswahlSeite").style.display = "block";
|
document.getElementById("modusAuswahlSeite").style.display = "block";
|
||||||
});
|
});
|
||||||
|
|
||||||
document.querySelectorAll(".modus-btn").forEach(button => {
|
// Erstellt druckfertige PDF-Seiten mit jeweils 8 Karten pro Seite.
|
||||||
button.addEventListener("click", () => {
|
|
||||||
const modus = button.dataset.modus;
|
|
||||||
|
|
||||||
if (modus === "druck") {
|
|
||||||
createPDFPages(parsedArray);
|
|
||||||
} else {
|
|
||||||
console.log("Gewählter Modus:", modus);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
function createPDFPages(wordArray) {
|
function createPDFPages(wordArray) {
|
||||||
const kartenContainer = document.getElementById("kartenContainer");
|
const kartenContainer = document.getElementById("kartenContainer");
|
||||||
|
|
||||||
@@ -132,11 +131,12 @@ modusBtns.forEach(btn => {
|
|||||||
const modus = btn.dataset.modus;
|
const modus = btn.dataset.modus;
|
||||||
|
|
||||||
if (modus === 'druck') {
|
if (modus === 'druck') {
|
||||||
showView('pdfPages');
|
showMode('pdfPages');
|
||||||
|
createPDFPages(parsedArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (modus === 'training_einfach') {
|
else if (modus === 'training_einfach') {
|
||||||
showView('trainingLevels');
|
showMode('onlineTraining');
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (modus === 'statistik') {
|
else if (modus === 'statistik') {
|
||||||
@@ -147,20 +147,22 @@ modusBtns.forEach(btn => {
|
|||||||
|
|
||||||
let trainingsZustand = {
|
let trainingsZustand = {
|
||||||
modus: "leicht",
|
modus: "leicht",
|
||||||
|
// für alle Level
|
||||||
quelleKarten: [],
|
quelleKarten: [],
|
||||||
|
basisKarten: [],
|
||||||
aktiveKarten: [],
|
aktiveKarten: [],
|
||||||
gelernt: [],
|
gelernt: [],
|
||||||
nichtGelernt: [],
|
nichtGelernt: [],
|
||||||
|
// für Mittel
|
||||||
|
ziehKarten: [],
|
||||||
|
rundeNummer: 0,
|
||||||
|
richtung: "EN_DE",
|
||||||
|
zuordnungen: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Startet das Training im Modus "Leicht".
|
||||||
function startLeichtTraining() {
|
function startLeichtTraining() {
|
||||||
console.log("🔥 startLeichtTraining вызвана");
|
trainingsZustand.modus = "leicht";
|
||||||
|
|
||||||
if (!parsedArray || parsedArray.length === 0) {
|
|
||||||
alert("Нет карточек для тренировки");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
trainingsZustand.quelleKarten = [...parsedArray];
|
trainingsZustand.quelleKarten = [...parsedArray];
|
||||||
trainingsZustand.aktiveKarten = [];
|
trainingsZustand.aktiveKarten = [];
|
||||||
trainingsZustand.gelernt = [];
|
trainingsZustand.gelernt = [];
|
||||||
@@ -173,10 +175,231 @@ function startLeichtTraining() {
|
|||||||
trainingsZustand.aktiveKarten.push(karte);
|
trainingsZustand.aktiveKarten.push(karte);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
zeigeNaechsteKarte();
|
zeigeNaechsteKarte();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Startet das Training im Modus "Mittel".
|
||||||
|
function startMittelTraining() {
|
||||||
|
trainingsZustand.modus = "mittel";
|
||||||
|
trainingsZustand.basisKarten = parsedArray.map(karte => ({
|
||||||
|
...karte,
|
||||||
|
// richtigEN: 0,
|
||||||
|
// richtigDE: 0,
|
||||||
|
// fehler: 0,
|
||||||
|
// verbleibend: 2
|
||||||
|
erfolge: 0,
|
||||||
|
fehler: 0
|
||||||
|
}));
|
||||||
|
|
||||||
|
trainingsZustand.gelernt = [];
|
||||||
|
trainingsZustand.nichtGelernt = [];
|
||||||
|
trainingsZustand.rundeNummer = 0;
|
||||||
|
|
||||||
|
ladeMittelRunde();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lädt eine neue Runde im mittleren Trainingsmodus.
|
||||||
|
function ladeMittelRunde() {
|
||||||
|
trainingsZustand.aktiveKarten = [];
|
||||||
|
trainingsZustand.ziehKarten = [];
|
||||||
|
trainingsZustand.zuordnungen = 0;
|
||||||
|
|
||||||
|
trainingsZustand.richtung = trainingsZustand.rundeNummer % 2 === 0 ? "EN_DE" : "DE_EN";
|
||||||
|
trainingsZustand.rundeNummer++;
|
||||||
|
|
||||||
|
mischeArray(trainingsZustand.basisKarten);
|
||||||
|
|
||||||
|
trainingsZustand.aktiveKarten = trainingsZustand.basisKarten.slice(0, 4);
|
||||||
|
|
||||||
|
if(trainingsZustand.aktiveKarten.length === 0) {
|
||||||
|
alert(`Training beendet!
|
||||||
|
Gelernt: ${trainingsZustand.gelernt.length}
|
||||||
|
Nicht gelernt: ${trainingsZustand.nichtGelernt.length}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
trainingsZustand.ziehKarten = mischeArray([...trainingsZustand.aktiveKarten]);
|
||||||
|
|
||||||
|
renderMittelMatching();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rendert das Matching-Layout für den mittleren Modus.
|
||||||
|
function renderMittelMatching() {
|
||||||
|
const container = document.getElementById("trainingMittel");
|
||||||
|
container.innerHTML = "";
|
||||||
|
|
||||||
|
const links = document.createElement("div");
|
||||||
|
links.className = "spalte-links";
|
||||||
|
|
||||||
|
const rechts = document.createElement("div");
|
||||||
|
rechts.className = "spalte-rechts";
|
||||||
|
|
||||||
|
// Linke Zone
|
||||||
|
trainingsZustand.aktiveKarten.forEach(karte => {
|
||||||
|
const dropZone = document.createElement("div");
|
||||||
|
dropZone.className = "training-card drop-zone";
|
||||||
|
dropZone.dataset.id = karte.id;
|
||||||
|
|
||||||
|
if(trainingsZustand.richtung === "EN_DE") {
|
||||||
|
dropZone.innerHTML = `
|
||||||
|
<div class="">
|
||||||
|
<h2>${karte.englisch}</h2>
|
||||||
|
<div class="ipa">${karte.ipa}</div>
|
||||||
|
<div class="example">${karte.beispielEN}</div>
|
||||||
|
</div>
|
||||||
|
`;} else {
|
||||||
|
dropZone.innerHTML = `
|
||||||
|
<div class="">
|
||||||
|
<h2>${karte.deutsch}</h2>
|
||||||
|
<div class="example">${karte.beispielDE}</div>
|
||||||
|
</div>
|
||||||
|
`;}
|
||||||
|
|
||||||
|
links.appendChild(dropZone);
|
||||||
|
});
|
||||||
|
|
||||||
|
// draggable + droppable (swap)
|
||||||
|
trainingsZustand.ziehKarten.forEach((karte, index) => {
|
||||||
|
const ziehKarte = document.createElement("div");
|
||||||
|
ziehKarte.className = "training-card zieh-karte";
|
||||||
|
ziehKarte.draggable = true;
|
||||||
|
ziehKarte.dataset.index = index;
|
||||||
|
|
||||||
|
if(trainingsZustand.richtung === "EN_DE") {
|
||||||
|
ziehKarte.innerHTML = `
|
||||||
|
<div class="">
|
||||||
|
<h2>${karte.deutsch}</h2>
|
||||||
|
<div class="example">${karte.beispielDE}</div>
|
||||||
|
</div>
|
||||||
|
`;} else {
|
||||||
|
ziehKarte.innerHTML = `
|
||||||
|
<div class="">
|
||||||
|
<h2>${karte.englisch}</h2>
|
||||||
|
<div class="ipa">${karte.ipa}</div>
|
||||||
|
<div class="example">${karte.beispielEN}</div>
|
||||||
|
</div>
|
||||||
|
`;}
|
||||||
|
|
||||||
|
// dragstart
|
||||||
|
ziehKarte.addEventListener("dragstart", e => {
|
||||||
|
console.log("dragstart работает");
|
||||||
|
e.dataTransfer.setData("draggedIndex", index);
|
||||||
|
});
|
||||||
|
|
||||||
|
// dragover
|
||||||
|
ziehKarte.addEventListener("dragover", e => {
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
// drop
|
||||||
|
ziehKarte.addEventListener("drop", e => {
|
||||||
|
console.log("drop работает");
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
const draggedIndex = Number(e.dataTransfer.getData("draggedIndex"));
|
||||||
|
// const targetId = karte.id;
|
||||||
|
|
||||||
|
swapZiehKarten(draggedIndex, index);
|
||||||
|
});
|
||||||
|
|
||||||
|
rechts.appendChild(ziehKarte);
|
||||||
|
});
|
||||||
|
|
||||||
|
container.appendChild(links);
|
||||||
|
container.appendChild(rechts);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Überprüft, ob die Zuordnungen korrekt sind.
|
||||||
|
function pruefeRunde() {
|
||||||
|
|
||||||
|
const ziehElemente = document.querySelectorAll(".zieh-karte");
|
||||||
|
|
||||||
|
trainingsZustand.aktiveKarten.forEach((karte, index) => {
|
||||||
|
|
||||||
|
const gezogene = trainingsZustand.ziehKarten[index];
|
||||||
|
const element = ziehElemente[index];
|
||||||
|
|
||||||
|
element.style.backgroundColor = "";
|
||||||
|
|
||||||
|
if (karte.id === gezogene.id) {
|
||||||
|
element.style.backgroundColor = "#a8f0a8";
|
||||||
|
karte.erfolge++;
|
||||||
|
} else {
|
||||||
|
element.style.backgroundColor = "#f5a8a8";
|
||||||
|
karte.fehler++;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
beendeMittelRunde();
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bewertet nach jeder Runde den Lernstatus jeder Karte.
|
||||||
|
function beendeMittelRunde() {
|
||||||
|
|
||||||
|
const verbleibende = [];
|
||||||
|
|
||||||
|
trainingsZustand.basisKarten.forEach(karte => {
|
||||||
|
|
||||||
|
if (karte.erfolge >= 2) {
|
||||||
|
trainingsZustand.gelernt.push(karte);
|
||||||
|
}
|
||||||
|
else if (karte.fehler >= 4) {
|
||||||
|
trainingsZustand.nichtGelernt.push(karte);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
verbleibende.push(karte);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
trainingsZustand.basisKarten = verbleibende;
|
||||||
|
|
||||||
|
if (trainingsZustand.basisKarten.length === 0) {
|
||||||
|
alert(`Training beendet!
|
||||||
|
Gelernt: ${trainingsZustand.gelernt.length}
|
||||||
|
Nicht gelernt: ${trainingsZustand.nichtGelernt.length}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ladeMittelRunde();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tauscht zwei Ziehkarten anhand ihrer Indizes
|
||||||
|
function swapZiehKarten(index1, index2) {
|
||||||
|
|
||||||
|
const temp = trainingsZustand.ziehKarten[index1];
|
||||||
|
trainingsZustand.ziehKarten[index1] =
|
||||||
|
trainingsZustand.ziehKarten[index2];
|
||||||
|
trainingsZustand.ziehKarten[index2] = temp;
|
||||||
|
|
||||||
|
renderMittelMatching();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Überprüft eine einzelne Zuordnung im Matching-Modus.
|
||||||
|
function pruefeZuordnung(ziehId, dropId) {
|
||||||
|
if(ziehId === dropId) {
|
||||||
|
const karte = trainingsZustand.aktiveKarten.find(k => k.id == ziehId);
|
||||||
|
|
||||||
|
trainingsZustand.gelernt.push(karte);
|
||||||
|
|
||||||
|
trainingsZustand.aktiveKarten = trainingsZustand.aktiveKarten.filter(k => k.id != ziehId);
|
||||||
|
|
||||||
|
trainingsZustand.ziehKarten = trainingsZustand.ziehKarten.filter(k => k.id != ziehId);
|
||||||
|
|
||||||
|
renderMittelMatching();
|
||||||
|
|
||||||
|
if(trainingsZustand.aktiveKarten.length === 0) {
|
||||||
|
ladeMittelRunde();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log("Falsh zugeorgnet");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wählt zufällig eine aktive Karte aus
|
||||||
function zeigeNaechsteKarte() {
|
function zeigeNaechsteKarte() {
|
||||||
if (
|
if (
|
||||||
trainingsZustand.aktiveKarten.length === 0 &&
|
trainingsZustand.aktiveKarten.length === 0 &&
|
||||||
@@ -198,6 +421,7 @@ function zeigeNaechsteKarte() {
|
|||||||
renderLeichtKarte(trainingsZustand.aktuelleKarte);
|
renderLeichtKarte(trainingsZustand.aktuelleKarte);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rendert eine einzelne Karte im leichten Modus.
|
||||||
function renderLeichtKarte(karte) {
|
function renderLeichtKarte(karte) {
|
||||||
const container = document.getElementById("trainingLeicht");
|
const container = document.getElementById("trainingLeicht");
|
||||||
container.innerHTML = "";
|
container.innerHTML = "";
|
||||||
@@ -223,8 +447,8 @@ function renderLeichtKarte(karte) {
|
|||||||
const actions = document.createElement("div");
|
const actions = document.createElement("div");
|
||||||
actions.className = "training-actions";
|
actions.className = "training-actions";
|
||||||
actions.innerHTML = `
|
actions.innerHTML = `
|
||||||
<button id="knowBtn">✔️ Weiß ich</button>
|
<button id="knowBtn">Weiß ich</button>
|
||||||
<button id="dontKnowBtn">❌ Weiß ich nicht</button>
|
<button id="dontKnowBtn">Weiß ich nicht</button>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
actions.querySelector("#knowBtn").onclick = () => antworteAufKarte(true);
|
actions.querySelector("#knowBtn").onclick = () => antworteAufKarte(true);
|
||||||
@@ -234,6 +458,7 @@ function renderLeichtKarte(karte) {
|
|||||||
container.appendChild(actions);
|
container.appendChild(actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verarbeitet die Antwort des Nutzers im leichten Modus.
|
||||||
function antworteAufKarte(weißIch) {
|
function antworteAufKarte(weißIch) {
|
||||||
const karte = trainingsZustand.aktuelleKarte;
|
const karte = trainingsZustand.aktuelleKarte;
|
||||||
|
|
||||||
@@ -259,51 +484,49 @@ function antworteAufKarte(weißIch) {
|
|||||||
zeigeNaechsteKarte();
|
zeigeNaechsteKarte();
|
||||||
}
|
}
|
||||||
|
|
||||||
function showView(id) {
|
// Blendet alle Trainingslevel-Ansichten aus
|
||||||
document.querySelectorAll(".modus-view").forEach(view => {
|
function showMode(id) {
|
||||||
view.style.display = "none";
|
|
||||||
});
|
|
||||||
|
|
||||||
const active = document.getElementById(id);
|
document.getElementById("pdfPages").style.display = "none";
|
||||||
if (active) {
|
document.getElementById("onlineTraining").style.display = "none";
|
||||||
active.style.display = "block";
|
|
||||||
}
|
document.getElementById(id).style.display = "block";
|
||||||
}
|
}
|
||||||
|
|
||||||
function showTrainingLevel(id) {
|
function showLevel(id) {
|
||||||
document.querySelectorAll(".training-view").forEach(view => {
|
console.log("showLevel called with:", id);
|
||||||
view.style.display = "none";
|
|
||||||
});
|
|
||||||
|
|
||||||
const active = document.getElementById(id);
|
document.getElementById("trainingLeicht").style.display = "none";
|
||||||
if (active) {
|
document.getElementById("trainingMittel").style.display = "none";
|
||||||
active.style.display = "block";
|
document.getElementById("trainingSchwer").style.display = "none";
|
||||||
}
|
|
||||||
|
document.getElementById(id).style.display = "block";
|
||||||
}
|
}
|
||||||
|
|
||||||
document.querySelectorAll(".level-btn").forEach(btn => {
|
document.querySelectorAll(".level-btn").forEach(btn => {
|
||||||
btn.addEventListener("click", () => {
|
btn.addEventListener("click", () => {
|
||||||
const level = btn.dataset.level;
|
const level = btn.dataset.level;
|
||||||
|
console.log("Level ausgewähl:", level);
|
||||||
|
|
||||||
if (level === "leicht") {
|
if (level === "leicht") {
|
||||||
showTrainingLevel("trainingLeicht");
|
showLevel("trainingLeicht");
|
||||||
startLeichtTraining();
|
startLeichtTraining();
|
||||||
|
|
||||||
|
document.getElementById("checkBtn").style.display = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level === "mittel") {
|
if (level === "mittel") {
|
||||||
showTrainingLevel("trainingMittel");
|
showLevel("trainingMittel");
|
||||||
startMittelTraining();
|
startMittelTraining();
|
||||||
|
|
||||||
|
document.getElementById("checkBtn").style.display = "block";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level === "schwer") {
|
if (level === "schwer") {
|
||||||
showTrainingLevel("trainingSchwer");
|
showLevel("trainingSchwer");
|
||||||
startSchwerTraining();
|
startSchwerTraining();
|
||||||
|
|
||||||
|
document.getElementById("checkBtn").style.display = "none";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
document
|
|
||||||
.querySelector(".modus-btn[data-modus='training_einfach']")
|
|
||||||
.addEventListener("click", () => {
|
|
||||||
showView("onlineTraining");
|
|
||||||
});
|
|
||||||
|
|||||||
@@ -283,12 +283,22 @@ h1 {
|
|||||||
|
|
||||||
.training-card {
|
.training-card {
|
||||||
width: 300px;
|
width: 300px;
|
||||||
height: 180px;
|
|
||||||
margin: 10px auto;
|
margin: 10px auto;
|
||||||
perspective: 1000px;
|
perspective: 1000px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#trainingLeicht .training-card {
|
||||||
|
height: 180px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#trainingMittel .training-card {
|
||||||
|
height: 100px;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
margin: 0;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.training-card-inner {
|
.training-card-inner {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
@@ -356,11 +366,59 @@ h1 {
|
|||||||
margin-top: -28px;
|
margin-top: -28px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.modus-view {
|
#pdfPages,
|
||||||
|
#onlineTraining,
|
||||||
|
#trainingLeicht,
|
||||||
|
#trainingMittel,
|
||||||
|
#trainingSchwer {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.training-view {
|
#trainingMittel {
|
||||||
display: none;
|
display: flex !important;
|
||||||
margin-top: 25px;
|
justify-content: center;
|
||||||
|
gap: 10px;
|
||||||
|
align-items: flex-start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.spalte-links {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spalte-rechts {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.drop-zone, .zieh-karte {
|
||||||
|
padding: 10px;
|
||||||
|
margin: 10px 0;
|
||||||
|
background: #fff;
|
||||||
|
border: 2px solid #666;
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.zieh-karte {
|
||||||
|
cursor: grab;
|
||||||
|
}
|
||||||
|
|
||||||
|
#checkBtn {
|
||||||
|
width: 500px;
|
||||||
|
height: 100px;
|
||||||
|
font-size: 46px;
|
||||||
|
font-weight: 600;
|
||||||
|
font-family: -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||||
|
color: #dc6743;
|
||||||
|
border: none;
|
||||||
|
border-radius: 8px;
|
||||||
|
cursor: pointer;
|
||||||
|
box-sizing: border-box;
|
||||||
|
background: linear-gradient(rgba(255,255,255,0.7), rgba(255,255,255,0.9)), url("verified.jfif");
|
||||||
|
background-repeat: repeat;
|
||||||
|
background-size: 80px;
|
||||||
|
}
|
||||||
BIN
MainPage/stas/verified.jfif
Normal file
BIN
MainPage/stas/verified.jfif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
@@ -1,369 +1,299 @@
|
|||||||
// KONFIGURATION & BITMASKEN
|
|
||||||
|
|
||||||
|
|
||||||
// Die Namen der 7 Segmente (a bis g)
|
|
||||||
const SEGMENT_NAMEN = ["a", "b", "c", "d", "e", "f", "g"];
|
|
||||||
|
|
||||||
// Ein Mapping: Welches Segment hat welchen "Bit Wert"?
|
|
||||||
// a=1, b=2, c=4, d=8 ... das sind Zweierpotenzen.
|
|
||||||
const SEGMENT_INDEX = { a:0, b:1, c:2, d:3, e:4, f:5, g:6 };
|
|
||||||
|
|
||||||
// Diese Funktion rechnet eine Liste von Segmenten (z.B. "a", "b") in eine Zahl um.
|
const SEG = { a:0, b:1, c:2, d:3, e:4, f:5, g:6 };
|
||||||
function erstelleMuster(listeVonSegmenten) {
|
const segNames = ["a","b","c","d","e","f","g"];
|
||||||
let muster = 0;
|
|
||||||
for (const segmentBuchstabe of listeVonSegmenten) {
|
function maskFromSegments(list){
|
||||||
// 1 << X bedeutet: Schiebe die 1 um X Stellen nach links
|
let m = 0;
|
||||||
// Das | (ODER) fügt das Bit hinzu.
|
for(const s of list) m |= (1 << SEG[s]);
|
||||||
muster = muster | (1 << SEGMENT_INDEX[segmentBuchstabe]);
|
return m;
|
||||||
}
|
|
||||||
return muster;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hier speichern wir das Muster für jede Ziffer von 0 bis 9
|
|
||||||
const ZIFFERN_MUSTER = [
|
const DIGIT_MASK = [
|
||||||
erstelleMuster(["a","b","c","d","e","f"]), // 0
|
maskFromSegments(["a","b","c","d","e","f"]),
|
||||||
erstelleMuster(["b","c"]), // 1
|
maskFromSegments(["b","c"]),
|
||||||
erstelleMuster(["a","b","d","e","g"]), // 2
|
maskFromSegments(["a","b","d","e","g"]),
|
||||||
erstelleMuster(["a","b","c","d","g"]), // 3
|
maskFromSegments(["a","b","c","d","g"]),
|
||||||
erstelleMuster(["b","c","f","g"]), // 4
|
maskFromSegments(["b","c","f","g"]),
|
||||||
erstelleMuster(["a","c","d","f","g"]), // 5
|
maskFromSegments(["a","c","d","f","g"]),
|
||||||
erstelleMuster(["a","c","d","e","f","g"]), // 6
|
maskFromSegments(["a","c","d","e","f","g"]),
|
||||||
erstelleMuster(["a","b","c"]), // 7
|
maskFromSegments(["a","b","c"]),
|
||||||
erstelleMuster(["a","b","c","d","e","f","g"]), // 8
|
maskFromSegments(["a","b","c","d","e","f","g"]),
|
||||||
erstelleMuster(["a","b","c","d","f","g"]) // 9
|
maskFromSegments(["a","b","c","d","f","g"])
|
||||||
];
|
];
|
||||||
|
|
||||||
// Eine Rückwärts Suche: Welches Muster gehört zu welcher Zahl?
|
|
||||||
// Wir bauen eine Map (Liste), um das schnell zu finden.
|
const MASK_TO_DIGIT = new Map(DIGIT_MASK.map((m,d)=>[m,d]));
|
||||||
const MUSTER_ZU_ZAHL = new Map();
|
|
||||||
ZIFFERN_MUSTER.forEach((muster, zahl) => {
|
|
||||||
MUSTER_ZU_ZAHL.set(muster, zahl);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
function removableTargetsFromDigit(d){
|
||||||
|
const start = DIGIT_MASK[d];
|
||||||
// Zählt, wie viele Bits in einer Zahl auf 1 stehen.
|
const res = [];
|
||||||
// (Also: Wie viele Streichhölzer sind an?)
|
for(let t=0;t<=9;t++){
|
||||||
function zaehleStreichhoelzer(zahl) {
|
const target = DIGIT_MASK[t];
|
||||||
let anzahl = 0;
|
if((target & start) === target){
|
||||||
// Solange die Zahl nicht 0 ist
|
|
||||||
while (zahl > 0) {
|
const removed = popcount(start ^ target);
|
||||||
// Ein kleiner Trick, um das letzte Bit zu löschen und zu zählen
|
res.push({to:t, removed});
|
||||||
zahl = zahl & (zahl - 1);
|
}
|
||||||
anzahl++;
|
|
||||||
}
|
}
|
||||||
return anzahl;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gibt eine zufällige Zahl zwischen min und max zurück
|
function popcount(x){
|
||||||
function zufallsZahl(min, max) {
|
x = x >>> 0;
|
||||||
|
let c = 0;
|
||||||
|
while(x){ x &= (x-1); c++; }
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
function randInt(min, max){ // inclusive
|
||||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||||
}
|
}
|
||||||
|
function pick(arr){ return arr[randInt(0, arr.length-1)]; }
|
||||||
|
|
||||||
// Wählt ein zufälliges Element aus einer Liste
|
let level = 1;
|
||||||
function wähleZufällig(liste) {
|
let targetRemove = 2;
|
||||||
return liste[zufallsZahl(0, liste.length - 1)];
|
let current = null;
|
||||||
}
|
let solution = null;
|
||||||
|
let removedSoFar = 0;
|
||||||
// Findet alle Zahlen, aus denen man 'basisZahl' machen kann, indem man Hölzer entfernt.
|
|
||||||
// Beispiel: Aus einer 8 kann man eine 0 machen (Mitte wegnehmen).
|
|
||||||
// Aber aus einer 1 kann man keine 8 machen (man müsste hinzufügen).
|
|
||||||
function findeMoeglicheUrsprungsZiffern(basisZahl) {
|
|
||||||
const basisMuster = ZIFFERN_MUSTER[basisZahl];
|
|
||||||
const moegliche = [];
|
|
||||||
|
|
||||||
for (let z = 0; z <= 9; z++) {
|
|
||||||
const vergleichsMuster = ZIFFERN_MUSTER[z];
|
|
||||||
|
|
||||||
// Wenn das vergleichsMuster ALLE Striche vom basisMuster hat:
|
|
||||||
if ((vergleichsMuster & basisMuster) === basisMuster) {
|
|
||||||
moegliche.push(z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return moegliche;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
let removedSet = new Set();
|
||||||
|
|
||||||
|
const elEq = document.getElementById("equation");
|
||||||
|
const elRemovedGrid = document.getElementById("removedGrid");
|
||||||
|
const elRemovedCount = document.getElementById("removedCount");
|
||||||
|
const elPileCount = document.getElementById("pileCount");
|
||||||
|
const elLvl = document.getElementById("lvl");
|
||||||
|
const elTarget = document.getElementById("target");
|
||||||
|
const elGoalN = document.getElementById("goalN");
|
||||||
|
const elTruthDot = document.getElementById("truthDot");
|
||||||
|
const elTruthText = document.getElementById("truthText");
|
||||||
|
const elHint = document.getElementById("hint");
|
||||||
|
|
||||||
let aktuellesLevel = 1;
|
|
||||||
let zielAnzahlLoeschen = 2; // Wie viele muss man löschen?
|
|
||||||
let anzahlGeloescht = 0; // Wie viele hat der Spieler schon gelöscht?
|
|
||||||
|
|
||||||
// Hier speichern wir die aktuellen Zahlen auf dem Bildschirm
|
|
||||||
let aktuelleGleichung = { A: 0, B: 0, C: 0 };
|
|
||||||
|
|
||||||
// Hier merken wir uns, welche Striche der Spieler angeklickt hat.
|
|
||||||
// Format: "Index-Segment", z.B. "0-a" (Erste Ziffer, Segment a)
|
|
||||||
let geloeschteStreichhoelzer = new Set();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const elGleichung = document.getElementById("equation");
|
|
||||||
const elGeloeschtGrid = document.getElementById("removedGrid");
|
|
||||||
const elZaehlerGeloescht = document.getElementById("removedCount");
|
|
||||||
const elStapelZaehler = document.getElementById("pileCount");
|
|
||||||
const elLevelAnzeige = document.getElementById("lvl");
|
|
||||||
const elZielAnzeige = document.getElementById("target");
|
|
||||||
const elZielText = document.getElementById("goalN");
|
|
||||||
const elWahrheitPunkt = document.getElementById("truthDot");
|
|
||||||
const elWahrheitText = document.getElementById("truthText");
|
|
||||||
const elHinweis = document.getElementById("hint");
|
|
||||||
|
|
||||||
// Buttons aktivieren
|
|
||||||
document.getElementById("btnNew").addEventListener("click", () => {
|
document.getElementById("btnNew").addEventListener("click", () => {
|
||||||
aktuellesLevel++;
|
level++;
|
||||||
starteNeuesLevel();
|
generateLevel();
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("btnReset").addEventListener("click", () => {
|
document.getElementById("btnReset").addEventListener("click", () => {
|
||||||
// Level neu starten (aber gleiches Level)
|
|
||||||
setzeSpielZurueck();
|
resetPlayState();
|
||||||
zeichneGleichung();
|
renderEquation();
|
||||||
pruefeObWahr();
|
updateTruthUI();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function segmentsFromMask(mask){
|
||||||
|
const set = new Set();
|
||||||
function setzeSpielZurueck() {
|
for(let i=0;i<7;i++){
|
||||||
geloeschteStreichhoelzer.clear(); // Liste leeren
|
if(mask & (1<<i)) set.add(segNames[i]);
|
||||||
anzahlGeloescht = 0;
|
}
|
||||||
elGeloeschtGrid.innerHTML = ""; // Anzeige leeren
|
return set;
|
||||||
updateZaehlerAnzeige();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateZaehlerAnzeige() {
|
function displayedMaskForDigit(digitValue, digitIndex){
|
||||||
elZaehlerGeloescht.textContent = anzahlGeloescht;
|
let mask = DIGIT_MASK[digitValue];
|
||||||
elStapelZaehler.textContent = anzahlGeloescht;
|
for(const s of segNames){
|
||||||
}
|
const key = digitIndex + "-" + s;
|
||||||
|
if(removedSet.has(key)){
|
||||||
// Berechnet, welche Zahl gerade angezeigt wird (basierend auf dem was gelöscht wurde)
|
mask &= ~(1 << SEG[s]);
|
||||||
function berechneAngezeigteZahl(originalZahl, positionIndex) {
|
|
||||||
let maske = ZIFFERN_MUSTER[originalZahl];
|
|
||||||
|
|
||||||
// Wir gehen alle 7 Segmente durch
|
|
||||||
for (const seg of SEGMENT_NAMEN) {
|
|
||||||
const schluessel = positionIndex + "-" + seg;
|
|
||||||
|
|
||||||
// Wenn dieses Segment gelöscht wurde...
|
|
||||||
if (geloeschteStreichhoelzer.has(schluessel)) {
|
|
||||||
// ... dann schalten wir das Bit in der Maske aus (mit & ~)
|
|
||||||
maske = maske & ~(1 << SEGMENT_INDEX[seg]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return mask;
|
||||||
// Schauen, ob das resultierende Muster eine gültige Zahl ist
|
|
||||||
if (MUSTER_ZU_ZAHL.has(maske)) {
|
|
||||||
return MUSTER_ZU_ZAHL.get(maske);
|
|
||||||
} else {
|
|
||||||
return null; // Keine gültige Zahl (Kaputt)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prüft: Ist A + B = C ?
|
function displayedDigitValue(digitValue, digitIndex){
|
||||||
function istGleichungWahr() {
|
const mask = displayedMaskForDigit(digitValue, digitIndex);
|
||||||
const a = berechneAngezeigteZahl(aktuelleGleichung.A, 0);
|
return MASK_TO_DIGIT.has(mask) ? MASK_TO_DIGIT.get(mask) : null;
|
||||||
const b = berechneAngezeigteZahl(aktuelleGleichung.B, 1);
|
}
|
||||||
const c = berechneAngezeigteZahl(aktuelleGleichung.C, 2);
|
|
||||||
|
|
||||||
// Wenn irgendeine Zahl ungültig ist, ist die Gleichung falsch
|
function equationIsTrue(){
|
||||||
if (a === null || b === null || c === null) return false;
|
|
||||||
|
|
||||||
|
const a = displayedDigitValue(current.A, 0);
|
||||||
|
const b = displayedDigitValue(current.B, 1);
|
||||||
|
const c = displayedDigitValue(current.C, 2);
|
||||||
|
if(a === null || b === null || c === null) return false;
|
||||||
return (a + b) === c;
|
return (a + b) === c;
|
||||||
}
|
}
|
||||||
|
|
||||||
function pruefeObWahr() {
|
function updateTruthUI(){
|
||||||
const istWahr = istGleichungWahr();
|
const ok = equationIsTrue();
|
||||||
|
elTruthDot.classList.toggle("ok", ok);
|
||||||
if (istWahr) {
|
elTruthText.textContent = ok ? "Equation is TRUE" : "Equation is FALSE";
|
||||||
elWahrheitPunkt.classList.add("ok");
|
|
||||||
elWahrheitText.textContent = "Gleichung ist WAHR";
|
|
||||||
} else {
|
|
||||||
elWahrheitPunkt.classList.remove("ok");
|
|
||||||
elWahrheitText.textContent = "Gleichung ist FALSCH";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Erstellt das HTML für EINE Ziffer
|
function resetPlayState(){
|
||||||
function erstelleZifferHTML(zahlenWert, positionIndex, farbe) {
|
removedSet.clear();
|
||||||
const zifferContainer = document.createElement("div");
|
removedSoFar = 0;
|
||||||
zifferContainer.className = "digit";
|
elRemovedGrid.innerHTML = "";
|
||||||
|
syncRemovedCounts();
|
||||||
|
}
|
||||||
|
|
||||||
// Welche Segmente hat die Zahl ursprünglich?
|
function syncRemovedCounts(){
|
||||||
const maske = ZIFFERN_MUSTER[zahlenWert];
|
elRemovedCount.textContent = String(removedSoFar);
|
||||||
|
elPileCount.textContent = String(removedSoFar);
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 0; i < 7; i++) {
|
function renderDigit(digitValue, digitIndex, color){
|
||||||
const segName = SEGMENT_NAMEN[i];
|
const digit = document.createElement("div");
|
||||||
|
digit.className = "digit";
|
||||||
// Prüfen: Hat die Zahl dieses Segment? (Bit Test)
|
|
||||||
const hatSegment = (maske & (1 << i)) !== 0;
|
|
||||||
|
|
||||||
if (hatSegment) {
|
const baseMask = DIGIT_MASK[digitValue];
|
||||||
const segElement = document.createElement("div");
|
const baseSegs = segmentsFromMask(baseMask);
|
||||||
segElement.className = "seg " + segName;
|
|
||||||
segElement.style.background = farbe;
|
|
||||||
|
|
||||||
// Eindeutige ID für dieses Segment (z.B. "0-a")
|
for(const s of segNames){
|
||||||
const id = positionIndex + "-" + segName;
|
if(!baseSegs.has(s)) continue;
|
||||||
|
|
||||||
// Wenn schon gelöscht, Klasse hinzufügen
|
const seg = document.createElement("div");
|
||||||
if (geloeschteStreichhoelzer.has(id)) {
|
seg.className = "seg " + s;
|
||||||
segElement.classList.add("removed");
|
seg.style.background = color;
|
||||||
}
|
|
||||||
|
|
||||||
// Klick Event (Hier passiert die Action!)
|
const key = digitIndex + "-" + s;
|
||||||
segElement.addEventListener("click", () => {
|
if(removedSet.has(key)) seg.classList.add("removed");
|
||||||
// Abbruch wenn schon weg oder Limit erreicht
|
|
||||||
if (geloeschteStreichhoelzer.has(id)) return;
|
|
||||||
if (anzahlGeloescht >= zielAnzahlLoeschen) return;
|
|
||||||
|
|
||||||
// Löschen durchführen
|
seg.addEventListener("click", () => {
|
||||||
geloeschteStreichhoelzer.add(id);
|
if(removedSet.has(key)) return;
|
||||||
anzahlGeloescht++;
|
if(removedSoFar >= targetRemove) return;
|
||||||
segElement.classList.add("removed");
|
|
||||||
|
|
||||||
// Kleines Streichholz in den Mülleimer animieren
|
removedSet.add(key);
|
||||||
const clone = document.createElement("div");
|
removedSoFar++;
|
||||||
clone.className = "removedSeg";
|
|
||||||
clone.style.background = farbe;
|
|
||||||
elGeloeschtGrid.appendChild(clone);
|
|
||||||
|
|
||||||
updateZaehlerAnzeige();
|
|
||||||
pruefeObWahr();
|
|
||||||
|
|
||||||
// Gewinn Prüfung
|
seg.classList.add("removed");
|
||||||
if (anzahlGeloescht === zielAnzahlLoeschen) {
|
|
||||||
if (istGleichungWahr()) {
|
|
||||||
elHinweis.innerHTML = "<b>Gelöst!</b> Super gemacht. Klicke auf <b>Neu level</b>.";
|
const clone = document.createElement("div");
|
||||||
} else {
|
clone.className = "removedSeg";
|
||||||
elHinweis.innerHTML = "<b>Nicht gelöst.</b> Alle Züge verbraucht, aber Gleichung falsch. <b>Reset</b>?";
|
clone.style.background = color;
|
||||||
}
|
elRemovedGrid.appendChild(clone);
|
||||||
|
|
||||||
|
syncRemovedCounts();
|
||||||
|
updateTruthUI();
|
||||||
|
|
||||||
|
if(removedSoFar === targetRemove){
|
||||||
|
if(equationIsTrue()){
|
||||||
|
elHint.innerHTML = "<b>Solved!</b> You removed exactly the target and made the equation true. Click <b>New level</b>.";
|
||||||
|
} else {
|
||||||
|
elHint.innerHTML = " <b>Not solved.</b> You used all removals but the equation isn’t true. Click <b>Reset level</b> to try again.";
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
zifferContainer.appendChild(segElement);
|
digit.appendChild(seg);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return zifferContainer;
|
return digit;
|
||||||
}
|
}
|
||||||
|
|
||||||
function zeichneGleichung() {
|
function renderEquation(){
|
||||||
elGleichung.innerHTML = ""; // Alles löschen
|
elEq.innerHTML = "";
|
||||||
|
|
||||||
const farben = [
|
const colors = [
|
||||||
"linear-gradient(180deg,#ff6b6b,#d64545)", // Rot für A
|
"linear-gradient(180deg,#ff6b6b,#d64545)",
|
||||||
"linear-gradient(180deg,#6bcBff,#3a7bd5)", // Blau für B
|
"linear-gradient(180deg,#6bcBff,#3a7bd5)",
|
||||||
"linear-gradient(180deg,#6bffb3,#1fae63)" // Grün für C
|
"linear-gradient(180deg,#6bffb3,#1fae63)"
|
||||||
];
|
];
|
||||||
|
|
||||||
// Gruppe A bauen
|
|
||||||
const g1 = document.createElement("div");
|
const g1 = document.createElement("div");
|
||||||
g1.className = "group";
|
g1.className = "group";
|
||||||
g1.appendChild(erstelleZifferHTML(aktuelleGleichung.A, 0, farben[0]));
|
g1.appendChild(renderDigit(current.A, 0, colors[0]));
|
||||||
|
|
||||||
// Plus Zeichen
|
|
||||||
const plus = document.createElement("div");
|
const plus = document.createElement("div");
|
||||||
plus.className = "symbol";
|
plus.className = "symbol";
|
||||||
plus.textContent = "+";
|
plus.textContent = "+";
|
||||||
|
|
||||||
// Gruppe B bauen
|
|
||||||
const g2 = document.createElement("div");
|
const g2 = document.createElement("div");
|
||||||
g2.className = "group";
|
g2.className = "group";
|
||||||
g2.appendChild(erstelleZifferHTML(aktuelleGleichung.B, 1, farben[1]));
|
g2.appendChild(renderDigit(current.B, 1, colors[1]));
|
||||||
|
|
||||||
// Ist Gleich Zeichen
|
|
||||||
const eq = document.createElement("div");
|
const eq = document.createElement("div");
|
||||||
eq.className = "symbol";
|
eq.className = "symbol";
|
||||||
eq.textContent = "=";
|
eq.textContent = "=";
|
||||||
|
|
||||||
// Gruppe C bauen
|
|
||||||
const g3 = document.createElement("div");
|
const g3 = document.createElement("div");
|
||||||
g3.className = "group";
|
g3.className = "group";
|
||||||
g3.appendChild(erstelleZifferHTML(aktuelleGleichung.C, 2, farben[2]));
|
g3.appendChild(renderDigit(current.C, 2, colors[2]));
|
||||||
|
|
||||||
// Alles zusammenfügen
|
elEq.appendChild(g1);
|
||||||
elGleichung.appendChild(g1);
|
elEq.appendChild(plus);
|
||||||
elGleichung.appendChild(plus);
|
elEq.appendChild(g2);
|
||||||
elGleichung.appendChild(g2);
|
elEq.appendChild(eq);
|
||||||
elGleichung.appendChild(eq);
|
elEq.appendChild(g3);
|
||||||
elGleichung.appendChild(g3);
|
|
||||||
|
|
||||||
pruefeObWahr();
|
updateTruthUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 7. LEVEL GENERATOR (Das Gehirn)
|
function generateLevel(){
|
||||||
// Hier wird ein Level gebaut, das garantiert lösbar ist.
|
resetPlayState();
|
||||||
|
|
||||||
|
|
||||||
function starteNeuesLevel() {
|
|
||||||
setzeSpielZurueck();
|
targetRemove = Math.min(2 + Math.floor(Math.log2(level + 1)), 6);
|
||||||
|
|
||||||
// Ziel berechnen: Level 1-2 -> 2 löschen, danach evtl mehr. Max 6.
|
|
||||||
zielAnzahlLoeschen = Math.min(2 + Math.floor(Math.log2(aktuellesLevel + 1)), 6);
|
|
||||||
|
|
||||||
let versuche = 0;
|
let tries = 0;
|
||||||
|
while(true){
|
||||||
// Endlosschleife, bis wir ein passendes Level finden
|
tries++;
|
||||||
while (true) {
|
if(tries > 5000){
|
||||||
versuche++;
|
targetRemove = Math.max(2, targetRemove - 1);
|
||||||
// Sicherheitsnetz: Wenn es zu lange dauert, Ziel senken
|
tries = 0;
|
||||||
if (versuche > 5000) {
|
|
||||||
zielAnzahlLoeschen = Math.max(2, zielAnzahlLoeschen - 1);
|
|
||||||
versuche = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1. Wir denken uns eine KORREKTE Lösung aus (z.B. 3 + 5 = 8)
|
const As = randInt(0, 9);
|
||||||
const lsgA = zufallsZahl(0, 9);
|
const Bs = randInt(0, 9);
|
||||||
const lsgB = zufallsZahl(0, 9);
|
const Cs = As + Bs;
|
||||||
const lsgC = lsgA + lsgB;
|
if(Cs < 0 || Cs > 9) continue;
|
||||||
|
|
||||||
if (lsgC > 9) continue; // Ergebnis darf nur 1 stellig sein (0-9)
|
|
||||||
|
|
||||||
// 2. Wir suchen Zahlen, die mehr Striche haben als unsere Lösung
|
|
||||||
// (Aus denen man die Lösung "schnitzen" kann)
|
|
||||||
const moeglicheA = findeMoeglicheUrsprungsZiffern(lsgA);
|
|
||||||
const moeglicheB = findeMoeglicheUrsprungsZiffern(lsgB);
|
|
||||||
const moeglicheC = findeMoeglicheUrsprungsZiffern(lsgC);
|
|
||||||
|
|
||||||
// Eine zufällige Auswahl treffen
|
|
||||||
const startA = wähleZufällig(moeglicheA);
|
|
||||||
const startB = wähleZufällig(moeglicheB);
|
|
||||||
const startC = wähleZufällig(moeglicheC);
|
|
||||||
|
|
||||||
// 3. Berechnen: Wie viele Striche müssen weg, um zur Lösung zu kommen?
|
|
||||||
// XOR (^) zeigt den Unterschied an.
|
|
||||||
const diffA = zaehleStreichhoelzer(ZIFFERN_MUSTER[startA] ^ ZIFFERN_MUSTER[lsgA]);
|
|
||||||
const diffB = zaehleStreichhoelzer(ZIFFERN_MUSTER[startB] ^ ZIFFERN_MUSTER[lsgB]);
|
|
||||||
const diffC = zaehleStreichhoelzer(ZIFFERN_MUSTER[startC] ^ ZIFFERN_MUSTER[lsgC]);
|
|
||||||
|
|
||||||
const gesamtWeg = diffA + diffB + diffC;
|
const Achoices = superDigits(As);
|
||||||
|
const Bchoices = superDigits(Bs);
|
||||||
|
const Cchoices = superDigits(Cs);
|
||||||
|
|
||||||
// Passt das zu unserem Ziel?
|
const Ashow = pick(Achoices);
|
||||||
if (gesamtWeg !== zielAnzahlLoeschen) continue;
|
const Bshow = pick(Bchoices);
|
||||||
|
const Cshow = pick(Cchoices);
|
||||||
|
|
||||||
// 4. Wichtig: Die angezeigte Start Gleichung muss FALSCH sein.
|
const need =
|
||||||
// Sonst gibt es ja nichts zu rätseln.
|
popcount(DIGIT_MASK[Ashow] ^ DIGIT_MASK[As]) +
|
||||||
if ((startA + startB) === startC) continue;
|
popcount(DIGIT_MASK[Bshow] ^ DIGIT_MASK[Bs]) +
|
||||||
|
popcount(DIGIT_MASK[Cshow] ^ DIGIT_MASK[Cs]);
|
||||||
|
|
||||||
// Gefunden! Speichern.
|
if(need !== targetRemove) continue;
|
||||||
aktuelleGleichung = { A: startA, B: startB, C: startC };
|
|
||||||
break; // Schleife beenden
|
|
||||||
|
const shownTrue = (Ashow + Bshow) === Cshow;
|
||||||
|
if(shownTrue) continue;
|
||||||
|
|
||||||
|
solution = { A: As, B: Bs, C: Cs };
|
||||||
|
current = { A: Ashow, B: Bshow, C: Cshow };
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// UI Updates
|
elLvl.textContent = String(level);
|
||||||
elLevelAnzeige.textContent = aktuellesLevel;
|
elTarget.textContent = String(targetRemove);
|
||||||
elZielAnzeige.textContent = zielAnzahlLoeschen;
|
elGoalN.textContent = String(targetRemove);
|
||||||
elZielText.textContent = zielAnzahlLoeschen;
|
|
||||||
|
|
||||||
elHinweis.innerHTML =
|
elHint.innerHTML =
|
||||||
`Level <b>${aktuellesLevel}</b>: Mache die Gleichung wahr, indem du <b>${zielAnzahlLoeschen}</b> Streichhölzer entfernst.`;
|
`Level <b>${level}</b>: Make the equation true by removing <b>${targetRemove}</b> match(es). ` +
|
||||||
|
`You can only remove sticks (click them).`;
|
||||||
|
|
||||||
zeichneGleichung();
|
renderEquation();
|
||||||
|
syncRemovedCounts();
|
||||||
|
updateTruthUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Spiel starten!
|
function superDigits(baseDigit){
|
||||||
starteNeuesLevel();
|
const base = DIGIT_MASK[baseDigit];
|
||||||
|
const res = [];
|
||||||
|
for(let d=0; d<=9; d++){
|
||||||
|
const m = DIGIT_MASK[d];
|
||||||
|
if((m & base) === base){
|
||||||
|
res.push(d);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
generateLevel();
|
||||||
Reference in New Issue
Block a user