Hasli4

Untitled

Aug 17th, 2026 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.98 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="ru">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  6. <title>Алгоритм сна</title>
  7. <style>
  8. /* =========================
  9. БАЗОВЫЕ СТИЛИ
  10. ========================= */
  11. * { box-sizing: border-box; }
  12. html, body { margin: 0; min-height: 100%; }
  13. body {
  14. background:
  15. radial-gradient(circle at 50% 0%, rgba(76, 70, 150, .26), transparent 34%),
  16. radial-gradient(circle at 20% 80%, rgba(38, 92, 130, .16), transparent 28%),
  17. #080b15;
  18. color: #e9ecff;
  19. font-family: "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  20. padding: 12px;
  21. }
  22. button {
  23. font: inherit;
  24. -webkit-tap-highlight-color: transparent;
  25. }
  26.  
  27. /* Основной контейнер намеренно компактный: всё поле всегда видно. */
  28. #game {
  29. width: min(720px, 100%);
  30. margin: 0 auto;
  31. background: linear-gradient(180deg, #121827, #0e1421);
  32. border: 1px solid rgba(157, 166, 220, .12);
  33. border-radius: 24px;
  34. padding: 14px;
  35. box-shadow: 0 20px 70px rgba(0,0,0,.45), inset 0 1px rgba(255,255,255,.03);
  36. }
  37.  
  38. header {
  39. display: flex;
  40. align-items: center;
  41. justify-content: space-between;
  42. gap: 10px;
  43. margin-bottom: 12px;
  44. }
  45. h1 {
  46. margin: 0;
  47. text-align: center;
  48. width: 100%;
  49. font-size: clamp(22px, 5vw, 30px);
  50. color: #cfd5ff;
  51. letter-spacing: 2px;
  52. text-shadow: 0 0 18px rgba(110, 110, 255, .45);
  53. }
  54. .restart-top {
  55. flex: 0 0 auto;
  56. border: 1px solid #444b69;
  57. background: #1a2133;
  58. color: #dfe4ff;
  59. border-radius: 12px;
  60. padding: 8px 10px;
  61. cursor: pointer;
  62. }
  63.  
  64. /* =========================
  65. ИГРОВАЯ СЦЕНА
  66. ========================= */
  67. .scene {
  68. display: grid;
  69. grid-template-columns: 145px minmax(0, 1fr);
  70. gap: 12px;
  71. align-items: stretch;
  72. }
  73.  
  74. .character-area {
  75. min-width: 0;
  76. min-height: 170px;
  77. border-radius: 18px;
  78. background: rgba(20, 24, 46, .68);
  79. border: 1px solid rgba(120, 130, 200, .14);
  80. display: flex;
  81. align-items: center;
  82. justify-content: center;
  83. padding: 10px;
  84. }
  85.  
  86. .bed {
  87. position: relative;
  88. width: 124px;
  89. height: 76px;
  90. border-radius: 15px 15px 10px 10px;
  91. background: linear-gradient(180deg, #69442e, #452919);
  92. box-shadow: 0 6px 0 #2f1b10, 0 12px 24px rgba(0,0,0,.3);
  93. }
  94. .bed::before {
  95. content: "";
  96. position: absolute;
  97. left: 6px;
  98. top: -15px;
  99. width: 48px;
  100. height: 22px;
  101. border-radius: 12px;
  102. background: #f1e7dc;
  103. transform: rotate(-3deg);
  104. box-shadow: 0 2px 5px rgba(0,0,0,.35);
  105. }
  106. .bed::after {
  107. content: "";
  108. position: absolute;
  109. left: 48px;
  110. top: -7px;
  111. width: 70px;
  112. height: 22px;
  113. border-radius: 9px;
  114. background: linear-gradient(180deg, #51479a, #342e6a);
  115. transform: rotate(2deg);
  116. box-shadow: 0 3px 8px rgba(0,0,0,.45);
  117. }
  118.  
  119. .character {
  120. position: absolute;
  121. left: 37px;
  122. top: -39px;
  123. font-size: 46px;
  124. z-index: 5;
  125. transform-origin: center;
  126. filter: drop-shadow(0 0 7px rgba(255, 210, 120, .5));
  127. }
  128. .character.frame1 { animation: sleep1 .45s ease-in-out; }
  129. .character.frame2 { animation: sleep2 .45s ease-in-out; }
  130. .character.frame3 { animation: sleep3 .45s ease-in-out; }
  131. @keyframes sleep1 { 50% { transform: translateY(-2px) rotate(-1deg); } }
  132. @keyframes sleep2 { 50% { transform: translateY(2px) rotate(1deg); } }
  133. @keyframes sleep3 { 50% { transform: translateY(-1px) rotate(0deg); } }
  134.  
  135. .play {
  136. min-width: 0;
  137. display: flex;
  138. flex-direction: column;
  139. gap: 10px;
  140. }
  141.  
  142. /* Зона сознания */
  143. .conscious {
  144. height: 110px;
  145. position: relative;
  146. /* Фигура может временно выходить за границы зоны сознания,
  147. поэтому не обрезаем её по краям. */
  148. overflow: visible;
  149. border: 2px dashed #454970;
  150. background:
  151. radial-gradient(circle at 50% 70%, rgba(78,73,160,.18), transparent 45%),
  152. rgba(28, 25, 69, .48);
  153. border-radius: 17px;
  154. display: flex;
  155. align-items: center;
  156. justify-content: center;
  157. }
  158. .conscious-label {
  159. position: absolute;
  160. top: 8px;
  161. left: 10px;
  162. color: #7f86b6;
  163. font-size: 10px;
  164. letter-spacing: .13em;
  165. text-transform: uppercase;
  166. pointer-events: none;
  167. }
  168. .conscious-tip {
  169. color: rgba(196, 201, 240, .45);
  170. text-align: center;
  171. font-size: 11px;
  172. line-height: 1.35;
  173. pointer-events: none;
  174. }
  175.  
  176. /* =========================
  177. ПОЛЕ ПОДСОЗНАНИЯ
  178. Главное исправление: НИКАКОГО scroll.
  179. Размер адаптивный, но всегда квадратный.
  180. ========================= */
  181. .board-title {
  182. display: flex;
  183. justify-content: space-between;
  184. align-items: center;
  185. gap: 8px;
  186. color: #c5cbe6;
  187. font-size: 12px;
  188. padding: 0 2px;
  189. }
  190.  
  191. .board-wrap {
  192. width: min(100%, 390px);
  193. aspect-ratio: 1 / 1;
  194. margin: 0 auto;
  195. padding: 5px;
  196. border-radius: 15px;
  197. background: rgba(33, 37, 67, .72);
  198. border: 1px solid rgba(123, 133, 191, .20);
  199. box-shadow: inset 0 0 25px rgba(0,0,0,.18);
  200. }
  201. #board {
  202. width: 100%;
  203. height: 100%;
  204. display: grid;
  205. grid-template-columns: repeat(8, minmax(0, 1fr));
  206. grid-template-rows: repeat(8, minmax(0, 1fr));
  207. gap: 3px;
  208. touch-action: none;
  209. }
  210. .cell {
  211. min-width: 0;
  212. min-height: 0;
  213. border-radius: 5px;
  214. background: rgba(11, 15, 28, .78);
  215. border: 1px solid rgba(104, 116, 170, .18);
  216. transition: background .12s, transform .12s;
  217. }
  218. .cell.ok { background: rgba(72, 205, 155, .26); border-color: rgba(110, 255, 198, .42); }
  219. .cell.bad { background: rgba(241, 82, 103, .25); border-color: rgba(255, 112, 130, .45); }
  220. .cell.filled {
  221. border-color: rgba(255,255,255,.26);
  222. box-shadow: inset 0 0 10px rgba(255,255,255,.10);
  223. }
  224. .cell.clearing { animation: rowFlash .38s ease forwards; }
  225. @keyframes rowFlash {
  226. 0% { opacity: 1; transform: scale(1); filter: brightness(1); }
  227. 45% { opacity: .95; transform: scale(.82); filter: brightness(2); }
  228. 100% { opacity: 0; transform: scale(.15); }
  229. }
  230.  
  231. /* Фигура мысли */
  232. .piece {
  233. --piece-cell: 32px;
  234. --piece-gap: 3px;
  235. position: fixed;
  236. display: grid;
  237. gap: var(--piece-gap);
  238. z-index: 20;
  239. cursor: grab;
  240. touch-action: none;
  241. user-select: none;
  242. filter: drop-shadow(0 6px 12px rgba(0,0,0,.55));
  243. }
  244. .piece.dragging {
  245. cursor: grabbing;
  246. filter: drop-shadow(0 12px 24px rgba(0,0,0,.75));
  247. }
  248. .piece-cell {
  249. border-radius: 7px;
  250. border: 1px solid rgba(255,255,255,.22);
  251. background: var(--color);
  252. box-shadow: inset 0 1px rgba(255,255,255,.12);
  253. min-width: 0;
  254. min-height: 0;
  255. }
  256. .piece-label {
  257. position: absolute;
  258. inset: 0;
  259. display: flex;
  260. align-items: center;
  261. justify-content: center;
  262. padding: 3px 6px;
  263. color: #fff;
  264. text-shadow: 0 1px 3px rgba(0,0,0,.7);
  265. font-weight: 700;
  266. font-size: clamp(8px, 1.7vw, 11px);
  267. line-height: 1.05;
  268. text-align: center;
  269. pointer-events: none;
  270. overflow: hidden;
  271. }
  272.  
  273. /* =========================
  274. НИЖНЯЯ ПАНЕЛЬ
  275. ========================= */
  276. .controls {
  277. display: grid;
  278. grid-template-columns: minmax(150px, 1fr) auto auto;
  279. gap: 8px;
  280. align-items: center;
  281. margin-top: 12px;
  282. }
  283. .stress-box {
  284. display: grid;
  285. grid-template-columns: auto minmax(80px, 1fr) auto;
  286. gap: 8px;
  287. align-items: center;
  288. min-width: 0;
  289. }
  290. .stress-label, .stress-value, .rows-counter {
  291. font-size: 12px;
  292. white-space: nowrap;
  293. }
  294. .stress-bar {
  295. height: 15px;
  296. border-radius: 999px;
  297. overflow: hidden;
  298. background: #171a2d;
  299. border: 1px solid #3b3f56;
  300. }
  301. #stressFill {
  302. width: 0%;
  303. height: 100%;
  304. background: linear-gradient(90deg, #22c55e, #eab308, #ef4444);
  305. border-radius: inherit;
  306. transition: width .25s ease;
  307. }
  308. .bonus {
  309. border: 1px solid #444b69;
  310. background: #1b2336;
  311. color: #e5e9ff;
  312. padding: 9px 11px;
  313. border-radius: 12px;
  314. cursor: pointer;
  315. white-space: nowrap;
  316. }
  317. .bonus:hover:not(:disabled) { background: #242e46; }
  318. .bonus:active:not(:disabled) { transform: scale(.97); }
  319. .bonus:disabled { opacity: .4; cursor: not-allowed; }
  320.  
  321. .info-line {
  322. display: flex;
  323. justify-content: center;
  324. gap: 12px;
  325. margin-top: 8px;
  326. color: #7f88aa;
  327. font-size: 11px;
  328. text-align: center;
  329. }
  330.  
  331.  
  332. /* Экран выбора сложности */
  333. .difficulty-overlay {
  334. position: fixed;
  335. inset: 0;
  336. z-index: 7000;
  337. display: flex;
  338. align-items: center;
  339. justify-content: center;
  340. padding: 18px;
  341. background: rgba(4, 6, 14, .80);
  342. backdrop-filter: blur(9px);
  343. }
  344. .difficulty-overlay.hidden { display: none; }
  345. .difficulty-card {
  346. width: min(560px, 100%);
  347. padding: 28px;
  348. border-radius: 24px;
  349. background:
  350. radial-gradient(circle at 50% 0%, rgba(104, 91, 196, .22), transparent 42%),
  351. linear-gradient(180deg, #1a2238, #0d1423);
  352. border: 1px solid rgba(164, 174, 230, .18);
  353. box-shadow: 0 28px 90px rgba(0,0,0,.55);
  354. text-align: center;
  355. }
  356. .difficulty-kicker {
  357. color: #8b91c6;
  358. font-size: 10px;
  359. letter-spacing: .2em;
  360. margin-bottom: 7px;
  361. }
  362. .difficulty-card h2 {
  363. margin: 0 0 8px;
  364. font-size: clamp(25px, 6vw, 34px);
  365. }
  366. .difficulty-card p {
  367. margin: 0 auto 20px;
  368. max-width: 440px;
  369. color: #9ca6c5;
  370. line-height: 1.45;
  371. font-size: 13px;
  372. }
  373. .difficulty-grid {
  374. display: grid;
  375. grid-template-columns: repeat(3, 1fr);
  376. gap: 10px;
  377. }
  378. .difficulty-btn {
  379. min-height: 112px;
  380. border-radius: 16px;
  381. border: 1px solid rgba(255,255,255,.10);
  382. background: rgba(255,255,255,.045);
  383. color: #eef1ff;
  384. cursor: pointer;
  385. padding: 14px 10px;
  386. display: flex;
  387. flex-direction: column;
  388. justify-content: center;
  389. gap: 8px;
  390. transition: transform .18s, background .18s, border-color .18s;
  391. }
  392. .difficulty-btn:hover {
  393. transform: translateY(-2px);
  394. background: rgba(255,255,255,.085);
  395. border-color: rgba(255,255,255,.20);
  396. }
  397. .difficulty-btn strong { font-size: 14px; }
  398. .difficulty-btn span { color: #9ca6c5; font-size: 11px; line-height: 1.25; }
  399. .difficulty-btn.easy { box-shadow: inset 0 -3px 0 rgba(74, 203, 151, .22); }
  400. .difficulty-btn.normal { box-shadow: inset 0 -3px 0 rgba(232, 183, 77, .22); }
  401. .difficulty-btn.hard { box-shadow: inset 0 -3px 0 rgba(236, 82, 104, .22); }
  402.  
  403. .combo-line {
  404. display: flex;
  405. justify-content: center;
  406. align-items: center;
  407. gap: 8px;
  408. margin-top: 5px;
  409. color: #8b95b4;
  410. font-size: 11px;
  411. }
  412. .combo-line strong { color: #dfe6ff; }
  413.  
  414. /* Окончание игры */
  415. .overlay {
  416. position: fixed;
  417. inset: 0;
  418. z-index: 5000;
  419. display: none;
  420. align-items: center;
  421. justify-content: center;
  422. padding: 18px;
  423. background: rgba(4,6,12,.72);
  424. backdrop-filter: blur(7px);
  425. }
  426. .overlay.show { display: flex; }
  427. .result {
  428. width: min(430px, 100%);
  429. border-radius: 21px;
  430. padding: 26px;
  431. background: linear-gradient(180deg, #1a2237, #0d1422);
  432. border: 1px solid rgba(160,170,220,.18);
  433. box-shadow: 0 24px 70px rgba(0,0,0,.45);
  434. text-align: center;
  435. }
  436. .result h2 { margin: 0 0 8px; font-size: 29px; }
  437. .result p { margin: 0 0 18px; color: #9ca6c5; line-height: 1.45; }
  438. .result button {
  439. border: 0;
  440. border-radius: 12px;
  441. background: #8178df;
  442. color: #fff;
  443. padding: 11px 18px;
  444. cursor: pointer;
  445. font-weight: 700;
  446. }
  447.  
  448. .toast {
  449. position: fixed;
  450. left: 50%;
  451. top: 12%;
  452. z-index: 6000;
  453. transform: translate(-50%, -10px);
  454. opacity: 0;
  455. pointer-events: none;
  456. padding: 9px 13px;
  457. border-radius: 12px;
  458. color: #eff2ff;
  459. background: rgba(13,18,32,.95);
  460. border: 1px solid rgba(255,255,255,.10);
  461. box-shadow: 0 12px 34px rgba(0,0,0,.35);
  462. transition: opacity .18s, transform .18s;
  463. text-align: center;
  464. white-space: nowrap;
  465. }
  466. .toast.show { opacity: 1; transform: translate(-50%, 0); }
  467.  
  468. /* Мобильная версия */
  469. @media (max-width: 560px) {
  470. body { padding: 7px; }
  471. #game { padding: 10px; border-radius: 19px; }
  472. .scene {
  473. grid-template-columns: 1fr;
  474. }
  475. .character-area {
  476. min-height: 110px;
  477. }
  478. .bed { transform: scale(.83); }
  479. .play { width: 100%; }
  480. .conscious { height: 86px; }
  481. .board-wrap { width: min(100%, 350px); }
  482. .controls {
  483. grid-template-columns: 1fr 1fr;
  484. }
  485. .stress-box {
  486. grid-column: 1 / -1;
  487. }
  488. .bonus { width: 100%; }
  489. .info-line { flex-wrap: wrap; gap: 5px 10px; }
  490. }
  491.  
  492. @media (max-width: 360px) {
  493. h1 { font-size: 20px; letter-spacing: 1px; }
  494. .board-wrap { width: min(100%, 310px); }
  495. .controls { gap: 6px; }
  496. .bonus { font-size: 11px; padding: 8px 6px; }
  497. .stress-label, .rows-counter { font-size: 10px; }
  498. }
  499. </style>
  500. </head>
  501. <body>
  502. <div id="game">
  503. <header>
  504. <h1>🌙 Алгоритм сна</h1>
  505. <button class="restart-top" id="restartTop">↻</button>
  506. </header>
  507.  
  508. <section class="scene">
  509. <div class="character-area">
  510. <div class="bed">
  511. <div class="character" id="character">😴</div>
  512. </div>
  513. </div>
  514.  
  515. <div class="play">
  516. <div class="conscious" id="conscious">
  517. <div class="conscious-label">СОЗНАНИЕ</div>
  518. <div class="conscious-tip" id="consciousTip">
  519. Перетащи мысль вниз.<br>
  520. ПКМ или долгое нажатие — повернуть.
  521. </div>
  522. </div>
  523.  
  524. <div class="board-title">
  525. <span>🧠 Подсознание</span>
  526. <span class="rows-counter" id="rowsCounter">Ряды: 0 / 5</span>
  527. </div>
  528.  
  529. <div class="board-wrap">
  530. <div id="board"></div>
  531. </div>
  532. </div>
  533. </section>
  534.  
  535. <section class="controls">
  536. <div class="stress-box">
  537. <span class="stress-label">Стресс</span>
  538. <div class="stress-bar"><div id="stressFill"></div></div>
  539. <span class="stress-value" id="stressValue">0%</span>
  540. </div>
  541.  
  542. <button class="bonus" id="sheepBtn">🐑 Овцы (2)</button>
  543. <button class="bonus" id="noiseBtn">🌫️ Шум (2)</button>
  544. </section>
  545.  
  546. <div class="info-line">
  547. <span id="difficultyInfo">Сложность: —</span>
  548. <span>Линия: −12%</span>
  549. <span>Победа: 5 линий</span>
  550. </div>
  551. <div class="combo-line">
  552. Комбо: <strong id="comboValue">0</strong> ·
  553. 🐑 и 🌫️ выдаются за успешные ходы и уменьшают стресс
  554. </div>
  555. </div>
  556.  
  557.  
  558. <div class="difficulty-overlay" id="difficultyOverlay">
  559. <div class="difficulty-card">
  560. <div class="difficulty-kicker">НОВАЯ НОЧЬ</div>
  561. <h2>Выбери сложность</h2>
  562. <p>Чем выше сложность, тем сильнее растёт стресс при ошибках.</p>
  563. <div class="difficulty-grid">
  564. <button class="difficulty-btn easy" data-difficulty="easy">
  565. <strong>🌙 Спокойно</strong>
  566. <span>Ошибка: +5% стресса</span>
  567. </button>
  568. <button class="difficulty-btn normal" data-difficulty="normal">
  569. <strong>😰 Тревожно</strong>
  570. <span>Ошибка: +9% стресса</span>
  571. </button>
  572. <button class="difficulty-btn hard" data-difficulty="hard">
  573. <strong>🔥 Бессонница</strong>
  574. <span>Ошибка: +15% стресса</span>
  575. </button>
  576. </div>
  577. </div>
  578. </div>
  579.  
  580. <div class="toast" id="toast"></div>
  581.  
  582. <div class="overlay" id="overlay">
  583. <div class="result">
  584. <h2 id="resultTitle">😴 Сон!</h2>
  585. <p id="resultText"></p>
  586. <button id="restartResult">Начать заново</button>
  587. </div>
  588. </div>
  589.  
  590. <script>
  591. (() => {
  592. "use strict";
  593.  
  594. // =========================
  595. // НАСТРОЙКИ ИГРЫ
  596. // =========================
  597. const COLS = 8;
  598. const ROWS = 8;
  599. const TARGET_ROWS = 5;
  600. const MAX_STRESS = 100;
  601. const CLEAR_STRESS = 12;
  602. const COMBO_REWARD_EVERY = 3;
  603.  
  604. const DIFFICULTIES = {
  605. easy: { name: "Спокойно", failStress: 5 },
  606. normal: { name: "Тревожно", failStress: 9 },
  607. hard: { name: "Бессонница", failStress: 15 }
  608. };
  609.  
  610. const THOUGHTS = [
  611. "не выключил утюг", "дедлайн завтра", "неловкая фраза 2014",
  612. "забыл ответить", "не закрыл дверь?", "завтра рано вставать",
  613. "что если опоздаю?", "не оплатил счёт", "надо позвонить",
  614. "что сказать на встрече?", "а вдруг всё забыл?", "проект не готов",
  615. "надо было иначе", "почему я это сказал?", "что обо мне думают?",
  616. "забытые продукты", "не выключил плиту", "а если не получится?",
  617. "надо лечь раньше", "что-то скрипит", "не ответил на сообщение",
  618. "что надеть завтра?", "пароль слишком простой", "где ключи?",
  619. "забытый файл", "срок уже близко", "а точно отправил?",
  620. "почему я это лайкнул?", "надо помыть посуду", "зарядить телефон"
  621. ];
  622.  
  623. const NORMAL_SHAPES = [
  624. [[0,0],[0,1],[1,0],[1,1]],
  625. [[0,0],[1,0],[2,0],[2,1]],
  626. [[0,1],[1,0],[1,1],[2,0]],
  627. [[0,0],[1,0],[2,0],[2,1]],
  628. [[0,0],[0,1],[0,2],[1,1]],
  629. [[0,0],[1,0],[1,1],[2,1]],
  630. [[0,0],[0,1],[1,1],[2,1]],
  631. [[0,0],[0,1],[0,2],[1,2],[2,2]],
  632. [[0,0],[1,0],[2,0],[1,1],[1,2]],
  633. [[0,0],[1,0],[1,1],[1,2],[2,2]],
  634. [[0,0],[0,1],[1,1],[2,1],[2,0]],
  635. [[0,0],[1,0],[2,0]],
  636. [[0,0],[0,1],[0,2]]
  637. ];
  638.  
  639. const SMALL_SHAPES = [
  640. [[0,0]],
  641. [[0,0],[1,0]],
  642. [[0,0],[0,1]],
  643. [[0,0],[1,0],[0,1]]
  644. ];
  645.  
  646. const COLORS = [
  647. "#e2556d", "#4c82d8", "#48a979", "#d39649",
  648. "#9565c9", "#d36b40", "#3b9ab5", "#a84f91"
  649. ];
  650.  
  651. // =========================
  652. // СОСТОЯНИЕ
  653. // =========================
  654. let board = [];
  655. let active = null;
  656. let stress = 0;
  657. let clearedRows = 0;
  658. let sheepUses = 0;
  659. let noiseUses = 0;
  660. let combo = 0;
  661. let gameEnded = true;
  662. let pieceId = 0;
  663. let animationTimer = null;
  664. let toastTimer = null;
  665. let difficulty = null;
  666. let drag = null;
  667.  
  668. const $ = id => document.getElementById(id);
  669. const boardEl = $("board");
  670. const consciousEl = $("conscious");
  671. const characterEl = $("character");
  672. const stressFillEl = $("stressFill");
  673. const stressValueEl = $("stressValue");
  674. const rowsCounterEl = $("rowsCounter");
  675. const consciousTipEl = $("consciousTip");
  676. const sheepBtn = $("sheepBtn");
  677. const noiseBtn = $("noiseBtn");
  678. const overlayEl = $("overlay");
  679. const resultTitleEl = $("resultTitle");
  680. const resultTextEl = $("resultText");
  681. const toastEl = $("toast");
  682. const difficultyOverlay = $("difficultyOverlay");
  683. const difficultyInfo = $("difficultyInfo");
  684. const comboValueEl = $("comboValue");
  685.  
  686. // =========================
  687. // УТИЛИТЫ
  688. // =========================
  689. function random(arr) {
  690. return arr[Math.floor(Math.random() * arr.length)];
  691. }
  692.  
  693. function rotateShape(cells) {
  694. const rotated = cells.map(([r, c]) => [c, -r]);
  695. const minR = Math.min(...rotated.map(([r]) => r));
  696. const minC = Math.min(...rotated.map(([, c]) => c));
  697. return rotated.map(([r, c]) => [r - minR, c - minC]);
  698. }
  699.  
  700. function bounds(cells) {
  701. return {
  702. rows: Math.max(...cells.map(([r]) => r)) + 1,
  703. cols: Math.max(...cells.map(([, c]) => c)) + 1
  704. };
  705. }
  706.  
  707. // =========================
  708. // ПОЛЕ
  709. // =========================
  710. function createEmptyBoard() {
  711. return Array.from({ length: ROWS }, () => Array(COLS).fill(null));
  712. }
  713.  
  714. function buildBoard() {
  715. boardEl.innerHTML = "";
  716. for (let r = 0; r < ROWS; r++) {
  717. for (let c = 0; c < COLS; c++) {
  718. const cell = document.createElement("div");
  719. cell.className = "cell";
  720. boardEl.appendChild(cell);
  721. }
  722. }
  723. renderBoard();
  724. }
  725.  
  726. function renderBoard() {
  727. const cells = boardEl.children;
  728. for (let r = 0; r < ROWS; r++) {
  729. for (let c = 0; c < COLS; c++) {
  730. const cell = cells[r * COLS + c];
  731. const value = board[r][c];
  732.  
  733. cell.classList.remove("filled", "ok", "bad", "clearing");
  734. cell.style.removeProperty("background");
  735.  
  736. if (value) {
  737. cell.classList.add("filled");
  738. cell.style.background =
  739. `linear-gradient(145deg, ${value.color}, rgba(255,255,255,.08))`;
  740. }
  741. }
  742. }
  743. }
  744.  
  745. function findFullRows() {
  746. const rows = [];
  747. for (let r = 0; r < ROWS; r++) {
  748. if (board[r].every(Boolean)) rows.push(r);
  749. }
  750. return rows;
  751. }
  752.  
  753. // Ключевой алгоритм очистки:
  754. // убираем полные строки, а ВСЕ неполные строки падают вниз.
  755. // Новые пустые строки появляются только сверху.
  756. function clearRows(rows) {
  757. const full = new Set(rows);
  758. const remaining = board.filter((_, index) => !full.has(index));
  759. const empty = Array.from({length: rows.length}, () => Array(COLS).fill(null));
  760. board = empty.concat(remaining);
  761. }
  762.  
  763. // =========================
  764. // СТРЕСС
  765. // =========================
  766. function setStress(value) {
  767. stress = Math.max(0, Math.min(MAX_STRESS, value));
  768. stressFillEl.style.width = `${stress}%`;
  769. stressValueEl.textContent = `${stress}%`;
  770.  
  771. if (stress < 30) {
  772. characterEl.textContent = "😴";
  773. consciousTipEl.innerHTML =
  774. "Мысли можно аккуратно уложить.<br>ПКМ / долгое нажатие — повернуть.";
  775. } else if (stress < 70) {
  776. characterEl.textContent = "😠";
  777. consciousTipEl.innerHTML =
  778. "Он ворочается…<br>Старайся не ошибаться.";
  779. } else {
  780. characterEl.textContent = "😡";
  781. consciousTipEl.innerHTML =
  782. "⚠️ Он уже почти проснулся!";
  783. }
  784.  
  785. if (stress >= MAX_STRESS) loseGame();
  786. }
  787.  
  788. function addStress(amount) {
  789. if (!gameEnded) setStress(stress + amount);
  790. }
  791.  
  792. function reduceStress(amount) {
  793. if (!gameEnded) setStress(stress - amount);
  794. }
  795.  
  796. function startCharacterAnimation() {
  797. clearInterval(animationTimer);
  798. let frame = 0;
  799. animationTimer = setInterval(() => {
  800. frame = (frame + 1) % 3 + 1;
  801. characterEl.classList.remove("frame1", "frame2", "frame3");
  802. void characterEl.offsetWidth;
  803. characterEl.classList.add(`frame${frame}`);
  804. }, 450);
  805. }
  806.  
  807. // =========================
  808. // БОНУСЫ И КОМБО
  809. // =========================
  810. function updateBonusUI() {
  811. sheepBtn.textContent = `🐑 Овцы (${sheepUses})`;
  812. noiseBtn.textContent = `🌫️ Шум (${noiseUses})`;
  813. sheepBtn.disabled = sheepUses <= 0 || gameEnded;
  814. noiseBtn.disabled = noiseUses <= 0 || gameEnded;
  815. comboValueEl.textContent = String(combo);
  816. }
  817.  
  818. function onSuccessfulPlacement() {
  819. combo++;
  820. if (combo % COMBO_REWARD_EVERY === 0) {
  821. // Каждые 3 успешных размещения — случайный бонус.
  822. if (Math.random() < 0.5) {
  823. sheepUses++;
  824. showToast("🐑 Комбо! Получены овцы: бонус −10% стресса.");
  825. } else {
  826. noiseUses++;
  827. showToast("🌫️ Комбо! Получен шум: бонус −7% стресса.");
  828. }
  829. }
  830. updateBonusUI();
  831. }
  832.  
  833. function useSheep() {
  834. if (sheepUses <= 0 || gameEnded) return;
  835. sheepUses--;
  836. reduceStress(10);
  837. updateBonusUI();
  838. showToast("🐑 Овцы успокоили мысли. Стресс −10%.");
  839. }
  840.  
  841. function useNoise() {
  842. if (noiseUses <= 0 || gameEnded) return;
  843. noiseUses--;
  844. reduceStress(7);
  845. updateBonusUI();
  846. showToast("🌫️ Белый шум приглушил тревогу. Стресс −7%.");
  847. }
  848.  
  849. // =========================
  850. // СОЗДАНИЕ МЫСЛИ
  851. // =========================
  852. function createPiece(small = false) {
  853. let cells = random(small ? SMALL_SHAPES : NORMAL_SHAPES).map(p => p.slice());
  854. const rotations = Math.floor(Math.random() * 4);
  855. for (let i = 0; i < rotations; i++) cells = rotateShape(cells);
  856.  
  857. return {
  858. id: ++pieceId,
  859. cells,
  860. color: random(COLORS),
  861. text: random(THOUGHTS),
  862. x: 0,
  863. y: 0,
  864. homeX: 0,
  865. homeY: 0,
  866. element: null
  867. };
  868. }
  869.  
  870. function getBoardMetrics() {
  871. const rect = boardEl.getBoundingClientRect();
  872. const styles = getComputedStyle(boardEl);
  873. const gap = parseFloat(styles.gap) || 3;
  874. const cellW = (rect.width - gap * (COLS - 1)) / COLS;
  875. const cellH = (rect.height - gap * (ROWS - 1)) / ROWS;
  876. return {rect, gap, cellW, cellH};
  877. }
  878.  
  879. function getPiecePixelSize(piece) {
  880. const {cellW, cellH, gap} = getBoardMetrics();
  881. const b = bounds(piece.cells);
  882. return {
  883. width: b.cols * cellW + (b.cols - 1) * gap,
  884. height: b.rows * cellH + (b.rows - 1) * gap
  885. };
  886. }
  887.  
  888. function renderPiece() {
  889. if (!active) return;
  890.  
  891. if (!active.element) {
  892. const p = document.createElement("div");
  893. p.className = "piece";
  894. p.dataset.id = active.id;
  895. // ВАЖНО: фигура находится в body, а не внутри .conscious.
  896. // Поэтому её можно свободно перетаскивать поверх всей сцены.
  897. document.body.appendChild(p);
  898. active.element = p;
  899. bindPieceEvents(p);
  900. }
  901.  
  902. const p = active.element;
  903. const b = bounds(active.cells);
  904. const {cellW, cellH, gap} = getBoardMetrics();
  905.  
  906. p.innerHTML = "";
  907. p.style.gridTemplateColumns = `repeat(${b.cols}, ${cellW}px)`;
  908. p.style.gridTemplateRows = `repeat(${b.rows}, ${cellH}px)`;
  909. p.style.width = `${b.cols * cellW + (b.cols - 1) * gap}px`;
  910. p.style.height = `${b.rows * cellH + (b.rows - 1) * gap}px`;
  911. p.style.setProperty("--piece-gap", `${gap}px`);
  912. p.style.setProperty("--color", active.color);
  913. p.style.left = `${active.x}px`;
  914. p.style.top = `${active.y}px`;
  915.  
  916. active.cells.forEach(([r, c]) => {
  917. const cell = document.createElement("div");
  918. cell.className = "piece-cell";
  919. cell.style.gridRow = r + 1;
  920. cell.style.gridColumn = c + 1;
  921. cell.style.background = active.color;
  922. p.appendChild(cell);
  923. });
  924.  
  925. const label = document.createElement("div");
  926. label.className = "piece-label";
  927. label.textContent = active.text;
  928. p.appendChild(label);
  929. }
  930.  
  931. function spawnPiece(small = false) {
  932. if (gameEnded) return;
  933. if (active?.element) active.element.remove();
  934.  
  935. active = createPiece(small);
  936.  
  937. const size = getPiecePixelSize(active);
  938. const zoneRect = consciousEl.getBoundingClientRect();
  939.  
  940. // Координаты активной фигуры теперь в viewport, потому что .piece = fixed.
  941. active.x = zoneRect.left + Math.max(6, (zoneRect.width - size.width) / 2);
  942. active.y = zoneRect.top + Math.max(18, (zoneRect.height - size.height) / 2);
  943. active.homeX = active.x;
  944. active.homeY = active.y;
  945.  
  946. renderPiece();
  947. }
  948.  
  949. // Поворачивает активную мысль. Во время drag сохраняем точку,
  950. // возле которой находится палец/курсора, чтобы фигура не прыгала.
  951. function rotateActive(pointerX = null, pointerY = null) {
  952. if (!active || gameEnded) return;
  953.  
  954. const oldSize = getPiecePixelSize(active);
  955. let anchorX = active.x + oldSize.width / 2;
  956. let anchorY = active.y + oldSize.height / 2;
  957.  
  958. if (drag && pointerX != null && pointerY != null) {
  959. anchorX = pointerX - drag.offsetX + oldSize.width / 2;
  960. anchorY = pointerY - drag.offsetY + oldSize.height / 2;
  961. }
  962.  
  963. active.cells = rotateShape(active.cells);
  964. const size = getPiecePixelSize(active);
  965. active.x = anchorX - size.width / 2;
  966. active.y = anchorY - size.height / 2;
  967.  
  968. if (drag && pointerX != null && pointerY != null) {
  969. drag.offsetX = pointerX - active.x;
  970. drag.offsetY = pointerY - active.y;
  971. drag.lastX = pointerX;
  972. drag.lastY = pointerY;
  973. }
  974.  
  975. // Не даём фигуре полностью исчезнуть за экраном, но разрешаем
  976. // свободно пересекать границы сознания и игрового поля.
  977. active.x = Math.max(-size.width + 12, Math.min(active.x, window.innerWidth - 12));
  978. active.y = Math.max(-size.height + 12, Math.min(active.y, window.innerHeight - 12));
  979.  
  980. renderPiece();
  981. showToast("🔄 Мысль повернулась");
  982. }
  983.  
  984. // =========================
  985. // DRAG / TOUCH
  986. // =========================
  987. function clearPreview() {
  988. for (const cell of boardEl.children) cell.classList.remove("ok", "bad");
  989. }
  990.  
  991. function boardDropPosition(pieceEl) {
  992. const {rect, gap, cellW, cellH} = getBoardMetrics();
  993. const pieceRect = pieceEl.getBoundingClientRect();
  994. const b = bounds(active.cells);
  995.  
  996. // Центр фигуры -> ближайшая клетка верхнего левого угла фигуры.
  997. const anchorX = pieceRect.left + pieceRect.width / 2 - (b.cols * cellW) / 2;
  998. const anchorY = pieceRect.top + pieceRect.height / 2 - (b.rows * cellH) / 2;
  999.  
  1000. return {
  1001. col: Math.round((anchorX - rect.left) / (cellW + gap)),
  1002. row: Math.round((anchorY - rect.top) / (cellH + gap))
  1003. };
  1004. }
  1005.  
  1006. function canPlace(cells, row, col) {
  1007. for (const [r, c] of cells) {
  1008. const rr = row + r;
  1009. const cc = col + c;
  1010. if (rr < 0 || rr >= ROWS || cc < 0 || cc >= COLS) return false;
  1011. if (board[rr][cc]) return false;
  1012. }
  1013. return true;
  1014. }
  1015.  
  1016. function updatePreview(pieceEl) {
  1017. clearPreview();
  1018. if (!active) return;
  1019.  
  1020. const {row, col} = boardDropPosition(pieceEl);
  1021. const ok = canPlace(active.cells, row, col);
  1022.  
  1023. for (const [r, c] of active.cells) {
  1024. const rr = row + r, cc = col + c;
  1025. if (rr >= 0 && rr < ROWS && cc >= 0 && cc < COLS) {
  1026. boardEl.children[rr * COLS + cc].classList.add(ok ? "ok" : "bad");
  1027. }
  1028. }
  1029. }
  1030.  
  1031. function bindPieceEvents(pieceEl) {
  1032. // ПКМ никогда не должен открывать стандартное контекстное меню браузера.
  1033. pieceEl.addEventListener("contextmenu", e => {
  1034. e.preventDefault();
  1035. // Если ЛКМ уже зажата — ПКМ сразу вращает фигуру.
  1036. if (drag && drag.pointerType === "mouse" && drag.primaryHeld) {
  1037. rotateActive(e.clientX, e.clientY);
  1038. }
  1039. });
  1040.  
  1041. pieceEl.addEventListener("mousedown", e => {
  1042. // Надёжный fallback для обычного mouse input.
  1043. // Браузеры иногда не доставляют второй pointerdown на window,
  1044. // когда первый указатель находится в pointer capture.
  1045. if (e.button === 2 && drag && drag.pointerType === "mouse" && drag.primaryHeld) {
  1046. e.preventDefault();
  1047. rotateActive(e.clientX, e.clientY);
  1048. }
  1049. });
  1050.  
  1051. pieceEl.addEventListener("pointerdown", e => {
  1052. if (gameEnded || !active) return;
  1053. e.preventDefault();
  1054.  
  1055. // Второй палец = поворот, первый палец = перетаскивание.
  1056. if (e.pointerType === "touch" && !e.isPrimary) {
  1057. if (drag && drag.pointerType === "touch") {
  1058. rotateActive(e.clientX, e.clientY);
  1059. }
  1060. return;
  1061. }
  1062.  
  1063. // ПКМ не запускает новый drag.
  1064. if (e.pointerType === "mouse" && e.button !== 0) {
  1065. if (e.button === 2 && drag && drag.pointerType === "mouse" && drag.primaryHeld) {
  1066. rotateActive(e.clientX, e.clientY);
  1067. }
  1068. return;
  1069. }
  1070.  
  1071. const rect = pieceEl.getBoundingClientRect();
  1072. drag = {
  1073. pointerId: e.pointerId,
  1074. pointerType: e.pointerType,
  1075. offsetX: e.clientX - rect.left,
  1076. offsetY: e.clientY - rect.top,
  1077. moved: false,
  1078. startX: e.clientX,
  1079. startY: e.clientY,
  1080. lastX: e.clientX,
  1081. lastY: e.clientY,
  1082. primaryHeld: true
  1083. };
  1084.  
  1085. pieceEl.setPointerCapture?.(e.pointerId);
  1086. pieceEl.classList.add("dragging");
  1087. });
  1088.  
  1089. pieceEl.addEventListener("pointermove", e => {
  1090. if (!drag || drag.pointerId !== e.pointerId || !active) return;
  1091. e.preventDefault();
  1092.  
  1093. const dx = e.clientX - drag.startX;
  1094. const dy = e.clientY - drag.startY;
  1095. if (Math.hypot(dx, dy) > 6) drag.moved = true;
  1096.  
  1097. drag.lastX = e.clientX;
  1098. drag.lastY = e.clientY;
  1099.  
  1100. active.x = e.clientX - drag.offsetX;
  1101. active.y = e.clientY - drag.offsetY;
  1102.  
  1103. const size = getPiecePixelSize(active);
  1104. active.x = Math.max(-size.width + 12, Math.min(active.x, window.innerWidth - 12));
  1105. active.y = Math.max(-size.height + 12, Math.min(active.y, window.innerHeight - 12));
  1106.  
  1107. pieceEl.style.left = `${active.x}px`;
  1108. pieceEl.style.top = `${active.y}px`;
  1109. updatePreview(pieceEl);
  1110. });
  1111.  
  1112. pieceEl.addEventListener("pointerup", e => {
  1113. if (!drag || drag.pointerId !== e.pointerId) return;
  1114.  
  1115. const wasMoved = drag.moved;
  1116. drag.primaryHeld = false;
  1117. drag = null;
  1118. pieceEl.classList.remove("dragging");
  1119. clearPreview();
  1120.  
  1121. if (wasMoved) dropPiece(pieceEl);
  1122. });
  1123.  
  1124. pieceEl.addEventListener("pointercancel", () => {
  1125. drag = null;
  1126. pieceEl.classList.remove("dragging");
  1127. clearPreview();
  1128. returnPieceHome();
  1129. });
  1130. }
  1131.  
  1132. function returnPieceHome() {
  1133. if (!active || !active.element) return;
  1134. active.x = active.homeX;
  1135. active.y = active.homeY;
  1136. active.element.style.left = `${active.x}px`;
  1137. active.element.style.top = `${active.y}px`;
  1138. }
  1139.  
  1140. // Дополнительный глобальный fallback для ПКМ + ЛКМ.
  1141. window.addEventListener("mousedown", e => {
  1142. if (gameEnded || !active || !drag) return;
  1143. if (e.button === 2 && drag.pointerType === "mouse" && drag.primaryHeld) {
  1144. e.preventDefault();
  1145. rotateActive(e.clientX, e.clientY);
  1146. }
  1147. }, {passive:false});
  1148.  
  1149. // На touch второй палец вращает фигуру.
  1150. window.addEventListener("pointerdown", e => {
  1151. if (gameEnded || !active || !drag) return;
  1152. if (e.pointerType === "touch" && !e.isPrimary && drag.pointerType === "touch") {
  1153. e.preventDefault();
  1154. rotateActive(e.clientX, e.clientY);
  1155. }
  1156. }, {passive:false});
  1157.  
  1158. window.addEventListener("contextmenu", e => {
  1159. if (drag?.pointerType === "mouse" && drag.primaryHeld) e.preventDefault();
  1160. });
  1161.  
  1162. window.addEventListener("keydown", e => {
  1163. if (gameEnded || !active || !drag || drag.pointerType !== "mouse" || !drag.primaryHeld) return;
  1164. if (e.key.toLowerCase() === "r") {
  1165. e.preventDefault();
  1166. rotateActive(drag.lastX, drag.lastY);
  1167. }
  1168. });
  1169.  
  1170. function dropPiece(pieceEl) {
  1171. if (!active || gameEnded) return;
  1172.  
  1173. const {row, col} = boardDropPosition(pieceEl);
  1174.  
  1175. // ОШИБКА НЕ УДАЛЯЕТ МЫСЛЬ.
  1176. // Она остаётся в сознании и ждёт следующей попытки.
  1177. if (!canPlace(active.cells, row, col)) {
  1178. returnPieceHome();
  1179. addStress(difficulty.failStress);
  1180. combo = 0;
  1181. updateBonusUI();
  1182. showToast(`💥 Неудачная попытка: +${difficulty.failStress}% стресса`);
  1183. // После ошибки текущая мысль остаётся активной.
  1184. // Новая фигура не заменяет её и появляется только после успешного размещения.
  1185. return;
  1186. }
  1187.  
  1188. // Корректно размещаем блок.
  1189. active.cells.forEach(([r, c]) => {
  1190. const rr = row + r;
  1191. const cc = col + c;
  1192. board[rr][cc] = {
  1193. id: active.id,
  1194. color: active.color,
  1195. text: active.text
  1196. };
  1197. });
  1198.  
  1199. if (active.element) active.element.remove();
  1200. active = null;
  1201.  
  1202. renderBoard();
  1203. onSuccessfulPlacement();
  1204.  
  1205. const rows = findFullRows();
  1206. if (rows.length) {
  1207. rows.forEach(r => {
  1208. for (let c = 0; c < COLS; c++) {
  1209. boardEl.children[r * COLS + c].classList.add("clearing");
  1210. }
  1211. });
  1212.  
  1213. setTimeout(() => {
  1214. clearRows(rows);
  1215. clearedRows += rows.length;
  1216. reduceStress(CLEAR_STRESS * rows.length);
  1217. rowsCounterEl.textContent = `Ряды: ${clearedRows} / ${TARGET_ROWS}`;
  1218. showToast(`✨ Линия очищена! Стресс −${CLEAR_STRESS * rows.length}%`);
  1219.  
  1220. if (clearedRows >= TARGET_ROWS) {
  1221. winGame();
  1222. } else {
  1223. spawnPiece(false);
  1224. }
  1225. }, 380);
  1226. } else {
  1227. // Стресс от правильного размещения НЕ растёт.
  1228. // Он уменьшается только за очищенные линии и бонусы.
  1229. spawnPiece(false);
  1230. }
  1231. }
  1232.  
  1233. // =========================
  1234. // СОЗДАНИЕ БОНУСОВ ЗА КОМБО
  1235. // =========================
  1236. // Уже реализовано в onSuccessfulPlacement():
  1237. // каждое третье успешное размещение выдаёт овцы или шум.
  1238. // Сам бонус теперь не замораживает и не удаляет фигуры:
  1239. // он просто снижает стресс.
  1240.  
  1241. // =========================
  1242. // КОНЕЦ ИГРЫ
  1243. // =========================
  1244. function winGame() {
  1245. if (gameEnded) return;
  1246. gameEnded = true;
  1247. setStress(0);
  1248. if (active?.element) active.element.remove();
  1249. active = null;
  1250. resultTitleEl.textContent = "😴 Персонаж уснул";
  1251. resultTextEl.textContent =
  1252. `Ты очистил ${clearedRows} линий на сложности «${difficulty.name}». Мысли уложены, стресс сброшен до нуля.`;
  1253. overlayEl.classList.add("show");
  1254. updateBonusUI();
  1255. }
  1256.  
  1257. function loseGame() {
  1258. if (gameEnded) return;
  1259. gameEnded = true;
  1260. if (active?.element) active.element.remove();
  1261. active = null;
  1262. characterEl.textContent = "😡";
  1263. resultTitleEl.textContent = "😡 Он проснулся";
  1264. resultTextEl.textContent =
  1265. `Стресс достиг 100% на сложности «${difficulty.name}». Попробуй делать меньше ошибок и собирать комбо для получения бонусов.`;
  1266. overlayEl.classList.add("show");
  1267. updateBonusUI();
  1268. }
  1269.  
  1270. // =========================
  1271. // НОВАЯ ИГРА
  1272. // =========================
  1273. function startGame(selectedDifficulty) {
  1274. difficulty = DIFFICULTIES[selectedDifficulty];
  1275. difficultyInfo.textContent =
  1276. `Сложность: ${difficulty.name} · ошибка +${difficulty.failStress}%`;
  1277.  
  1278. gameEnded = false;
  1279. stress = 0;
  1280. clearedRows = 0;
  1281. sheepUses = 0;
  1282. noiseUses = 0;
  1283. combo = 0;
  1284. pieceId = 0;
  1285. drag = null;
  1286. board = createEmptyBoard();
  1287.  
  1288. if (active?.element) active.element.remove();
  1289. active = null;
  1290.  
  1291. overlayEl.classList.remove("show");
  1292. difficultyOverlay.classList.add("hidden");
  1293. rowsCounterEl.textContent = "Ряды: 0 / 5";
  1294.  
  1295. buildBoard();
  1296. setStress(0);
  1297. updateBonusUI();
  1298. startCharacterAnimation();
  1299.  
  1300. spawnPiece(false);
  1301. }
  1302.  
  1303. function showDifficulty() {
  1304. gameEnded = true;
  1305. if (active?.element) active.element.remove();
  1306. active = null;
  1307. difficultyOverlay.classList.remove("hidden");
  1308. }
  1309.  
  1310. // =========================
  1311. // RESIZE
  1312. // =========================
  1313. window.addEventListener("resize", () => {
  1314. if (!active || !active.element || drag) return;
  1315. const size = getPiecePixelSize(active);
  1316. active.x = Math.max(-size.width + 12, Math.min(active.x, window.innerWidth - 12));
  1317. active.y = Math.max(-size.height + 12, Math.min(active.y, window.innerHeight - 12));
  1318. renderPiece();
  1319. });
  1320.  
  1321. // =========================
  1322. // КНОПКИ
  1323. // =========================
  1324. difficultyOverlay.querySelectorAll("[data-difficulty]").forEach(btn => {
  1325. btn.addEventListener("click", () => startGame(btn.dataset.difficulty));
  1326. });
  1327.  
  1328. sheepBtn.addEventListener("click", useSheep);
  1329. noiseBtn.addEventListener("click", useNoise);
  1330.  
  1331. $("restartTop").addEventListener("click", showDifficulty);
  1332. $("restartResult").addEventListener("click", showDifficulty);
  1333.  
  1334. // =========================
  1335. // ПЕРВЫЙ ЭКРАН
  1336. // =========================
  1337. buildBoard();
  1338. setStress(0);
  1339. updateBonusUI();
  1340. showDifficulty();
  1341.  
  1342. })();
  1343. </script>
  1344. </body>
  1345. </html>
Add Comment
Please, Sign In to add comment