Teach programming with a reachable ship destination and movement choices

This commit is contained in:
coyotte508 2026-10-31 17:56:01 +01:00
commit 77d75ece95
8 changed files with 73 additions and 13 deletions

View file

@ -13,7 +13,7 @@ npm test
npm run dev
```
Open <http://127.0.0.1:5250>. Start with **Flight school / École de vol**: eight exercises use the real engine. Start with **Planning turns**: one crew member, two movement cards, and an empty turn. Arrange the cards, try the start/pause practice clock, then watch each turn execute. The later exercises have editable programs and a teammate already maintaining the computer; they cover firing, energy, malfunctions, battlebots/interceptors, double actions, phasing and specializations.
Open <http://127.0.0.1:5250>. Start with **Flight school / École de vol**: eight exercises use the real engine. Start with **Planning turns**: one crew member, a highlighted destination, two movement actions, and an empty turn. Choose left, right or a deck change to reach the destination; try the start/pause practice clock, then watch each turn execute. A missed destination can be retried. The later exercises have editable programs and a teammate already maintaining the computer; they cover firing, energy, malfunctions, battlebots/interceptors, double actions, phasing and specializations.
For a full mission, expand **Local session / Session locale**. Select 1–5 humans, the crew, mission, threat pools and optional modules. In solo, you control four androids and have access to the full action deck. In multiplayer testing, open another tab with `?seat=1`, etc. Readiness lasts two minutes; everyone must be ready together. The local mission starts after a three-second countdown. If someone misses the window, the crew keeps waiting. Select a card half, then a turn. Advance individual phases to lock previous turns, or let the shared clock do so. After programming, the captain can resolve one step at a time or finish the mission; everyone can inspect the replay and log.

View file

@ -61,9 +61,10 @@ export async function mountLesson(target, { chapter = "basics", locale = "en", o
const label = [t("Découvrir", "Discover"), t("Préparer", "Plan"), t("Exécuter", "Execute")];
const transport = (action, icon, title, disabled = false) => `<button data-guide="${action}" class="quiet icon-button" title="${title}" aria-label="${title}" ${disabled ? 'disabled' : ''}>${pictogram(icon)}</button>`;
function renderGuide(s) {
const missed = LESSONS[index].basics && s.step === 2 && completedTurns(s.state) >= 3 && !s.completed;
guide.innerHTML = `<div class="native-guide-top"><span>${escape(LESSONS[index].title[locale === "fr" ? 0 : 1])}</span><div class="native-guide-tools">${standalone ? `<a href="/">${t("Partie locale", "Local game")}</a>` : ''}${transport("sound", soundOn ? "speaker" : "muted", soundOn ? t("Couper les sons", "Mute sounds") : t("Activer les sons", "Enable sounds"))}</div></div>
<nav class="basics-stages" aria-label="${t("Étapes", "Steps")}">${label.map((name, i) => `<button data-guide-step="${i}" class="quiet ${Math.min(s.step, 2) === i ? 'active' : ''}" ${i > s.step || s.busy ? 'disabled' : ''} ${s.step === i ? 'aria-current="step"' : ''}><span class="step-number">${i + 1}</span><span>${name}</span></button>`).join('')}</nav>
<h1>${escape(s.title)}</h1><p class="native-guide-text">${escape(s.text)}</p>
<h1>${escape(s.title)}</h1><p class="native-guide-text">${escape(missed ? t("Destination manquée. Revenez préparer un autre trajet.", "Destination missed. Go back and plan another route.") : s.text)}</p>
<div class="native-guide-controls">${transport("restart", "rewind", t("Recommencer l’exercice", "Restart exercise"), s.busy)}${transport("previous", "left", t("Étape précédente", "Previous step"), s.step === 0 || s.busy)}${transport("replay", "restart", t("Rejouer cette étape", "Replay step"), s.busy || s.step === 0)}${s.canContinue ? `<button data-guide="continue" class="primary icon-button" title="${t("Commencer", "Start")}" aria-label="${t("Commencer", "Start")}">${pictogram("right")}</button>` : ''}${s.completed && (nextChapter || standalone && LESSONS[index + 1]) ? `<button data-guide="next" class="primary icon-label"><span>${t("Exercice suivant", "Next exercise")}</span>${pictogram("right")}</button>` : ''}<small title="${t("Progression enregistrée", "Progress saved")}" aria-label="${t("Progression enregistrée", "Progress saved")}">${s.saved ? "✓" : ""}</small></div>
${s.error ? `<p role="alert">${escape(s.error)}</p>` : ''}`;
}

View file

@ -389,6 +389,15 @@ export function mountConsole(root, host = null) {
crewLabel: (id) =>
view.players[id]?.name ?? `${t("Androïde", "Android")} ${id + 1}`,
});
if (basic && view.tutorial.targetStation) {
const goal = $("#ship").querySelector(`[data-station="${view.tutorial.targetStation}"]`);
if (goal) {
const reached = view.stage === "resolution" && ship.crew[0].station === view.tutorial.targetStation;
goal.classList.add("tutorial-destination");
goal.classList.toggle("destination-reached", reached);
goal.insertAdjacentHTML("beforeend", `<span class="destination-marker" role="img" aria-label="${t("Destination", "Destination")}" title="${t("Destination", "Destination")}">${pictogram(reached ? "check" : "destination")}</span>`);
}
}
$("#resources").innerHTML =
`${symbol("fuel", `${t("Combustible", "Fuel")} : ${ship.fuel}`, `<b>${ship.fuel}</b>`)}${symbol("rocket", `${t("Roquettes", "Rockets")} : ${ship.rockets}`, `<b>${ship.rockets}</b>`)}${symbol("computer", t("Ordinateur", "Computer") + " · " + ship.computer.map((x, i) => `${t("Phase", "Phase")} ${i + 1} : ${x ? t("entretenu", "maintained") : t("à entretenir", "not maintained")}`).join(" · "), ship.computer.map((x, i) => `<span class="computer-phase ${x ? "maintained" : ""}">${i + 1}</span>`).join(""))}${symbol("bots", `${t("Robots de combat · Escouades disponibles", "Battlebots · Available squads")} : ${ship.bots.filter((b) => b.owner === null && b.station && !b.disabled).length}`, `<b>${ship.bots.filter((b) => b.owner === null && b.station && !b.disabled).length}</b><small>${t("escouades", "squads")}</small>`)}${ship.crew
.filter((p) => p.space)
@ -531,12 +540,12 @@ export function mountConsole(root, host = null) {
];
const grouped = [];
for (const card of hand) {
if (basic && !card.sides.some(side => side.length === 1 && ["red", "blue"].includes(side[0]))) continue;
if (basic && !card.sides.some(side => side.length === 1 && ["red", "blue", "lift"].includes(side[0]))) continue;
const same = grouped.find(
(c) =>
c.kind === "normal" &&
card.kind === "normal" &&
JSON.stringify(basic ? c.sides.filter(side => side.length === 1 && ["red", "blue"].includes(side[0])) : c.sides) === JSON.stringify(basic ? card.sides.filter(side => side.length === 1 && ["red", "blue"].includes(side[0])) : card.sides),
JSON.stringify(basic ? c.sides.filter(side => side.length === 1 && ["red", "blue", "lift"].includes(side[0])) : c.sides) === JSON.stringify(basic ? card.sides.filter(side => side.length === 1 && ["red", "blue", "lift"].includes(side[0])) : card.sides),
);
if (same) same.count++;
else grouped.push({ ...card, count: 1 });
@ -579,7 +588,7 @@ export function mountConsole(root, host = null) {
)
.map(
(c) =>
`<div class="card ${c.kind}">${c.count > 1 ? `<span class="copies">×${c.count}</span>` : ""}${c.sides.map((side, index) => basic && !(side.length === 1 && ["red", "blue"].includes(side[0])) ? "" : `<button data-card="${esc(c.id)}" data-side="${index}" class="${selected.some((s) => s.id === c.id && s.side === index) ? "selected" : ""}" aria-pressed="${selected.some((s) => s.id === c.id && s.side === index)}" title="${esc(side.map(label).join(" → "))}" aria-label="${esc(side.map(label).join(" → "))}">${side.map(icon).join(" · ")}</button>`).join("")}</div>`,
`<div class="card ${c.kind}">${c.count > 1 ? `<span class="copies">×${c.count}</span>` : ""}${c.sides.map((side, index) => basic && !(side.length === 1 && ["red", "blue", "lift"].includes(side[0])) ? "" : `<button data-card="${esc(c.id)}" data-side="${index}" class="${selected.some((s) => s.id === c.id && s.side === index) ? "selected" : ""}" aria-pressed="${selected.some((s) => s.id === c.id && s.side === index)}" title="${esc(side.map(label).join(" → "))}" aria-label="${esc(side.map(label).join(" → "))}">${side.map(icon).join(" · ")}</button>`).join("")}</div>`,
)
.join("")
: "";

View file

@ -35,6 +35,7 @@ const paths = {
step: "m5 4 11 8L5 20V4Zm14 0v16",
forward: "m2 5 9 7-9 7V5Zm10 0 9 7-9 7V5Z",
restart: "M4 10a8 8 0 1 1 1 8M4 3v7h7",
destination: "M5 21V3m0 0h14l-3 4 3 4H5",
check: "m4 12 5 5L20 6",
close: "m5 5 14 14M5 19 19 5",
cards: "M7 7h13v15H7zM4 18H2V2h13v2",

View file

@ -2264,7 +2264,7 @@ input:not([type="checkbox"]):not([type="range"]) {
.training-ship .deck-upper .station {
min-height: 88px;
}
.training-ship .deck-upper .occupants {
.training-ship .occupants {
align-items: center;
min-height: 50px;
padding: 8px 0;
@ -2277,7 +2277,7 @@ input:not([type="checkbox"]):not([type="range"]) {
min-height: 88px;
}
.training-ship .deck-lower .occupants {
display: none;
display: flex;
}
.training-ship .crew-pawn > svg.equipment-art {
width: 36px;
@ -2358,9 +2358,8 @@ input:not([type="checkbox"]):not([type="range"]) {
.native-tutorial.learning-basics #program { display: flex; gap: 12px; border-left: 3px solid #e6b66b; padding: 12px; background: #101e28; }
.native-tutorial.learning-basics #program .slot { flex: 0 0 72px; min-height: 90px; }
.native-tutorial.learning-basics #program .slot.current { border-color: #74e8bd; box-shadow: 0 0 0 2px #74e8bd55; }
.native-tutorial.learning-basics #hand { grid-template-columns: repeat(2, 80px); }
.native-tutorial.learning-basics #hand { grid-template-columns: repeat(3, 80px); }
.native-tutorial.learning-basics #hand .card { min-height: 68px; }
.native-tutorial.learning-basics #hand .copies,
.native-tutorial.learning-basics #program-crew,
.native-tutorial.learning-basics .crew-tabs,
.native-tutorial.learning-basics #player-help,
@ -2393,3 +2392,19 @@ input:not([type="checkbox"]):not([type="range"]) {
.training-ship .deck-upper .station,
.training-ship .deck-lower .station { min-height: 104px; }
.native-tutorial.learning-basics .training-ship .deck-lower { opacity: 1; }
.training-ship .station.tutorial-destination {
border: 2px dashed #e8c984;
background: #e8c98418;
}
.destination-marker { position: absolute; right: 10px; bottom: 10px; color: #e8c984; }
.training-ship .station.destination-reached { border-style: solid; border-color: #74e8bd; background: #74e8bd18; }
.destination-reached .destination-marker { color: #74e8bd; }
.native-tutorial.learning-basics #hand .card > button {
display: flex;
align-items: center;
justify-content: center;
min-height: 68px;
width: 100%;
}

View file

@ -13,7 +13,7 @@ export function createLessonTutorial(id, { locale = "en", storage, onProgress }
if (!lesson) throw Error("Unknown lesson");
const t = (fr, en) => locale === "fr" ? fr : en;
return createTutorial({
game: "space-alert", id, version: 2, storage, onProgress,
game: "space-alert", id, version: lesson.basics ? 3 : 2, storage, onProgress,
initialState: () => createLesson(id, 1000),
move(state, move) {
if (move.type === "practice-phase") {
@ -39,12 +39,12 @@ export function createLessonTutorial(id, { locale = "en", storage, onProgress }
{ id: "discover", title: lesson.title[locale === "fr" ? 0 : 1],
text: lesson.basics ? t("Préparez vos actions, puis regardez-les s’exécuter. Commençons sans menace, avec un seul androïde.", "Plan your actions, then watch them execute. Start without threats, with one android.") : lesson.instructions.map(p => p[locale === "fr" ? 0 : 1]).join("\n\n") },
{ id: "plan", title: t("Préparer le programme", "Plan the program"),
text: lesson.basics ? t("Placez deux flèches dans le programme. Le vaisseau attend. La troisième case reste vide : attendre.", "Place two arrows in the program. The ship waits. The third slot stays empty: wait.") : t("Programmez les cartes sur le vaisseau, puis terminez la programmation. Le chrono est facultatif ici.", "Program cards on the ship, then finish planning. The clock is optional here."),
text: lesson.basics ? t("Rejoignez la salle marquée en deux actions. La troisième case reste vide : attendre.", "Reach the marked room in two actions. Leave the third slot empty: wait.") : t("Programmez les cartes sur le vaisseau, puis terminez la programmation. Le chrono est facultatif ici.", "Program cards on the ship, then finish planning. The clock is optional here."),
complete: state => state.stage === "resolution" },
{ id: "execute", title: t("Exécuter les tours", "Run the turns"),
text: t("Programme verrouillé. Avancez la résolution avec ▶. Les équipiers agissent ensemble, puis les menaces.", "Program locked. Advance resolution with ▶. Crew act together, then threats."),
complete: state => lesson.basics ? completedTurns(state) >= 3 : !!state.game.resolution?.outcome },
complete: state => lesson.basics ? completedTurns(state) >= 3 && state.game.resolution.ship.crew[0].station === state.tutorial.targetStation : !!state.game.resolution?.outcome },
],
completion: { title: t("Exercice terminé", "Exercise complete"), text: lesson.basics ? t("Le chrono sert à préparer. Les tours exécutent ensuite votre programme. Une case vide signifie attendre.", "The clock is for planning. Turns then execute your program. An empty slot means wait.") : t("Rejouez pour comparer un autre programme, ou passez à la suite.", "Replay to compare another program, or move on.") },
completion: { title: t("Exercice terminé", "Exercise complete"), text: lesson.basics ? t("Destination atteinte ! Votre programme vous y a conduit.", "Destination reached! Your program took you there.") : t("Rejouez pour comparer un autre programme, ou passez à la suite.", "Replay to compare another program, or move on.") },
});
}

View file

@ -197,6 +197,7 @@ export function createLesson(id, now) {
title: l.title,
instructions: l.instructions,
basics: !!l.basics,
targetStation: l.basics ? "blue-lower" : undefined,
clockRunning: false,
};
s.game.tracks = Object.fromEntries(
@ -219,5 +220,15 @@ export function createLesson(id, now) {
s.game.programs[1][turn - 1] = { cards: [{ id, side }] };
s.game.slotVersions[1][turn - 1]++;
}
if (l.basics) {
// A small physical hand makes spending and reusing actions visible.
const remaining = { red: 2, blue: 2, lift: 2 };
s.game.hands[0] = s.game.hands[0].filter(id => {
const action = s.game.cards[id].sides.find(side => side.length === 1 && remaining[side[0]] > 0)?.[0];
if (!action) return false;
remaining[action]--;
return true;
});
}
return s;
}

View file

@ -53,3 +53,26 @@ test("practice clock advances planning only; resolution remains untimed", async
assert.equal(completedTurns(t.snapshot.state), 0);
t.destroy();
});
for (const route of [["blue", "lift"], ["lift", "blue"], ["blue", "red"], ["red", "lift"]]) {
test(`navigation lesson checks the resolved destination: ${route.join(", ")}`, async () => {
const t = await createLessonTutorial("basics");
await t.continue();
await place(t, 1, route[0]);
await place(t, 2, route[1]);
assert.equal(t.snapshot.completed, false);
await t.play({ type: "practice-phase" });
await t.play({ type: "practice-phase" });
for (let i = 0; i < 30 && completedTurns(t.snapshot.state) < 3; i++)
assert.equal(await t.play({ type: "resolve" }), true, t.snapshot.error);
const succeeds = route.includes("blue") && route.includes("lift");
assert.equal(t.snapshot.completed, succeeds);
assert.equal(t.snapshot.state.game.resolution.ship.crew[0].station === "blue-lower", succeeds);
if (!succeeds) {
await t.previousStep();
assert.equal(t.snapshot.state.stage, "programming");
assert.equal(t.snapshot.step, 1);
}
t.destroy();
});
}