Online-Training: Flip, Multiple, Matching, Hint, Schreiben
This commit is contained in:
@@ -231,7 +231,7 @@ function zeigeNaechsteKarte() {
|
||||
|
||||
// Rendert eine einzelne Karte im leichten Modus.
|
||||
function renderLeichtKarte(karte) {
|
||||
const container = document.getElementById("trainingLeicht");
|
||||
const container = document.getElementById("trainingFlip");
|
||||
container.innerHTML = "";
|
||||
|
||||
const cardEl = document.createElement("div");
|
||||
@@ -307,7 +307,7 @@ function ladeMittelRunde() {
|
||||
|
||||
// Rendert das Matching-Layout für den mittleren Modus.
|
||||
function renderMittelMatching() {
|
||||
const container = document.getElementById("trainingMittel");
|
||||
const container = document.getElementById("trainingMatching");
|
||||
container.innerHTML = "";
|
||||
|
||||
const links = document.createElement("div");
|
||||
@@ -450,16 +450,49 @@ function beendeMittelRunde() {
|
||||
|
||||
// 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;
|
||||
[trainingsZustand.ziehKarten[index1], trainingsZustand.ziehKarten[index2]] =
|
||||
[trainingsZustand.ziehKarten[index2], trainingsZustand.ziehKarten[index1]];
|
||||
|
||||
const container = document.querySelector(".spalte-rechts");
|
||||
const cards = container.children;
|
||||
container.innerHTML = "";
|
||||
|
||||
container.insertBefore(cards[index2], cards[index1]);
|
||||
trainingsZustand.ziehKarten.forEach((karte, idx) => {
|
||||
const ziehKarte = document.createElement("div");
|
||||
ziehKarte.className = "training-card zieh-karte";
|
||||
ziehKarte.draggable = true;
|
||||
ziehKarte.dataset.index = idx;
|
||||
|
||||
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>
|
||||
`;
|
||||
}
|
||||
|
||||
ziehKarte.addEventListener("dragstart", e => {
|
||||
e.dataTransfer.setData("draggedIndex", idx);
|
||||
});
|
||||
|
||||
ziehKarte.addEventListener("dragover", e => e.preventDefault());
|
||||
|
||||
ziehKarte.addEventListener("drop", e => {
|
||||
e.preventDefault();
|
||||
const draggedIndex = Number(e.dataTransfer.getData("draggedIndex"));
|
||||
swapZiehKarten(draggedIndex, idx);
|
||||
});
|
||||
|
||||
container.appendChild(ziehKarte);
|
||||
});
|
||||
}
|
||||
|
||||
// Blendet alle Trainingslevel-Ansichten aus
|
||||
@@ -472,37 +505,260 @@ function showMode(id) {
|
||||
}
|
||||
|
||||
function showLevel(id) {
|
||||
document.getElementById("trainingLeicht").classList.add("hidden");
|
||||
document.getElementById("trainingMittel").classList.add("hidden");
|
||||
document.getElementById("trainingSchwer").classList.add("hidden");
|
||||
document.querySelectorAll("#onlineTraining .training-view").forEach(view => {
|
||||
if (view.id !== "trainingLevels") {
|
||||
view.classList.add("hidden");
|
||||
}
|
||||
});
|
||||
|
||||
document.getElementById(id).classList.remove("hidden");
|
||||
}
|
||||
|
||||
document.querySelectorAll(".level-btn").forEach(btn => {
|
||||
btn.addEventListener("click", () => {
|
||||
const level = btn.dataset.level;
|
||||
console.log("Level ausgewähl:", level);
|
||||
const type = btn.dataset.level;
|
||||
console.log("Trainingsart:", type);
|
||||
|
||||
if (level === "leicht") {
|
||||
showLevel("trainingLeicht");
|
||||
if (type === "flip") {
|
||||
showLevel("trainingFlip");
|
||||
startLeichtTraining();
|
||||
|
||||
document.getElementById("checkBtn").style.display = "none";
|
||||
}
|
||||
|
||||
if (level === "mittel") {
|
||||
showLevel("trainingMittel");
|
||||
if (type === "matching") {
|
||||
showLevel("trainingMatching");
|
||||
startMittelTraining();
|
||||
|
||||
document.getElementById("checkBtn").style.display = "block";
|
||||
}
|
||||
|
||||
if (level === "schwer") {
|
||||
showLevel("trainingSchwer");
|
||||
startSchwerTraining();
|
||||
if (type === "multiple") {
|
||||
showLevel("trainingMultiple");
|
||||
startMultipleTraining();
|
||||
document.getElementById("checkBtn").style.display = "none";
|
||||
}
|
||||
|
||||
if (type === "hint") {
|
||||
showLevel("trainingHint");
|
||||
startHintTraining();
|
||||
document.getElementById("checkBtn").style.display = "none";
|
||||
}
|
||||
|
||||
if (type === "write") {
|
||||
showLevel("trainingWrite");
|
||||
startWriteTraining();
|
||||
document.getElementById("checkBtn").style.display = "none";
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function startMultipleTraining() {
|
||||
trainingsZustand.modus = "multiple";
|
||||
trainingsZustand.quelleKarten = mischeArray([...parsedArray]);
|
||||
trainingsZustand.aktuelleKarte = null;
|
||||
trainingsZustand.gelernt = [];
|
||||
trainingsZustand.nichtGelernt = [];
|
||||
|
||||
zeigeNaechsteMultipleKarte();
|
||||
}
|
||||
|
||||
function generiereMultipleOptionen(karte) {
|
||||
const optionen = [karte.deutsch];
|
||||
|
||||
const falscheOptionen = parsedArray
|
||||
.filter(k => k.id !== karte.id)
|
||||
.map(k => k.deutsch);
|
||||
|
||||
mischeArray(falscheOptionen);
|
||||
|
||||
optionen.push(...falscheOptionen.slice(0, 4));
|
||||
|
||||
return mischeArray(optionen);
|
||||
}
|
||||
|
||||
function generiereHint(deutsch) {
|
||||
const chars = deutsch.split('');
|
||||
const anzahlZuVerstecken = Math.floor(chars.length / 2);
|
||||
|
||||
const indices = Array.from(chars.keys());
|
||||
mischeArray(indices);
|
||||
|
||||
for (let i = 0; i < anzahlZuVerstecken; i++) {
|
||||
chars[indices[i]] = '*';
|
||||
}
|
||||
|
||||
return chars.join('');
|
||||
}
|
||||
|
||||
|
||||
function zeigeNaechsteMultipleKarte() {
|
||||
if (trainingsZustand.quelleKarten.length === 0) {
|
||||
alert(`Training beendet!
|
||||
Gelernt: ${trainingsZustand.gelernt.length}
|
||||
Nicht gelernt: ${trainingsZustand.nichtGelernt.length}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const karte = trainingsZustand.quelleKarten.shift();
|
||||
trainingsZustand.aktuelleKarte = karte;
|
||||
|
||||
const container = document.getElementById("trainingMultiple");
|
||||
container.innerHTML = "";
|
||||
|
||||
const frage = document.createElement("div");
|
||||
frage.className = "multiple-frage";
|
||||
frage.innerHTML = `<h2>${karte.englisch}</h2>`;
|
||||
container.appendChild(frage);
|
||||
|
||||
const optionen = generiereMultipleOptionen(karte);
|
||||
const optionContainer = document.createElement("div");
|
||||
optionContainer.className = "multiple-optionen";
|
||||
|
||||
optionen.forEach(text => {
|
||||
const btn = document.createElement("button");
|
||||
btn.className = "multiple-option";
|
||||
btn.innerText = text;
|
||||
|
||||
btn.onclick = () => {
|
||||
if (text === karte.deutsch) {
|
||||
trainingsZustand.gelernt.push(karte);
|
||||
zeigeNaechsteMultipleKarte();
|
||||
} else {
|
||||
btn.style.textDecoration = "line-through";
|
||||
btn.disabled = true;
|
||||
}
|
||||
};
|
||||
|
||||
optionContainer.appendChild(btn);
|
||||
});
|
||||
|
||||
container.appendChild(optionContainer);
|
||||
}
|
||||
|
||||
trainingsZustand.hintCards = [];
|
||||
|
||||
function startHintTraining() {
|
||||
trainingsZustand.modus = "hint";
|
||||
trainingsZustand.hintCards = mischeArray([...parsedArray]);
|
||||
zeigeNaechsteHintKarte();
|
||||
}
|
||||
|
||||
function zeigeNaechsteHintKarte() {
|
||||
if (trainingsZustand.hintCards.length === 0) {
|
||||
alert(`Training beendet!
|
||||
Gelernt: ${trainingsZustand.gelernt.length}
|
||||
Nicht gelernt: ${trainingsZustand.nichtGelernt.length}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const karte = trainingsZustand.hintCards.shift();
|
||||
trainingsZustand.aktuelleKarte = karte;
|
||||
|
||||
const container = document.getElementById("trainingHint");
|
||||
container.innerHTML = "";
|
||||
|
||||
const frage = document.createElement("div");
|
||||
frage.className = "hint-frage";
|
||||
frage.innerHTML = `<h2>${karte.englisch}</h2>`;
|
||||
container.appendChild(frage);
|
||||
|
||||
const clue = document.createElement("div");
|
||||
clue.className = "hint-clue";
|
||||
clue.innerText = generiereHint(karte.deutsch);
|
||||
container.appendChild(clue);
|
||||
|
||||
const input = document.createElement("input");
|
||||
input.className = "hint-input";
|
||||
input.placeholder = "Schreibe die Übersetzung hier...";
|
||||
container.appendChild(input);
|
||||
|
||||
const button = document.createElement("button");
|
||||
button.className = "hint-button";
|
||||
button.innerText = "Überprüfen";
|
||||
container.appendChild(button);
|
||||
|
||||
const feedback = document.createElement("div");
|
||||
feedback.className = "hint-feedback";
|
||||
container.appendChild(feedback);
|
||||
|
||||
button.onclick = () => {
|
||||
const answer = input.value.trim();
|
||||
if (answer.toLowerCase() === karte.deutsch.toLowerCase()) {
|
||||
feedback.innerText = "✅ Richtig!";
|
||||
trainingsZustand.gelernt.push(karte);
|
||||
setTimeout(() => zeigeNaechsteHintKarte(), 800);
|
||||
} else {
|
||||
feedback.innerText = `❌ Falsch! Richtige Antwort: ${karte.deutsch}`;
|
||||
trainingsZustand.nichtGelernt.push(karte);
|
||||
setTimeout(() => zeigeNaechsteHintKarte(), 1200);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function startWriteTraining() {
|
||||
trainingsZustand.modus = "write";
|
||||
trainingsZustand.quelleKarten = mischeArray([...parsedArray]);
|
||||
trainingsZustand.aktuelleKarte = null;
|
||||
trainingsZustand.gelernt = [];
|
||||
trainingsZustand.nichtGelernt = [];
|
||||
|
||||
zeigeNaechsteWriteKarte();
|
||||
}
|
||||
|
||||
function zeigeNaechsteWriteKarte() {
|
||||
if (trainingsZustand.quelleKarten.length === 0) {
|
||||
const container = document.getElementById("trainingWrite");
|
||||
container.innerHTML = `
|
||||
<div class="schwer-frage">
|
||||
Training beendet!<br>
|
||||
Gelernt: ${trainingsZustand.gelernt.length}<br>
|
||||
Nicht gelernt: ${trainingsZustand.nichtGelernt.length}
|
||||
</div>
|
||||
`;
|
||||
return;
|
||||
}
|
||||
|
||||
const karte = trainingsZustand.quelleKarten.shift();
|
||||
trainingsZustand.aktuelleKarte = karte;
|
||||
|
||||
const container = document.getElementById("trainingWrite");
|
||||
container.innerHTML = "";
|
||||
|
||||
const frage = document.createElement("div");
|
||||
frage.className = "schwer-frage";
|
||||
frage.innerHTML = `<h2>${karte.englisch}</h2>`;
|
||||
container.appendChild(frage);
|
||||
|
||||
const input = document.createElement("input");
|
||||
input.type = "text";
|
||||
input.placeholder = "Schreibe die Übersetzung hier...";
|
||||
input.style.fontSize = "18px";
|
||||
input.style.width = "300px";
|
||||
input.style.padding = "8px";
|
||||
container.appendChild(input);
|
||||
|
||||
const submitBtn = document.createElement("button");
|
||||
submitBtn.innerText = "Überprüfen";
|
||||
submitBtn.style.marginTop = "10px";
|
||||
submitBtn.onclick = () => {
|
||||
const answer = input.value.trim();
|
||||
const resultDiv = document.createElement("div");
|
||||
resultDiv.style.marginTop = "12px";
|
||||
resultDiv.style.fontWeight = "600";
|
||||
|
||||
if (answer.toLowerCase() === karte.deutsch.toLowerCase()) {
|
||||
trainingsZustand.gelernt.push(karte);
|
||||
resultDiv.style.color = "#28a745";
|
||||
resultDiv.innerText = "Richtig!";
|
||||
} else {
|
||||
trainingsZustand.nichtGelernt.push(karte);
|
||||
resultDiv.style.color = "#dc3545";
|
||||
resultDiv.innerText = `Falsch! Richtige Antwort: ${karte.deutsch}`;
|
||||
}
|
||||
|
||||
container.appendChild(resultDiv);
|
||||
|
||||
setTimeout(() => zeigeNaechsteWriteKarte(), 2000);
|
||||
};
|
||||
|
||||
container.appendChild(submitBtn);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user