Compare commits
3 Commits
b1ffd825db
...
be159bcbf0
| Author | SHA1 | Date | |
|---|---|---|---|
| be159bcbf0 | |||
| 374be205b7 | |||
| 2e3c937b99 |
@@ -2,231 +2,171 @@
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>CROSSWORD</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Crossword Puzzle</title>
|
||||
<style>
|
||||
body { font-family: 'Courier New', monospace; font-size: 12px; padding: 16px; }
|
||||
|
||||
.dir-btn { font-family: 'Courier New', monospace; background: none; border: none; cursor: pointer; color: #999; padding-right: 6px; }
|
||||
.dir-btn.active { color: #000; font-weight: bold; }
|
||||
|
||||
.layout { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 8px; }
|
||||
|
||||
.crossword-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(21, 26px);
|
||||
border-top: 1px solid #000;
|
||||
border-left: 1px solid #000;
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.cell { width: 26px; height: 26px; border-right: 1px solid #000; border-bottom: 1px solid #000; position: relative; }
|
||||
.cell.blocked { background: #000; }
|
||||
.cell.hl-word { background: #c8d8f0; }
|
||||
.cell.hl-active { background: #3a6fd8; }
|
||||
.cell.hl-active input, .cell.hl-active .cell-number { color: #fff; }
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
background: #fff;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.cell input { width: 100%; height: 100%; border: none; background: transparent; font-family: 'Courier New', monospace; font-size: 12px; font-weight: bold; text-align: center; text-transform: uppercase; outline: none; padding-top: 4px; caret-color: transparent; }
|
||||
.container {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.cell-number { position: absolute; top: 1px; left: 2px; font-size: 7px; pointer-events: none; }
|
||||
h1 {
|
||||
text-align: center;
|
||||
color: #000;
|
||||
margin-bottom: 20px;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.clues { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; }
|
||||
.clues-section h3 { font-size: 11px; border-bottom: 1px solid #000; margin-bottom: 4px; }
|
||||
.clue { display: flex; gap: 4px; font-size: 11px; line-height: 1.6; cursor: pointer; }
|
||||
.clue.active { background: #c8d8f0; }
|
||||
.clue-num { min-width: 18px; flex-shrink: 0; }
|
||||
.grid-wrapper {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.crossword-grid {
|
||||
display: inline-grid;
|
||||
gap: 0;
|
||||
border: 2px solid #000;
|
||||
}
|
||||
|
||||
.cell {
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border: 1px solid #000;
|
||||
background: white;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
text-transform: uppercase;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.cell.blocked {
|
||||
background: #000;
|
||||
}
|
||||
|
||||
.cell input {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none;
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
text-transform: uppercase;
|
||||
background: transparent;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.cell-number {
|
||||
position: absolute;
|
||||
top: 1px;
|
||||
left: 2px;
|
||||
font-size: 8px;
|
||||
font-weight: normal;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.clues {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 30px;
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
.clues-section h3 {
|
||||
font-size: 18px;
|
||||
margin-bottom: 10px;
|
||||
border-bottom: 2px solid #000;
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
.clue {
|
||||
padding: 5px 0;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Crossword Puzzle - 21×21</h1>
|
||||
|
||||
<b>CROSSWORD</b>
|
||||
|
||||
<div style="margin:6px 0">
|
||||
<button class="dir-btn active" id="btnAcross" onclick="setDirection('across')">ACROSS</button>
|
||||
<button class="dir-btn" id="btnDown" onclick="setDirection('down')">DOWN</button>
|
||||
</div>
|
||||
|
||||
<div class="layout">
|
||||
<div>
|
||||
<div class="grid-wrapper">
|
||||
<div class="crossword-grid" id="grid"></div>
|
||||
</div>
|
||||
<div style="min-width:220px;flex:1">
|
||||
|
||||
<div class="clues">
|
||||
<div class="clues-section"><h3>Across</h3><div id="cluesAcross"></div></div>
|
||||
<div class="clues-section"><h3>Down</h3><div id="cluesDown"></div></div>
|
||||
<div class="clues-section">
|
||||
<h3>Across</h3>
|
||||
<div id="cluesAcross">
|
||||
</div>
|
||||
</div>
|
||||
<div class="clues-section">
|
||||
<h3>Down</h3>
|
||||
<div id="cluesDown">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const GRID_SIZE = 21;
|
||||
let direction = 'across';
|
||||
let activeRow = -1, activeCol = -1;
|
||||
|
||||
const cellData = Array.from({length: GRID_SIZE}, () => Array(GRID_SIZE).fill(null));
|
||||
const clueMap = { across: {}, down: {} };
|
||||
|
||||
const acrossClues = {1:"Moves like water",2:"Ancient writing surface",3:"Celestial body",4:"Swift journey",5:"Old musical key",6:"Grain storage structure",7:"Feline sound",8:"Desert wanderer",9:"Poetic foot",10:"City in Tuscany",11:"Measured pace",12:"Spiral galaxy centre",13:"Feudal estate",14:"Nautical term",15:"Musical interval",16:"Volcanic output",17:"Cured hide",18:"Silent agreement",19:"River mouth deposit",20:"Geometric solid",21:"Norse figure"};
|
||||
const downClues = {1:"Flowing script",2:"Tidal zone",3:"Mountain ridge",4:"Distant signal",5:"Ancient measure",6:"Harbour light",7:"Frozen mass",8:"River bend",9:"Winged deity",10:"Cavern feature",11:"Woven fabric",12:"Sacred text",13:"Coastal feature",14:"Solar flare",15:"Deep valley",16:"Stone formation",17:"Ocean current",18:"Wind direction",19:"Compass point",20:"Tide creature",21:"Storm surge"};
|
||||
|
||||
function isBlocked(r, c) { return (r + c) % 7 === 0 && r % 3 === 0; }
|
||||
|
||||
function buildGrid() {
|
||||
function createGrid() {
|
||||
const grid = document.getElementById('grid');
|
||||
let n = 1;
|
||||
grid.style.gridTemplateColumns = `repeat(${GRID_SIZE}, 30px)`;
|
||||
|
||||
let clueNumber = 1;
|
||||
|
||||
for (let r = 0; r < GRID_SIZE; r++) {
|
||||
for (let c = 0; c < GRID_SIZE; c++) {
|
||||
const cell = document.createElement('div');
|
||||
cell.className = 'cell';
|
||||
if (isBlocked(r, c)) {
|
||||
|
||||
const isBlocked = (r + c) % 7 === 0 && r % 3 === 0;
|
||||
|
||||
if (isBlocked) {
|
||||
cell.classList.add('blocked');
|
||||
cellData[r][c] = { blocked: true, el: cell };
|
||||
} else {
|
||||
const sa = (c === 0 || isBlocked(r, c-1)) && (c < GRID_SIZE-1 && !isBlocked(r, c+1));
|
||||
const sd = (r === 0 || isBlocked(r-1, c)) && (r < GRID_SIZE-1 && !isBlocked(r+1, c));
|
||||
if (sa || sd) {
|
||||
const ns = document.createElement('span');
|
||||
ns.className = 'cell-number'; ns.textContent = n;
|
||||
if (sa) clueMap.across[n] = {r, c};
|
||||
if (sd) clueMap.down[n] = {r, c};
|
||||
cell.appendChild(ns); n++;
|
||||
const needsNumber = (c === 0 || (c > 0 && isBlackSquare(r, c-1))) ||
|
||||
(r === 0 || (r > 0 && isBlackSquare(r-1, c)));
|
||||
|
||||
if (needsNumber && (c < GRID_SIZE-1 || r < GRID_SIZE-1)) {
|
||||
const num = document.createElement('span');
|
||||
num.className = 'cell-number';
|
||||
num.textContent = clueNumber++;
|
||||
cell.appendChild(num);
|
||||
}
|
||||
|
||||
const input = document.createElement('input');
|
||||
input.type = 'text'; input.maxLength = 1;
|
||||
input.setAttribute('autocomplete','off'); input.setAttribute('autocorrect','off'); input.setAttribute('spellcheck','false');
|
||||
input.addEventListener('focus', () => onFocus(r, c));
|
||||
input.addEventListener('click', () => onClick(r, c));
|
||||
input.addEventListener('keydown', e => onKey(e, r, c));
|
||||
input.addEventListener('input', e => onInput(e, r, c));
|
||||
input.maxLength = 1;
|
||||
cell.appendChild(input);
|
||||
cellData[r][c] = { blocked: false, el: cell, input };
|
||||
}
|
||||
|
||||
grid.appendChild(cell);
|
||||
}
|
||||
}
|
||||
buildClues();
|
||||
}
|
||||
|
||||
function buildClues() {
|
||||
const ac = document.getElementById('cluesAcross');
|
||||
const dn = document.getElementById('cluesDown');
|
||||
Object.keys(clueMap.across).map(Number).sort((a,b)=>a-b).forEach(n => {
|
||||
const d = document.createElement('div');
|
||||
d.className = 'clue'; d.id = `clue-across-${n}`;
|
||||
d.innerHTML = `<span class="clue-num">${n}.</span><span>${acrossClues[n]||'Clue '+n}</span>`;
|
||||
d.addEventListener('click', () => jumpToClue('across', n)); ac.appendChild(d);
|
||||
});
|
||||
Object.keys(clueMap.down).map(Number).sort((a,b)=>a-b).forEach(n => {
|
||||
const d = document.createElement('div');
|
||||
d.className = 'clue'; d.id = `clue-down-${n}`;
|
||||
d.innerHTML = `<span class="clue-num">${n}.</span><span>${downClues[n]||'Clue '+n}</span>`;
|
||||
d.addEventListener('click', () => jumpToClue('down', n)); dn.appendChild(d);
|
||||
});
|
||||
function isBlackSquare(r, c) {
|
||||
return (r + c) % 7 === 0 && r % 3 === 0;
|
||||
}
|
||||
|
||||
function getWord(r, c, dir) {
|
||||
const cells = [];
|
||||
if (dir === 'across') {
|
||||
let sc = c; while (sc > 0 && !isBlocked(r, sc-1)) sc--;
|
||||
while (sc < GRID_SIZE && !isBlocked(r, sc)) { cells.push([r, sc]); sc++; }
|
||||
} else {
|
||||
let sr = r; while (sr > 0 && !isBlocked(sr-1, c)) sr--;
|
||||
while (sr < GRID_SIZE && !isBlocked(sr, c)) { cells.push([sr, c]); sr++; }
|
||||
}
|
||||
return cells;
|
||||
}
|
||||
|
||||
function applyHL(wc, ar, ac2) {
|
||||
for (let r = 0; r < GRID_SIZE; r++)
|
||||
for (let c = 0; c < GRID_SIZE; c++) {
|
||||
const d = cellData[r][c];
|
||||
if (d && !d.blocked) d.el.classList.remove('hl-word','hl-active');
|
||||
}
|
||||
wc.forEach(([r,c]) => cellData[r][c].el.classList.add('hl-word'));
|
||||
if (cellData[ar]?.[ac2] && !cellData[ar][ac2].blocked) cellData[ar][ac2].el.classList.add('hl-active');
|
||||
}
|
||||
|
||||
function onFocus(r, c) {
|
||||
activeRow = r; activeCol = c;
|
||||
applyHL(getWord(r, c, direction), r, c);
|
||||
updateClueHL(r, c);
|
||||
}
|
||||
|
||||
function onClick(r, c) {
|
||||
if (activeRow === r && activeCol === c) {
|
||||
direction = direction === 'across' ? 'down' : 'across';
|
||||
document.getElementById('btnAcross').classList.toggle('active', direction==='across');
|
||||
document.getElementById('btnDown').classList.toggle('active', direction==='down');
|
||||
applyHL(getWord(r, c, direction), r, c);
|
||||
updateClueHL(r, c);
|
||||
}
|
||||
activeRow = r; activeCol = c;
|
||||
}
|
||||
|
||||
function onKey(e, r, c) {
|
||||
if (e.key==='ArrowRight') { e.preventDefault(); move(r,c,0,1); }
|
||||
else if (e.key==='ArrowLeft') { e.preventDefault(); move(r,c,0,-1); }
|
||||
else if (e.key==='ArrowDown') { e.preventDefault(); move(r,c,1,0); }
|
||||
else if (e.key==='ArrowUp') { e.preventDefault(); move(r,c,-1,0); }
|
||||
else if (e.key==='Tab') { e.preventDefault(); advWord(e.shiftKey?-1:1); }
|
||||
else if (e.key==='Backspace' && cellData[r][c].input.value==='') { e.preventDefault(); stepBack(r, c); }
|
||||
}
|
||||
|
||||
function onInput(e, r, c) {
|
||||
const d = cellData[r][c];
|
||||
if (d.input.value.length > 0) {
|
||||
d.input.value = d.input.value.slice(-1).toUpperCase();
|
||||
const wc = getWord(r, c, direction);
|
||||
const idx = wc.findIndex(([wr,wc2])=>wr===r&&wc2===c);
|
||||
if (idx !== -1 && idx < wc.length-1) cellData[wc[idx+1][0]][wc[idx+1][1]].input.focus();
|
||||
}
|
||||
}
|
||||
|
||||
function move(r, c, dr, dc) {
|
||||
const nr=r+dr, nc=c+dc;
|
||||
if (nr>=0&&nr<GRID_SIZE&&nc>=0&&nc<GRID_SIZE) { const d=cellData[nr][nc]; if (d&&!d.blocked) d.input.focus(); }
|
||||
}
|
||||
|
||||
function stepBack(r, c) {
|
||||
const wc=getWord(r,c,direction), idx=wc.findIndex(([wr,wc2])=>wr===r&&wc2===c);
|
||||
if (idx>0) { cellData[wc[idx-1][0]][wc[idx-1][1]].input.value=''; cellData[wc[idx-1][0]][wc[idx-1][1]].input.focus(); }
|
||||
}
|
||||
|
||||
function advWord(delta) {
|
||||
const map=direction==='across'?clueMap.across:clueMap.down;
|
||||
const keys=Object.keys(map).map(Number).sort((a,b)=>a-b);
|
||||
const wc=getWord(activeRow,activeCol,direction), [sr,sc]=wc[0];
|
||||
const cur=keys.find(n=>map[n].r===sr&&map[n].c===sc);
|
||||
jumpToClue(direction, keys[((keys.indexOf(cur)+delta)+keys.length)%keys.length]);
|
||||
}
|
||||
|
||||
function jumpToClue(dir, num) {
|
||||
direction=dir;
|
||||
document.getElementById('btnAcross').classList.toggle('active', direction==='across');
|
||||
document.getElementById('btnDown').classList.toggle('active', direction==='down');
|
||||
const map=dir==='across'?clueMap.across:clueMap.down;
|
||||
if (map[num]) cellData[map[num].r][map[num].c].input.focus();
|
||||
}
|
||||
|
||||
function updateClueHL(r, c) {
|
||||
document.querySelectorAll('.clue').forEach(el=>el.classList.remove('active'));
|
||||
const wc=getWord(r,c,direction); if (!wc.length) return;
|
||||
const [sr,sc]=wc[0], map=direction==='across'?clueMap.across:clueMap.down;
|
||||
for (const [num,pos] of Object.entries(map)) {
|
||||
if (pos.r===sr&&pos.c===sc) {
|
||||
const el=document.getElementById(`clue-${direction}-${num}`);
|
||||
if (el) { el.classList.add('active'); el.scrollIntoView({block:'nearest',behavior:'smooth'}); }
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setDirection(dir) {
|
||||
direction=dir;
|
||||
document.getElementById('btnAcross').classList.toggle('active',dir==='across');
|
||||
document.getElementById('btnDown').classList.toggle('active',dir==='down');
|
||||
if (activeRow>=0) { applyHL(getWord(activeRow,activeCol,direction),activeRow,activeCol); updateClueHL(activeRow,activeCol); }
|
||||
}
|
||||
|
||||
buildGrid();
|
||||
createGrid();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -11,6 +11,7 @@
|
||||
<h1>Flashcards Generator</h1>
|
||||
</header>
|
||||
<div class="main-wrapper">
|
||||
<div id="startScreen">
|
||||
<div class="section-title" id="title">
|
||||
<div class="content">
|
||||
<label for="inputText" class="inputText">Sende deine Wortliste an ChatGPT mit folgender Anweisung:</label>
|
||||
@@ -38,33 +39,38 @@
|
||||
<div class="button-wrapper">
|
||||
<button id="kartenErstellen">Karten erstellen</button>
|
||||
</div>
|
||||
<div id="modusAuswahlSeite" style="display:none">
|
||||
</div>
|
||||
|
||||
<div id="modusAuswahlSeite" style="display:none;">
|
||||
<h2>Wählt einen Modus:</h2>
|
||||
<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="statistik">📊 Statistik</button>
|
||||
</div>
|
||||
|
||||
<div id="pdfPages" class="modus-view">
|
||||
<div id="pdfPages">
|
||||
<div id="kartenContainer"></div>
|
||||
<div class="button-wrapper">
|
||||
<button id="druckenBtn" style="display:none;">Drucken</button>
|
||||
</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>
|
||||
<button class="level-btn" data-level="leicht">🟢 Leicht</button>
|
||||
<button class="level-btn" data-level="mittel">🟡 Mittel</button>
|
||||
<button class="level-btn" data-level="schwer">🔴 Schwer</button>
|
||||
</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="trainingSchwer" class="training-view"></div>
|
||||
|
||||
<div class="button-wrapper">
|
||||
<button id="checkBtn" style="display:none;" onclick="pruefeRunde()">Überprüfen</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="trainingContainer" style="display:none; text-align:center; margin-top:30px;"></div>
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
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', () => {
|
||||
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) {
|
||||
const wortBlocks = inputText.trim().split("\n\n");
|
||||
const wortListe = [];
|
||||
@@ -23,6 +34,7 @@ function parseWordText(inputText) {
|
||||
}
|
||||
|
||||
const wortObj = {
|
||||
id: crypto.randomUUID(),
|
||||
englisch: lines[0],
|
||||
ipa: lines[1],
|
||||
beispielEN: lines[2],
|
||||
@@ -36,6 +48,7 @@ function parseWordText(inputText) {
|
||||
return wortListe;
|
||||
}
|
||||
|
||||
// Gibt beide Seiten als Objekt zurück.
|
||||
function createPagePair() {
|
||||
const frontPage = document.createElement("div");
|
||||
frontPage.className = "page page-front";
|
||||
@@ -47,9 +60,6 @@ function createPagePair() {
|
||||
}
|
||||
|
||||
const button = document.getElementById("kartenErstellen");
|
||||
const onlineContainer = document.getElementById("kartenContainer");
|
||||
const frontPage = document.querySelector(".page_front");
|
||||
const backPage = document.querySelector(".page_back");
|
||||
|
||||
button.addEventListener("click", () => {
|
||||
const inputText = document.getElementById("inputText").value;
|
||||
@@ -62,38 +72,26 @@ button.addEventListener("click", () => {
|
||||
|
||||
alert("Karten erfolgreich erstellt!");
|
||||
|
||||
showView("modusAuswahlSeite");
|
||||
|
||||
document.getElementById("title").style.display = "none";
|
||||
button.style.display = "none";
|
||||
|
||||
document.getElementById("startScreen").style.display = "none";
|
||||
document.getElementById("modusAuswahlSeite").style.display = "block";
|
||||
});
|
||||
|
||||
document.querySelectorAll(".modus-btn").forEach(button => {
|
||||
button.addEventListener("click", () => {
|
||||
const modus = button.dataset.modus;
|
||||
|
||||
if (modus === "druck") {
|
||||
createPDFPages(parsedArray);
|
||||
} else {
|
||||
console.log("Gewählter Modus:", modus);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Erstellt druckfertige PDF-Seiten mit jeweils 8 Karten pro Seite.
|
||||
function createPDFPages(wordArray) {
|
||||
|
||||
const kartenContainer = document.getElementById("kartenContainer");
|
||||
const druckenBtn = document.getElementById("druckenBtn");
|
||||
|
||||
kartenContainer.innerHTML = "";
|
||||
kartenContainer.style.display = "flex";
|
||||
kartenContainer.style.flexDirection = "column";
|
||||
|
||||
for (let i = 0; i < parsedArray.length; i += 8) {
|
||||
for (let i = 0; i < wordArray.length; i += 8) {
|
||||
|
||||
const { frontPage, backPage } = createPagePair();
|
||||
|
||||
parsedArray.slice(i, i + 8).forEach((karte) => {
|
||||
wordArray.slice(i, i + 8).forEach((karte) => {
|
||||
|
||||
const frontCard = document.createElement("div");
|
||||
frontCard.className = "card card-en";
|
||||
@@ -115,28 +113,31 @@ function createPDFPages(wordArray) {
|
||||
|
||||
kartenContainer.appendChild(frontPage);
|
||||
kartenContainer.appendChild(backPage);
|
||||
document.getElementById("druckenBtn").style.display = "block";
|
||||
}
|
||||
|
||||
druckenBtn.style.display = "block";
|
||||
|
||||
alert("PDF-Seiten wurden erstellt! Du kannst sie jetzt drucken.");
|
||||
}
|
||||
|
||||
|
||||
document.getElementById("druckenBtn").addEventListener("click", () => {
|
||||
window.print();
|
||||
});
|
||||
|
||||
const modusBtns = document.querySelectorAll('.modus-btn');
|
||||
const trainingLevels = document.getElementById('trainingLevels');
|
||||
|
||||
modusBtns.forEach(btn => {
|
||||
btn.addEventListener('click', () => {
|
||||
const modus = btn.dataset.modus;
|
||||
|
||||
if (modus === 'druck') {
|
||||
showView('pdfPages');
|
||||
showMode('pdfPages');
|
||||
createPDFPages(parsedArray);
|
||||
}
|
||||
|
||||
else if (modus === 'training_einfach') {
|
||||
showView('trainingLevels');
|
||||
showMode('onlineTraining');
|
||||
}
|
||||
|
||||
else if (modus === 'statistik') {
|
||||
@@ -147,20 +148,21 @@ modusBtns.forEach(btn => {
|
||||
|
||||
let trainingsZustand = {
|
||||
modus: "leicht",
|
||||
// für alle Level
|
||||
quelleKarten: [],
|
||||
basisKarten: [],
|
||||
aktiveKarten: [],
|
||||
gelernt: [],
|
||||
nichtGelernt: [],
|
||||
// für Mittel
|
||||
ziehKarten: [],
|
||||
rundeNummer: 0,
|
||||
richtung: "EN_DE",
|
||||
};
|
||||
|
||||
// Startet das Training im Modus "Leicht".
|
||||
function startLeichtTraining() {
|
||||
console.log("🔥 startLeichtTraining вызвана");
|
||||
|
||||
if (!parsedArray || parsedArray.length === 0) {
|
||||
alert("Нет карточек для тренировки");
|
||||
return;
|
||||
}
|
||||
|
||||
trainingsZustand.modus = "leicht";
|
||||
trainingsZustand.quelleKarten = [...parsedArray];
|
||||
trainingsZustand.aktiveKarten = [];
|
||||
trainingsZustand.gelernt = [];
|
||||
@@ -173,67 +175,10 @@ function startLeichtTraining() {
|
||||
trainingsZustand.aktiveKarten.push(karte);
|
||||
}
|
||||
}
|
||||
|
||||
zeigeNaechsteKarte();
|
||||
}
|
||||
|
||||
function zeigeNaechsteKarte() {
|
||||
if (
|
||||
trainingsZustand.aktiveKarten.length === 0 &&
|
||||
trainingsZustand.quelleKarten.length === 0
|
||||
) {
|
||||
alert(`Training beendet!
|
||||
Gelernt: ${trainingsZustand.gelernt.length}
|
||||
Nicht gelernt: ${trainingsZustand.nichtGelernt.length}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const index = Math.floor(
|
||||
Math.random() * trainingsZustand.aktiveKarten.length
|
||||
);
|
||||
|
||||
trainingsZustand.aktuelleKarte =
|
||||
trainingsZustand.aktiveKarten[index];
|
||||
|
||||
renderLeichtKarte(trainingsZustand.aktuelleKarte);
|
||||
}
|
||||
|
||||
function renderLeichtKarte(karte) {
|
||||
const container = document.getElementById("trainingLeicht");
|
||||
container.innerHTML = "";
|
||||
|
||||
const cardEl = document.createElement("div");
|
||||
cardEl.className = "training-card";
|
||||
cardEl.innerHTML = `
|
||||
<div class="training-card-inner">
|
||||
<div class="training-front">
|
||||
<h2>${karte.englisch}</h2>
|
||||
<div class="ipa">${karte.ipa}</div>
|
||||
<div class="example">${karte.beispielEN}</div>
|
||||
</div>
|
||||
<div class="training-back">
|
||||
<h2>${karte.deutsch}</h2>
|
||||
<div class="example">${karte.beispielDE}</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
cardEl.onclick = () => cardEl.classList.toggle("flip");
|
||||
|
||||
const actions = document.createElement("div");
|
||||
actions.className = "training-actions";
|
||||
actions.innerHTML = `
|
||||
<button id="knowBtn">✔️ Weiß ich</button>
|
||||
<button id="dontKnowBtn">❌ Weiß ich nicht</button>
|
||||
`;
|
||||
|
||||
actions.querySelector("#knowBtn").onclick = () => antworteAufKarte(true);
|
||||
actions.querySelector("#dontKnowBtn").onclick = () => antworteAufKarte(false);
|
||||
|
||||
container.appendChild(cardEl);
|
||||
container.appendChild(actions);
|
||||
}
|
||||
|
||||
// Verarbeitet die Antwort des Nutzers im leichten Modus.
|
||||
function antworteAufKarte(weißIch) {
|
||||
const karte = trainingsZustand.aktuelleKarte;
|
||||
|
||||
@@ -259,51 +204,305 @@ function antworteAufKarte(weißIch) {
|
||||
zeigeNaechsteKarte();
|
||||
}
|
||||
|
||||
function showView(id) {
|
||||
document.querySelectorAll(".modus-view").forEach(view => {
|
||||
view.style.display = "none";
|
||||
// Wählt zufällig eine aktive Karte aus
|
||||
function zeigeNaechsteKarte() {
|
||||
if (trainingsZustand.aktiveKarten.length === 0) {
|
||||
|
||||
if (trainingsZustand.quelleKarten.length === 0) {
|
||||
alert(`Training beendet!
|
||||
Gelernt: ${trainingsZustand.gelernt.length}
|
||||
Nicht gelernt: ${trainingsZustand.nichtGelernt.length}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const neueKarte = trainingsZustand.quelleKarten.shift();
|
||||
neueKarte.versuche = 0;
|
||||
trainingsZustand.aktiveKarten.push(neueKarte);
|
||||
}
|
||||
const index = Math.floor(
|
||||
Math.random() * trainingsZustand.aktiveKarten.length
|
||||
);
|
||||
|
||||
trainingsZustand.aktuelleKarte =
|
||||
trainingsZustand.aktiveKarten[index];
|
||||
|
||||
renderLeichtKarte(trainingsZustand.aktuelleKarte);
|
||||
}
|
||||
|
||||
// Rendert eine einzelne Karte im leichten Modus.
|
||||
function renderLeichtKarte(karte) {
|
||||
const container = document.getElementById("trainingLeicht");
|
||||
container.innerHTML = "";
|
||||
|
||||
const cardEl = document.createElement("div");
|
||||
cardEl.className = "training-card";
|
||||
cardEl.innerHTML = `
|
||||
<div class="training-card-inner">
|
||||
<div class="training-front">
|
||||
<h2>${karte.englisch}</h2>
|
||||
<div class="ipa">${karte.ipa}</div>
|
||||
<div class="example">${karte.beispielEN}</div>
|
||||
</div>
|
||||
<div class="training-back">
|
||||
<h2>${karte.deutsch}</h2>
|
||||
<div class="example">${karte.beispielDE}</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
cardEl.onclick = () => cardEl.classList.toggle("flip");
|
||||
|
||||
const actions = document.createElement("div");
|
||||
actions.className = "training-actions";
|
||||
actions.innerHTML = `
|
||||
<button id="knowBtn">Weiß ich</button>
|
||||
<button id="dontKnowBtn">Weiß ich nicht</button>
|
||||
`;
|
||||
|
||||
actions.querySelector("#knowBtn").onclick = () => antworteAufKarte(true);
|
||||
actions.querySelector("#dontKnowBtn").onclick = () => antworteAufKarte(false);
|
||||
|
||||
container.appendChild(cardEl);
|
||||
container.appendChild(actions);
|
||||
}
|
||||
|
||||
// Startet das Training im Modus "Mittel".
|
||||
function startMittelTraining() {
|
||||
trainingsZustand.modus = "mittel";
|
||||
trainingsZustand.basisKarten = parsedArray.map(karte => ({
|
||||
...karte,
|
||||
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.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);
|
||||
});
|
||||
|
||||
const active = document.getElementById(id);
|
||||
if (active) {
|
||||
active.style.display = "block";
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
|
||||
function showTrainingLevel(id) {
|
||||
document.querySelectorAll(".training-view").forEach(view => {
|
||||
view.style.display = "none";
|
||||
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);
|
||||
});
|
||||
|
||||
const active = document.getElementById(id);
|
||||
if (active) {
|
||||
active.style.display = "block";
|
||||
// dragover
|
||||
ziehKarte.addEventListener("dragover", e => {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
// drop
|
||||
ziehKarte.addEventListener("drop", e => {
|
||||
console.log("drop работает");
|
||||
|
||||
e.preventDefault();
|
||||
|
||||
const draggedIndex = Number(e.dataTransfer.getData("draggedIndex"));
|
||||
|
||||
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;
|
||||
|
||||
const container = document.querySelector(".spalte-rechts");
|
||||
const cards = container.children;
|
||||
|
||||
container.insertBefore(cards[index2], cards[index1]);
|
||||
}
|
||||
|
||||
// Blendet alle Trainingslevel-Ansichten aus
|
||||
function showMode(id) {
|
||||
|
||||
document.getElementById("pdfPages").style.display = "none";
|
||||
document.getElementById("onlineTraining").style.display = "none";
|
||||
|
||||
document.getElementById(id).style.display = "block";
|
||||
}
|
||||
|
||||
function showLevel(id) {
|
||||
document.getElementById("trainingLeicht").classList.add("hidden");
|
||||
document.getElementById("trainingMittel").classList.add("hidden");
|
||||
document.getElementById("trainingSchwer").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);
|
||||
|
||||
if (level === "leicht") {
|
||||
showTrainingLevel("trainingLeicht");
|
||||
showLevel("trainingLeicht");
|
||||
startLeichtTraining();
|
||||
|
||||
document.getElementById("checkBtn").style.display = "none";
|
||||
}
|
||||
|
||||
if (level === "mittel") {
|
||||
showTrainingLevel("trainingMittel");
|
||||
showLevel("trainingMittel");
|
||||
startMittelTraining();
|
||||
|
||||
document.getElementById("checkBtn").style.display = "block";
|
||||
}
|
||||
|
||||
if (level === "schwer") {
|
||||
showTrainingLevel("trainingSchwer");
|
||||
showLevel("trainingSchwer");
|
||||
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 {
|
||||
width: 300px;
|
||||
height: 180px;
|
||||
margin: 10px auto;
|
||||
perspective: 1000px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#trainingLeicht .training-card {
|
||||
height: 180px;
|
||||
}
|
||||
|
||||
#trainingMittel .training-card {
|
||||
height: 100px;
|
||||
font-size: 0.9rem;
|
||||
margin: 0;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.training-card-inner {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
@@ -356,11 +366,62 @@ h1 {
|
||||
margin-top: -28px;
|
||||
}
|
||||
|
||||
.modus-view {
|
||||
#pdfPages,
|
||||
#onlineTraining,
|
||||
#trainingMittel,
|
||||
#trainingSchwer {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.training-view {
|
||||
display: none;
|
||||
margin-top: 25px;
|
||||
#trainingMittel {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.spalte-links {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.spalte-rechts {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
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,370 +1,299 @@
|
||||
|
||||
|
||||
|
||||
// Die Namen der 7 Segmente (a bis g)
|
||||
const SEGMENT_NAMEN = ["a", "b", "c", "d", "e", "f", "g"];
|
||||
const SEG = { a:0, b:1, c:2, d:3, e:4, f:5, g:6 };
|
||||
const segNames = ["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.
|
||||
function erstelleMuster(listeVonSegmenten) {
|
||||
let muster = 0;
|
||||
for (const segmentBuchstabe of listeVonSegmenten) {
|
||||
// 1 << X bedeutet: Schiebe die 1 um X Stellen nach links
|
||||
// Das | (ODER) fügt das Bit hinzu.
|
||||
muster = muster | (1 << SEGMENT_INDEX[segmentBuchstabe]);
|
||||
}
|
||||
return muster;
|
||||
function maskFromSegments(list){
|
||||
let m = 0;
|
||||
for(const s of list) m |= (1 << SEG[s]);
|
||||
return m;
|
||||
}
|
||||
|
||||
// Hier speichern wir das Muster für jede Ziffer von 0 bis 9
|
||||
// bitmasking: Jede Ziffer ist eine Kombination von Segmenten die an sind
|
||||
const ZIFFERN_MUSTER = [
|
||||
erstelleMuster(["a","b","c","d","e","f"]), // 0
|
||||
erstelleMuster(["b","c"]), // 1
|
||||
erstelleMuster(["a","b","d","e","g"]), // 2
|
||||
erstelleMuster(["a","b","c","d","g"]), // 3
|
||||
erstelleMuster(["b","c","f","g"]), // 4
|
||||
erstelleMuster(["a","c","d","f","g"]), // 5
|
||||
erstelleMuster(["a","c","d","e","f","g"]), // 6
|
||||
erstelleMuster(["a","b","c"]), // 7
|
||||
erstelleMuster(["a","b","c","d","e","f","g"]), // 8
|
||||
erstelleMuster(["a","b","c","d","f","g"]) // 9
|
||||
|
||||
const DIGIT_MASK = [
|
||||
maskFromSegments(["a","b","c","d","e","f"]),
|
||||
maskFromSegments(["b","c"]),
|
||||
maskFromSegments(["a","b","d","e","g"]),
|
||||
maskFromSegments(["a","b","c","d","g"]),
|
||||
maskFromSegments(["b","c","f","g"]),
|
||||
maskFromSegments(["a","c","d","f","g"]),
|
||||
maskFromSegments(["a","c","d","e","f","g"]),
|
||||
maskFromSegments(["a","b","c"]),
|
||||
maskFromSegments(["a","b","c","d","e","f","g"]),
|
||||
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 MUSTER_ZU_ZAHL = new Map();
|
||||
ZIFFERN_MUSTER.forEach((muster, zahl) => {
|
||||
MUSTER_ZU_ZAHL.set(muster, zahl);
|
||||
});
|
||||
|
||||
const MASK_TO_DIGIT = new Map(DIGIT_MASK.map((m,d)=>[m,d]));
|
||||
|
||||
|
||||
function removableTargetsFromDigit(d){
|
||||
const start = DIGIT_MASK[d];
|
||||
const res = [];
|
||||
for(let t=0;t<=9;t++){
|
||||
const target = DIGIT_MASK[t];
|
||||
if((target & start) === target){
|
||||
|
||||
|
||||
// Zählt, wie viele Bits in einer Zahl auf 1 stehen.
|
||||
// (Also: Wie viele Streichhölzer sind an?)
|
||||
function zaehleStreichhoelzer(zahl) {
|
||||
let anzahl = 0;
|
||||
// Solange die Zahl nicht 0 ist
|
||||
while (zahl > 0) {
|
||||
// Ein kleiner Trick um das letzte Bit zu löschen und zu zählen
|
||||
zahl = zahl & (zahl - 1);
|
||||
anzahl++;
|
||||
const removed = popcount(start ^ target);
|
||||
res.push({to:t, removed});
|
||||
}
|
||||
return anzahl;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// Gibt eine zufällige Zahl zwischen min und max zurück
|
||||
function zufallsZahl(min, max) {
|
||||
function popcount(x){
|
||||
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;
|
||||
}
|
||||
function pick(arr){ return arr[randInt(0, arr.length-1)]; }
|
||||
|
||||
// Wählt ein zufälliges Element aus einer Liste
|
||||
function wähleZufällig(liste) {
|
||||
return liste[zufallsZahl(0, liste.length - 1)];
|
||||
}
|
||||
|
||||
// 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 level = 1;
|
||||
let targetRemove = 2;
|
||||
let current = null;
|
||||
let solution = null;
|
||||
let removedSoFar = 0;
|
||||
|
||||
|
||||
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", () => {
|
||||
aktuellesLevel++;
|
||||
starteNeuesLevel();
|
||||
level++;
|
||||
generateLevel();
|
||||
});
|
||||
|
||||
document.getElementById("btnReset").addEventListener("click", () => {
|
||||
// Level neu starten (aber gleiches Level)
|
||||
setzeSpielZurueck();
|
||||
zeichneGleichung();
|
||||
pruefeObWahr();
|
||||
|
||||
resetPlayState();
|
||||
renderEquation();
|
||||
updateTruthUI();
|
||||
});
|
||||
|
||||
|
||||
|
||||
function setzeSpielZurueck() {
|
||||
geloeschteStreichhoelzer.clear(); // Liste leeren
|
||||
anzahlGeloescht = 0;
|
||||
elGeloeschtGrid.innerHTML = ""; // Anzeige leeren
|
||||
updateZaehlerAnzeige();
|
||||
function segmentsFromMask(mask){
|
||||
const set = new Set();
|
||||
for(let i=0;i<7;i++){
|
||||
if(mask & (1<<i)) set.add(segNames[i]);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
function updateZaehlerAnzeige() {
|
||||
elZaehlerGeloescht.textContent = anzahlGeloescht;
|
||||
elStapelZaehler.textContent = anzahlGeloescht;
|
||||
}
|
||||
|
||||
// Berechnet, welche Zahl gerade angezeigt wird (basierend auf dem was gelöscht wurde)
|
||||
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]);
|
||||
function displayedMaskForDigit(digitValue, digitIndex){
|
||||
let mask = DIGIT_MASK[digitValue];
|
||||
for(const s of segNames){
|
||||
const key = digitIndex + "-" + s;
|
||||
if(removedSet.has(key)){
|
||||
mask &= ~(1 << SEG[s]);
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
// Prüft: Ist A + B = C ?
|
||||
function istGleichungWahr() {
|
||||
const a = berechneAngezeigteZahl(aktuelleGleichung.A, 0);
|
||||
const b = berechneAngezeigteZahl(aktuelleGleichung.B, 1);
|
||||
const c = berechneAngezeigteZahl(aktuelleGleichung.C, 2);
|
||||
function displayedDigitValue(digitValue, digitIndex){
|
||||
const mask = displayedMaskForDigit(digitValue, digitIndex);
|
||||
return MASK_TO_DIGIT.has(mask) ? MASK_TO_DIGIT.get(mask) : null;
|
||||
}
|
||||
|
||||
// Wenn irgendeine Zahl ungültig ist, ist die Gleichung falsch
|
||||
function equationIsTrue(){
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
function pruefeObWahr() {
|
||||
const istWahr = istGleichungWahr();
|
||||
|
||||
if (istWahr) {
|
||||
elWahrheitPunkt.classList.add("ok");
|
||||
elWahrheitText.textContent = "Gleichung ist WAHR";
|
||||
} else {
|
||||
elWahrheitPunkt.classList.remove("ok");
|
||||
elWahrheitText.textContent = "Gleichung ist FALSCH";
|
||||
}
|
||||
function updateTruthUI(){
|
||||
const ok = equationIsTrue();
|
||||
elTruthDot.classList.toggle("ok", ok);
|
||||
elTruthText.textContent = ok ? "Equation is TRUE" : "Equation is FALSE";
|
||||
}
|
||||
|
||||
|
||||
// Erstellt das HTML für EINE Ziffer
|
||||
function erstelleZifferHTML(zahlenWert, positionIndex, farbe) {
|
||||
const zifferContainer = document.createElement("div");
|
||||
zifferContainer.className = "digit";
|
||||
|
||||
// Welche Segmente hat die Zahl ursprünglich?
|
||||
const maske = ZIFFERN_MUSTER[zahlenWert];
|
||||
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const segName = SEGMENT_NAMEN[i];
|
||||
|
||||
// Prüfen: Hat die Zahl dieses Segment? (Bit Test)
|
||||
const hatSegment = (maske & (1 << i)) !== 0;
|
||||
|
||||
if (hatSegment) {
|
||||
const segElement = document.createElement("div");
|
||||
segElement.className = "seg " + segName;
|
||||
segElement.style.background = farbe;
|
||||
|
||||
// Eindeutige ID für dieses Segment (z.B. "0-a")
|
||||
const id = positionIndex + "-" + segName;
|
||||
|
||||
// Wenn schon gelöscht, Klasse hinzufügen
|
||||
if (geloeschteStreichhoelzer.has(id)) {
|
||||
segElement.classList.add("removed");
|
||||
function resetPlayState(){
|
||||
removedSet.clear();
|
||||
removedSoFar = 0;
|
||||
elRemovedGrid.innerHTML = "";
|
||||
syncRemovedCounts();
|
||||
}
|
||||
|
||||
// Klick Event (Hier passiert die Action!)
|
||||
segElement.addEventListener("click", () => {
|
||||
// Abbruch wenn schon weg oder Limit erreicht
|
||||
if (geloeschteStreichhoelzer.has(id)) return;
|
||||
if (anzahlGeloescht >= zielAnzahlLoeschen) return;
|
||||
function syncRemovedCounts(){
|
||||
elRemovedCount.textContent = String(removedSoFar);
|
||||
elPileCount.textContent = String(removedSoFar);
|
||||
}
|
||||
|
||||
function renderDigit(digitValue, digitIndex, color){
|
||||
const digit = document.createElement("div");
|
||||
digit.className = "digit";
|
||||
|
||||
const baseMask = DIGIT_MASK[digitValue];
|
||||
const baseSegs = segmentsFromMask(baseMask);
|
||||
|
||||
for(const s of segNames){
|
||||
if(!baseSegs.has(s)) continue;
|
||||
|
||||
const seg = document.createElement("div");
|
||||
seg.className = "seg " + s;
|
||||
seg.style.background = color;
|
||||
|
||||
const key = digitIndex + "-" + s;
|
||||
if(removedSet.has(key)) seg.classList.add("removed");
|
||||
|
||||
seg.addEventListener("click", () => {
|
||||
if(removedSet.has(key)) return;
|
||||
if(removedSoFar >= targetRemove) return;
|
||||
|
||||
removedSet.add(key);
|
||||
removedSoFar++;
|
||||
|
||||
|
||||
seg.classList.add("removed");
|
||||
|
||||
// Löschen durchführen
|
||||
geloeschteStreichhoelzer.add(id);
|
||||
anzahlGeloescht++;
|
||||
segElement.classList.add("removed");
|
||||
|
||||
// Kleines Streichholz in den Mülleimer animieren
|
||||
const clone = document.createElement("div");
|
||||
clone.className = "removedSeg";
|
||||
clone.style.background = farbe;
|
||||
elGeloeschtGrid.appendChild(clone);
|
||||
clone.style.background = color;
|
||||
elRemovedGrid.appendChild(clone);
|
||||
|
||||
updateZaehlerAnzeige();
|
||||
pruefeObWahr();
|
||||
syncRemovedCounts();
|
||||
updateTruthUI();
|
||||
|
||||
// Gewinn Prüfung
|
||||
if (anzahlGeloescht === zielAnzahlLoeschen) {
|
||||
if (istGleichungWahr()) {
|
||||
elHinweis.innerHTML = "<b>Gelöst!</b> Super gemacht. Klicke auf <b>Neu level</b>.";
|
||||
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 {
|
||||
elHinweis.innerHTML = "<b>Nicht gelöst.</b> Alle Züge verbraucht, aber Gleichung falsch. <b>Reset</b>?";
|
||||
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() {
|
||||
elGleichung.innerHTML = ""; // Alles löschen
|
||||
function renderEquation(){
|
||||
elEq.innerHTML = "";
|
||||
|
||||
const farben = [
|
||||
"linear-gradient(180deg,#ff6b6b,#d64545)", // Rot für A
|
||||
"linear-gradient(180deg,#6bcBff,#3a7bd5)", // Blau für B
|
||||
"linear-gradient(180deg,#6bffb3,#1fae63)" // Grün für C
|
||||
const colors = [
|
||||
"linear-gradient(180deg,#ff6b6b,#d64545)",
|
||||
"linear-gradient(180deg,#6bcBff,#3a7bd5)",
|
||||
"linear-gradient(180deg,#6bffb3,#1fae63)"
|
||||
];
|
||||
|
||||
// Gruppe A bauen
|
||||
const g1 = document.createElement("div");
|
||||
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");
|
||||
plus.className = "symbol";
|
||||
plus.textContent = "+";
|
||||
|
||||
// Gruppe B bauen
|
||||
const g2 = document.createElement("div");
|
||||
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");
|
||||
eq.className = "symbol";
|
||||
eq.textContent = "=";
|
||||
|
||||
// Gruppe C bauen
|
||||
const g3 = document.createElement("div");
|
||||
g3.className = "group";
|
||||
g3.appendChild(erstelleZifferHTML(aktuelleGleichung.C, 2, farben[2]));
|
||||
g3.appendChild(renderDigit(current.C, 2, colors[2]));
|
||||
|
||||
// Alles zusammenfügen
|
||||
elGleichung.appendChild(g1);
|
||||
elGleichung.appendChild(plus);
|
||||
elGleichung.appendChild(g2);
|
||||
elGleichung.appendChild(eq);
|
||||
elGleichung.appendChild(g3);
|
||||
elEq.appendChild(g1);
|
||||
elEq.appendChild(plus);
|
||||
elEq.appendChild(g2);
|
||||
elEq.appendChild(eq);
|
||||
elEq.appendChild(g3);
|
||||
|
||||
pruefeObWahr();
|
||||
updateTruthUI();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 7. LEVEL GENERATOR (Das Gehirn)
|
||||
// Hier wird ein Level gebaut, das garantiert lösbar ist.
|
||||
function generateLevel(){
|
||||
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;
|
||||
|
||||
// Endlosschleife, bis wir ein passendes Level finden
|
||||
let tries = 0;
|
||||
while(true){
|
||||
versuche++;
|
||||
// Sicherheitsnetz: Wenn es zu lange dauert, Ziel senken
|
||||
if (versuche > 5000) {
|
||||
zielAnzahlLoeschen = Math.max(2, zielAnzahlLoeschen - 1);
|
||||
versuche = 0;
|
||||
tries++;
|
||||
if(tries > 5000){
|
||||
targetRemove = Math.max(2, targetRemove - 1);
|
||||
tries = 0;
|
||||
}
|
||||
|
||||
// 1. Wir denken uns eine KORREKTE Lösung aus (z.B. 3 + 5 = 8)
|
||||
const lsgA = zufallsZahl(0, 9);
|
||||
const lsgB = zufallsZahl(0, 9);
|
||||
const lsgC = lsgA + lsgB;
|
||||
const As = randInt(0, 9);
|
||||
const Bs = randInt(0, 9);
|
||||
const Cs = As + Bs;
|
||||
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);
|
||||
const Achoices = superDigits(As);
|
||||
const Bchoices = superDigits(Bs);
|
||||
const Cchoices = superDigits(Cs);
|
||||
|
||||
// Eine zufällige Auswahl treffen
|
||||
const startA = wähleZufällig(moeglicheA);
|
||||
const startB = wähleZufällig(moeglicheB);
|
||||
const startC = wähleZufällig(moeglicheC);
|
||||
const Ashow = pick(Achoices);
|
||||
const Bshow = pick(Bchoices);
|
||||
const Cshow = pick(Cchoices);
|
||||
|
||||
// 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 need =
|
||||
popcount(DIGIT_MASK[Ashow] ^ DIGIT_MASK[As]) +
|
||||
popcount(DIGIT_MASK[Bshow] ^ DIGIT_MASK[Bs]) +
|
||||
popcount(DIGIT_MASK[Cshow] ^ DIGIT_MASK[Cs]);
|
||||
|
||||
const gesamtWeg = diffA + diffB + diffC;
|
||||
if(need !== targetRemove) continue;
|
||||
|
||||
// Passt das zu unserem Ziel?
|
||||
if (gesamtWeg !== zielAnzahlLoeschen) continue;
|
||||
|
||||
// 4. Wichtig: Die angezeigte Start Gleichung muss FALSCH sein.
|
||||
// Sonst gibt es ja nichts zu rätseln.
|
||||
if ((startA + startB) === startC) continue;
|
||||
const shownTrue = (Ashow + Bshow) === Cshow;
|
||||
if(shownTrue) continue;
|
||||
|
||||
// Gefunden! Speichern.
|
||||
aktuelleGleichung = { A: startA, B: startB, C: startC };
|
||||
break; // Schleife beenden
|
||||
solution = { A: As, B: Bs, C: Cs };
|
||||
current = { A: Ashow, B: Bshow, C: Cshow };
|
||||
break;
|
||||
}
|
||||
|
||||
// UI Updates
|
||||
elLevelAnzeige.textContent = aktuellesLevel;
|
||||
elZielAnzeige.textContent = zielAnzahlLoeschen;
|
||||
elZielText.textContent = zielAnzahlLoeschen;
|
||||
elLvl.textContent = String(level);
|
||||
elTarget.textContent = String(targetRemove);
|
||||
elGoalN.textContent = String(targetRemove);
|
||||
|
||||
elHinweis.innerHTML =
|
||||
`Level <b>${aktuellesLevel}</b>: Mache die Gleichung wahr, indem du <b>${zielAnzahlLoeschen}</b> Streichhölzer entfernst.`;
|
||||
elHint.innerHTML =
|
||||
`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!
|
||||
starteNeuesLevel();
|
||||
function superDigits(baseDigit){
|
||||
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