fix: anchor trainer entrance and generate variable exits

This commit is contained in:
nyan404 committed 2026-11-17 16:44:04 +03:00
1 parent 30d012de80
commit 87a9a5934a
12 files changed
+117 -53

No files matched your search

+9 -7
View File
@@ -1,4 +1,4 @@
import {Training, DEFAULTS, ROWS, COLS, START, EXIT, coordinate, hintChance} from './engine.js';
import {Training, DEFAULTS, ROWS, COLS, START, coordinate, hintChance} from './engine.js';
const $ = id => document.getElementById(id);
const compact = matchMedia('(max-width: 700px), (pointer: coarse)');
@@ -15,9 +15,10 @@ function addItem(list, text) {
}
function sound(value) { return sounds[value] || 'Очень громкий шорох'; }
function ended(view) { return view.status === 'won' || view.status === 'lost'; }
function initialCells(view) { return view.cells.filter(cell => cell.base).map(cell => coordinate(cell.id)).join(', '); }
function describe(cell, view) {
if (cell.id === START) return 'вход';
if (cell.id === EXIT) return 'выход';
if (cell.entrance) return 'вход';
if (cell.exit) return 'выход';
if (cell.wrong) return 'ошибочная отметка, безопасно';
if (cell.hazard) return 'опасная клетка';
if (cell.opened) return `проверено, опасностей рядом: ${cell.value}`;
@@ -27,7 +28,7 @@ function describe(cell, view) {
return cell.available ? 'неизвестно, прыжок доступен' : 'неизвестно, сначала откройте соседнюю клетку';
}
function cellValue(cell, view, showMarks) {
if (cell.transition) return cell.id === START ? '↥' : '↗';
if (cell.transition) return cell.entrance ? '↥' : '↗';
if (cell.wrong) return '≠';
if (cell.hazard) return '×';
if (cell.marked && showMarks) return '⚑';
@@ -104,7 +105,7 @@ function start(options = DEFAULTS) {
stopTimers(); game = new Training(options); selected = START; startedAt = null; renderedHistory = 0;
$('history').replaceChildren(); $('messages').replaceChildren();
addItem($('messages'), 'Лес затих. Звуки появятся после прыжка.');
$('status').textContent = `Начните с клеток А1–А${options.height === 1 ? 5 : 3}. Стрелки перемещают фокус, Enter или пробел выполняет действие.`;
$('status').textContent = `Начальные клетки: ${initialCells(game.view())}. Стрелки перемещают фокус, Enter или пробел выполняет действие.`;
updateClock(); render();
}
function render() {
@@ -113,7 +114,7 @@ function render() {
for (const cell of view.cells) {
const node = cells[cell.id], button = buttons[cell.id];
const projectedMark = cell.marked && (isMap || projection);
node.className = [cell.opened && 'opened', projectedMark && 'marked', cell.available && !cell.transition && 'available', cell.transition && 'transition', cell.hazard && 'hazard', cell.wrong && 'wrong', cell.id === selected && 'selected', cell.id === view.position && 'current', hints.has(cell.id) && !finished && 'hint'].filter(Boolean).join(' ');
node.className = [cell.opened && 'opened', projectedMark && 'marked', cell.available && !cell.transition && 'available', cell.transition && 'transition', cell.entrance && 'entrance', cell.exit && 'exit', cell.hazard && 'hazard', cell.wrong && 'wrong', cell.id === selected && 'selected', cell.id === view.position && 'current', hints.has(cell.id) && !finished && 'hint'].filter(Boolean).join(' ');
node.setAttribute('aria-selected', String(cell.id === selected));
button.tabIndex = cell.id === selected ? 0 : -1;
button.querySelector('.cell-value').textContent = cellValue(cell, view, isMap || projection);
@@ -125,13 +126,14 @@ function render() {
$('lu-value').textContent = `${view.options.lu} ЛУ`;
$('height-value').textContent = `${view.options.height} из 5`;
$('scene-height').textContent = `Высота ${view.options.height}`;
$('transition-coordinates').textContent = `Вход: ${coordinate(view.start)} · Выход: ${coordinate(view.exit)}`;
$('season-value').textContent = {'-3':'Лето',0:'Демисезон',5:'Зима'}[view.options.season];
$('growth-value').textContent = {12:'45–75%',15:'76–85%',18:'81–88%',22:'89–95%',25:'96–100%'}[view.options.growth];
$('hint-chance').textContent = `${Math.round(hintChance(view.options.lu) * 100)}%`;
$('progress').textContent = `${view.opened} / ${view.safe}`;
$('mark-count').textContent = view.marks; $('hazard-count').textContent = view.hazards;
$('attempt-state').textContent = {ready:'Готов к прыжку',playing:'На уступах',won:'Карта готова',lost:'Падение'}[view.status];
$('scene-instructions').textContent = compact.matches ? `Выберите клетку, затем нажмите «Прыгнуть» или «Отметить опасной». Начало: А1–А${view.options.height === 1 ? 5 : 3}.` : `Клик — ${mode === 'jump' ? 'прыжок' : 'отметка'}. Начало: А1–А${view.options.height === 1 ? 5 : 3}, затем рядом с любой проверенной клеткой.`;
$('scene-instructions').textContent = compact.matches ? `Выберите клетку, затем нажмите «Прыгнуть» или «Отметить опасной». Начальные клетки: ${initialCells(view)}.` : `Клик — ${mode === 'jump' ? 'прыжок' : 'отметка'}. Начальные клетки: ${initialCells(view)}; затем рядом с любой проверенной клеткой.`;
const cell = view.cells[selected], note = cell.marked ? 'Снять отметку' : 'Отметить опасной';
$('selection').textContent = `Выбрана клетка ${coordinate(selected)} · ${describe(cell, view)}`;
$('map-selection').textContent = `Выбрана ${coordinate(selected)} · ${describe(cell, view)}`;