diff --git a/MainPage/Abdelaziz/CrossWords.html b/MainPage/Abdelaziz/CrossWords.html index 7e03488..cc2e825 100644 --- a/MainPage/Abdelaziz/CrossWords.html +++ b/MainPage/Abdelaziz/CrossWords.html @@ -2,171 +2,231 @@ - - Crossword Puzzle + CROSSWORD -
-

Crossword Puzzle - 21×21

- -
-
-
+CROSSWORD + +
+ + +
+ +
+
+
+
+
-
-

Across

-
-
-
-
-

Down

-
-
-
+

Across

+

Down

+
- +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=0&&ncwr===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(); + \ No newline at end of file