From 2f64bf86e1f3c7674ab52a0ab1bc77be5c19cbc0 Mon Sep 17 00:00:00 2001 From: Naz Date: Wed, 16 Sep 2026 10:09:22 +0000 Subject: [PATCH] =?UTF-8?q?v5:=20=D0=BA=D1=83=D0=B1=D0=B8=D0=BA=20=D0=B8?= =?UTF-8?q?=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB=D0=B8=D0=B7=D0=B8=D1=80?= =?UTF-8?q?=D1=83=D0=B5=D1=82=D1=81=D1=8F=20=D1=81=D1=80=D0=B0=D0=B7=D1=83?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D1=88=D0=B0=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 156 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index c3c4ff4..10c44a1 100644 --- a/index.html +++ b/index.html @@ -719,12 +719,165 @@ document.addEventListener('touchend', () => { isDragging = false; }); -initCube(); -setTimeout(() => scramble(), 500); - let moveHistory = []; let hintTimeout = null; +function initAndScramble() { + initCube(); + + const layers = ['U', 'D', 'L', 'R', 'F', 'B']; + const moves = 20; + + for (let i = 0; i < moves; i++) { + const layer = layers[Math.floor(Math.random() * layers.length)]; + const direction = Math.random() > 0.5 ? 1 : -1; + + applyQuickMove(layer, direction); + } + + moveHistory = []; +} + +function applyQuickMove(layer, direction) { + const affectedCubies = []; + + for (let x = 0; x < 3; x++) { + for (let y = 0; y < 3; y++) { + for (let z = 0; z < 3; z++) { + let include = false; + if (layer === 'U' && cube[x][y][z].y === 1) include = true; + if (layer === 'D' && cube[x][y][z].y === -1) include = true; + if (layer === 'L' && cube[x][y][z].x === -1) include = true; + if (layer === 'R' && cube[x][y][z].x === 1) include = true; + if (layer === 'F' && cube[x][y][z].z === 1) include = true; + if (layer === 'B' && cube[x][y][z].z === -1) include = true; + + if (include) { + affectedCubies.push(cube[x][y][z]); + } + } + } + } + + affectedCubies.forEach(cubie => { + let newX = cubie.x; + let newY = cubie.y; + let newZ = cubie.z; + + if (layer === 'U' || layer === 'D') { + const temp = newX; + if (direction > 0) { + newX = -newZ; + newZ = temp; + } else { + newX = newZ; + newZ = -temp; + } + } else if (layer === 'L' || layer === 'R') { + const temp = newY; + if (direction > 0) { + newY = -newZ; + newZ = temp; + } else { + newY = newZ; + newZ = -temp; + } + } else if (layer === 'F' || layer === 'B') { + const temp = newX; + if (direction > 0) { + newX = -newY; + newY = temp; + } else { + newX = newY; + newY = -temp; + } + } + + const tempColors = { ...cubie.colors }; + if (layer === 'U' || layer === 'D') { + if (direction > 0) { + cubie.colors.front = tempColors.right; + cubie.colors.right = tempColors.back; + cubie.colors.back = tempColors.left; + cubie.colors.left = tempColors.front; + } else { + cubie.colors.front = tempColors.left; + cubie.colors.left = tempColors.back; + cubie.colors.back = tempColors.right; + cubie.colors.right = tempColors.front; + } + } else if (layer === 'L' || layer === 'R') { + if (direction > 0) { + cubie.colors.front = tempColors.top; + cubie.colors.top = tempColors.back; + cubie.colors.back = tempColors.bottom; + cubie.colors.bottom = tempColors.front; + } else { + cubie.colors.front = tempColors.bottom; + cubie.colors.bottom = tempColors.back; + cubie.colors.back = tempColors.top; + cubie.colors.top = tempColors.front; + } + } else if (layer === 'F' || layer === 'B') { + if (direction > 0) { + cubie.colors.top = tempColors.left; + cubie.colors.left = tempColors.bottom; + cubie.colors.bottom = tempColors.right; + cubie.colors.right = tempColors.top; + } else { + cubie.colors.top = tempColors.right; + cubie.colors.right = tempColors.bottom; + cubie.colors.bottom = tempColors.left; + cubie.colors.left = tempColors.top; + } + } + + cubie.x = newX; + cubie.y = newY; + cubie.z = newZ; + + updateCubiePosition(cubie.element, cubie.x, cubie.y, cubie.z); + + const faceElements = cubie.element.querySelectorAll('.face'); + faceElements.forEach(face => { + const faceClass = Array.from(face.classList).find(c => c.startsWith('face-') && !c.startsWith('face-face')); + if (faceClass) { + const faceName = faceClass.replace('face-', ''); + const colorName = cubie.colors[faceName] || 'black'; + face.className = `face face-${faceName} face-${colorName}`; + if (faceName === 'front') face.style.transform = 'rotateY(0deg) translateZ(48px)'; + if (faceName === 'back') face.style.transform = 'rotateY(180deg) translateZ(48px)'; + if (faceName === 'right') face.style.transform = 'rotateY(90deg) translateZ(48px)'; + if (faceName === 'left') face.style.transform = 'rotateY(-90deg) translateZ(48px)'; + if (faceName === 'top') face.style.transform = 'rotateX(90deg) translateZ(48px)'; + if (faceName === 'bottom') face.style.transform = 'rotateX(-90deg) translateZ(48px)'; + } + }); + }); + + const newCube = []; + for (let x = 0; x < 3; x++) { + newCube[x] = []; + for (let y = 0; y < 3; y++) { + newCube[x][y] = []; + for (let z = 0; z < 3; z++) { + newCube[x][y][z] = cube[x][y][z]; + } + } + } + + for (let x = 0; x < 3; x++) { + for (let y = 0; y < 3; y++) { + for (let z = 0; z < 3; z++) { + const cubie = newCube[x][y][z]; + cube[cubie.x + 1][cubie.y + 1][cubie.z + 1] = cubie; + } + } + } +} + +initAndScramble(); + function showHint() { const moveNames = { 'U': { name: 'Верх (U)', axis: 'Y' },