Allow returning to the safe trainer start
This commit is contained in:
1 parent
ba25b64190
commit
ba074df4ec
10 files changed
+102
-48
No files matched your search
@@ -85,7 +85,7 @@ export class Training {
|
||||
}
|
||||
#valid(id) { return Number.isInteger(id) && id >= 0 && id < ROWS * COLS; }
|
||||
#finished() { return this.#status === 'won' || this.#status === 'lost'; }
|
||||
#transition(id) { return id === START || id === this.#field.exit; }
|
||||
#transition(id) { return id === this.#field.exit; }
|
||||
#available(id) { return !this.#transition(id) && distance(this.#position, id) === 1; }
|
||||
#guard(id) {
|
||||
if (this.#finished()) return {code: 'finished'};
|
||||
@@ -108,8 +108,9 @@ export class Training {
|
||||
this.#history.push({type: 'fall', id});
|
||||
return {code: 'fall', id, hint: null};
|
||||
}
|
||||
const code = this.#opened.has(id) ? 'revisited' : 'opened';
|
||||
this.#opened.add(id); this.#position = id;
|
||||
const code = id === START || this.#opened.has(id) ? 'revisited' : 'opened';
|
||||
if (id !== START) this.#opened.add(id);
|
||||
this.#position = id;
|
||||
const value = this.#field.values[id];
|
||||
this.#history.push({type: code, id, value});
|
||||
this.#win();
|
||||
@@ -121,7 +122,7 @@ export class Training {
|
||||
mark(id) {
|
||||
const rejected = this.#guard(id);
|
||||
if (rejected) return rejected;
|
||||
if (this.#opened.has(id)) return {code: 'opened'};
|
||||
if (id === START || this.#opened.has(id)) return {code: 'opened'};
|
||||
const marked = !this.#marks.has(id);
|
||||
if (marked) this.#marks.add(id); else this.#marks.delete(id);
|
||||
this.#history.push({type: marked ? 'marked' : 'unmarked', id});
|
||||
@@ -131,6 +132,7 @@ export class Training {
|
||||
rate(id, rating) {
|
||||
const rejected = this.#guard(id);
|
||||
if (rejected) return rejected;
|
||||
if (id === START) return {code: 'opened'};
|
||||
if (rating !== null && (!Number.isInteger(rating) || rating < 0 || rating > 7)) return {code: 'invalid-level'};
|
||||
if ((this.#ratings.get(id) ?? null) === rating) return {code: 'unchanged'};
|
||||
if (rating === null) this.#ratings.delete(id); else this.#ratings.set(id, rating);
|
||||
|
||||
@@ -67,7 +67,7 @@ dd { margin: 0; text-align: right; font-weight: bold; }
|
||||
.cell-grid .current button { box-shadow: inset 0 0 0 2px var(--light); }
|
||||
.scene-grid .hint button { background: var(--danger); color: var(--light); }
|
||||
.cell-grid button:focus-visible { outline: 3px solid var(--focus); outline-offset: -4px; box-shadow: inset 0 0 0 5px var(--ink); z-index: 3; position: relative; }
|
||||
.cell-grid .transition button { background: #222b28cc; color: var(--light); }
|
||||
.cell-grid :is(.entrance, .transition) button { background: #222b28cc; color: var(--light); }
|
||||
.cell-grid .wrong button { background: var(--paper); color: var(--danger); }
|
||||
.cell-coord { position: absolute; left: 4px; top: 2px; font-size: 10px; font-weight: normal; color: var(--light); background: #17120dbb; padding: 0 2px; line-height: 1.4; }
|
||||
.cell-value { font-size: clamp(14px, 1.5vw, 24px); }
|
||||
|
||||
+10
-7
@@ -43,8 +43,9 @@ function describe(cell, view, showNotes = true, isMap = false) {
|
||||
if (cell.hazard) return `опасная клетка${rating}`;
|
||||
if (cell.entrance || cell.opened || ended(view)) {
|
||||
const fact = simple() || ended(view) ? `, ${levelText(cell.value).slice(0, -1).toLowerCase()}` : '';
|
||||
if (cell.entrance) return `вход${fact}`;
|
||||
return `${cell.opened ? 'проверено' : 'безопасная клетка'}${fact}${rating}${!isMap && cell.available ? ', можно прыгнуть' : ''}`;
|
||||
const jump = !isMap && cell.available ? ', можно прыгнуть' : '';
|
||||
if (cell.entrance) return `стартовая клетка${fact}${jump}`;
|
||||
return `${cell.opened ? 'проверено' : 'безопасная клетка'}${fact}${rating}${jump}`;
|
||||
}
|
||||
if (cell.marked && showNotes) return `ваш флажок опасности${rating}`;
|
||||
if (hints.has(cell.id)) return `подсказка: опасность${rating}`;
|
||||
@@ -189,7 +190,7 @@ 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)}`;
|
||||
$('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 = simple() ? `${Math.round(hintChance(view.options.lu) * 100)}%` : 'Выкл.';
|
||||
@@ -202,15 +203,17 @@ function render() {
|
||||
$('scene-instructions').textContent = compact.matches ? 'Выберите клетку, затем нажмите нужную кнопку под полем.' : 'Нажмите на соседнюю клетку, чтобы прыгнуть. Правая кнопка мыши или Shift+Enter ставят или снимают флажок.';
|
||||
const cell = view.cells[selected], note = cell.marked ? 'Снять отметку' : 'Отметить опасной';
|
||||
const selectionState = finished ? 'попытка завершена' : cell.id === view.position ? 'вы здесь' :
|
||||
cell.transition ? (cell.entrance ? 'вход' : 'выход') : cell.marked ? 'есть отметка' :
|
||||
cell.entrance ? (cell.available ? 'старт' : 'старт, вне досягаемости') :
|
||||
cell.transition ? 'выход' : cell.marked ? 'есть отметка' :
|
||||
!cell.available ? 'вне досягаемости' : '';
|
||||
$('touch-actions').hidden = !compact.matches;
|
||||
$('selection').textContent = `Клетка ${coordinate(selected)}${selectionState ? ` (${selectionState})` : ''}`;
|
||||
$('map-selection').textContent = `Клетка ${coordinate(selected)} · ${describe(cell, view, true, true)}`;
|
||||
$('mark').textContent = note; $('map-mark').textContent = note;
|
||||
$('jump').disabled = finished || !cell.available || cell.marked;
|
||||
for (const id of ['mark','map-mark']) $(id).disabled = finished || cell.opened || cell.transition;
|
||||
$('map-levels').disabled = finished || cell.transition;
|
||||
const notesLocked = finished || cell.entrance || cell.transition;
|
||||
for (const id of ['mark','map-mark']) $(id).disabled = notesLocked || cell.opened;
|
||||
$('map-levels').disabled = notesLocked;
|
||||
for (const button of $('map-levels').querySelectorAll('[data-level]')) button.setAttribute('aria-pressed', String(Number(button.dataset.level) === cell.rating));
|
||||
$('map-clear-level').disabled = cell.rating === null;
|
||||
$('clear-marks').disabled = finished || (view.marks === 0 && view.ratings === 0);
|
||||
@@ -321,7 +324,7 @@ $('new-game').addEventListener('click', event => confirmAction('Начать з
|
||||
$('clear-marks').addEventListener('click', event => confirmAction('Очистить отметки?', 'Исчезнут только ваши флажки и оценки. Проверенные клетки и история останутся, а игру можно будет продолжить.', 'Очистить отметки', () => { game.clearMarks(); $('status').textContent = 'Флажки и оценки убраны. Можно продолжать.'; render(); }, event.currentTarget));
|
||||
$('simple-mode').addEventListener('change', () => {
|
||||
stopSound(); clearHints();
|
||||
$('status').textContent = simple() ? 'В упрощённом режиме уровни видны на входе и на проверенных клетках.' : 'В звуковом режиме оцените клетку по шорохам.';
|
||||
$('status').textContent = simple() ? 'В упрощённом режиме уровни видны на стартовой и проверенных клетках.' : 'В звуковом режиме оцените клетку по шорохам.';
|
||||
$('messages').replaceChildren(); messages.forEach(renderMessage);
|
||||
$('history').replaceChildren(); renderedHistory = 0;
|
||||
render();
|
||||
|
||||
Reference in new issue
Block a user