HTML 1ファイルで動きます。コピーして、新しいファイル(〇〇.html)に貼ると、そのまま遊べます。このフォルダの 2_kinko/index.html と同じ中身です。
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>金庫とパスワード</title>
<style>
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; background: #0e1430; }
* { box-sizing: border-box; }
#stage { position: absolute; left: 0; top: 0; width: 960px; height: 540px; overflow: hidden; color: #f4f7ff; font-size: 18px; user-select: none; -webkit-user-select: none;
background:
radial-gradient(circle at 80px 190px, #fff 0 1.5px, transparent 2px),
radial-gradient(circle at 300px 160px, #fff 0 1px, transparent 2px),
radial-gradient(circle at 560px 200px, #fff 0 1.5px, transparent 2px),
radial-gradient(circle at 900px 170px, #fff 0 1px, transparent 2px),
radial-gradient(circle at 760px 260px, #fff 0 1px, transparent 2px),
linear-gradient(#10173a 0%, #1d2a5e 70%, #2b3a78 70%, #222f66 100%); }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
button:disabled { cursor: default; }
#hud { position: absolute; left: 0; top: 0; width: 960px; height: 40px; background: rgba(6, 10, 28, .7); display: flex; align-items: center; padding: 0 10px; gap: 8px; }
.step { font-size: 16px; padding: 3px 12px; border-radius: 14px; background: #2b376b; color: #9fb0e0; white-space: nowrap; }
.step.now { background: #ffd54f; color: #2a2100; font-weight: 700; }
.step.done { background: #2f9e6a; color: #fff; }
#score { margin-left: auto; font-size: 20px; font-weight: 700; color: #ffd54f; white-space: nowrap; }
#mute { font-size: 16px; padding: 4px 12px; border-radius: 10px; background: #3a4a8a; white-space: nowrap; }
#talk { position: absolute; left: 10px; top: 46px; width: 940px; height: 84px; background: #fff; color: #1c2340; border-radius: 16px; display: flex; align-items: center; padding: 0 12px 0 8px; gap: 10px; box-shadow: 0 4px 0 rgba(0, 0, 0, .3); }
#picoFace { width: 72px; height: 72px; flex: none; }
#picoFace.hop { animation: hop .35s; }
#talkText { flex: 1; font-size: 20px; line-height: 1.45; white-space: pre-line; font-weight: 600; }
#next { flex: none; min-width: 150px; height: 56px; padding: 0 16px; border-radius: 14px; background: #ff8a3d; color: #fff; font-size: 20px; font-weight: 700; box-shadow: 0 5px 0 #b9541a; animation: pulse 1s infinite; white-space: nowrap; }
#next:active { transform: translateY(3px); box-shadow: 0 2px 0 #b9541a; }
#main { position: absolute; left: 0; top: 134px; width: 960px; height: 406px; }
#fx { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 50; }
.panel { background: rgba(8, 14, 40, .6); border: 2px solid #4a5a9a; border-radius: 14px; padding: 10px 12px; }
.btn { border-radius: 14px; background: #3f6fe0; color: #fff; font-weight: 700; font-size: 20px; padding: 10px 18px; box-shadow: 0 5px 0 #24459b; }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #24459b; }
.btn:disabled { opacity: .4; }
.btn.go { background: #2fae6b; box-shadow: 0 5px 0 #1b7044; }
.lbl { font-size: 16px; color: #c5d1f5; }
/* 金庫 */
.safe svg { display: block; width: 100%; height: auto; }
.safe .door { transform-box: view-box; transform-origin: 40px 168px; transition: transform .5s cubic-bezier(.3, 1.5, .5, 1); }
.safe.open .door { transform: scaleX(.1); }
.safe .dial { transform-box: view-box; transform-origin: 150px 168px; }
.safe.spin .dial { animation: rot .5s linear infinite; }
.safe.shake { animation: shake .35s; }
.safe .chain { display: none; }
.safe.locked .chain { display: block; animation: pop .3s; transform-box: view-box; transform-origin: 150px 168px; }
.safe .cells text, .safe .msg { fill: #5dff9b; font-weight: 700; }
.safe .cells.bad text, .safe .msg.bad { fill: #ff6b6b; }
.safe .cells.ok text, .safe .msg.ok { fill: #ffd54f; }
.safe.golden .body { fill: #e9b93a; }
/* ガチャロボ */
.gacha svg { display: block; width: 100%; height: auto; }
.gacha .eyesX { display: none; }
.gacha.dizzy .eyesA { display: none; }
.gacha.dizzy .eyesX { display: block; }
.gacha.dizzy { animation: wobble 1s ease-in-out infinite; }
.gacha.attack { animation: jitter .12s linear infinite; }
.gacha.laugh { animation: hop .3s infinite; }
.bubble { background: #fff; color: #1c2340; border-radius: 14px; padding: 8px 12px; font-size: 18px; font-weight: 700; text-align: center; min-height: 44px; white-space: pre-line; }
/* 場面1 */
.keys { display: grid; grid-template-columns: repeat(3, 80px); gap: 10px; }
.key { width: 80px; height: 60px; font-size: 26px; font-weight: 700; background: #e9eefb; color: #1c2340; border-radius: 12px; box-shadow: 0 5px 0 #8e9cc4; }
.key:active { transform: translateY(3px); box-shadow: 0 2px 0 #8e9cc4; }
.key.sub { font-size: 18px; background: #ffc9c9; box-shadow: 0 5px 0 #b97a7a; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; min-height: 30px; }
.chip { background: #5a2a3a; color: #ffb3b3; border-radius: 8px; padding: 1px 8px; font-size: 18px; font-weight: 700; animation: pop .25s; }
.big { font-size: 22px; font-weight: 700; }
.yel { color: #ffd54f; }
/* 場面2 */
.hat { display: inline-block; background: #ffbf00; color: #3a2a00; font-weight: 700; padding: 6px 16px; border-radius: 18px 18px 6px 6px; }
.cblk { background: #ff8c1a; color: #fff; font-weight: 700; border-radius: 10px; padding: 8px 10px 14px; width: 330px; box-shadow: 0 4px 0 rgba(0, 0, 0, .35); font-size: 20px; }
.cin { margin: 8px 0 0 22px; background: #1b2550; border-radius: 10px; padding: 8px; min-height: 52px; }
.slot { display: inline-block; min-width: 84px; padding: 3px 12px; border-radius: 18px; background: rgba(0, 0, 0, .3); border: 2px dashed #fff; text-align: center; vertical-align: middle; font-size: 20px; }
.slot.filled { background: #fff; color: #1c2340; border-style: solid; animation: pop .25s; }
.cin .slot { min-width: 220px; border-radius: 10px; }
.cin .slot.filled { background: #4c97ff; color: #fff; }
.blk { border-radius: 10px; padding: 7px 14px; font-weight: 700; font-size: 18px; color: #fff; box-shadow: 0 4px 0 rgba(0, 0, 0, .4); margin: 0 8px 10px 0; }
.blk:active { transform: translateY(2px); }
.blk.num { background: #e9731a; border-radius: 18px; min-width: 74px; }
.blk.act { background: #4c97ff; }
.blk.sel { outline: 3px solid #fff; }
.note { position: absolute; font-size: 34px; color: #ffd54f; animation: floatUp 1s forwards; pointer-events: none; }
/* 場面3 */
.plate { background: #231942; border: 2px solid #8a5be0; border-radius: 12px; padding: 6px 10px; text-align: center; }
.qname { font-size: 26px; font-weight: 700; color: #ffd54f; }
.choice { display: block; width: 100%; margin-top: 10px; text-align: center; }
.choice.right { background: #2fae6b; box-shadow: 0 5px 0 #1b7044; opacity: 1 !important; }
.choice.wrong { background: #b24a4a; box-shadow: 0 5px 0 #6e2a2a; }
.row { border-top: 1px solid #4a5a9a; padding: 5px 0 4px; animation: pop .3s; }
.row b { display: block; font-size: 18px; }
.row span { font-size: 16px; color: #c5d1f5; }
.row em { font-style: normal; font-weight: 700; color: #ffd54f; float: right; font-size: 18px; }
/* 場面4 */
.card { display: block; width: 100%; text-align: left; background: #f4f7ff; color: #1c2340; border-radius: 14px; padding: 10px 14px; box-shadow: 0 5px 0 #8e9cc4; margin-bottom: 14px; }
.card:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 #8e9cc4; }
.card b { display: block; font-size: 22px; }
.card span { font-size: 16px; color: #4a567e; }
.card:disabled { opacity: .4; }
.card.pick { outline: 4px solid #ffd54f; opacity: 1 !important; }
.card.good { background: #c9f7dc; outline: 4px solid #2fae6b; opacity: 1 !important; }
.card.pw b { font-size: 24px; letter-spacing: 1px; }
.ent { font-size: 18px; padding: 1px 8px; border-radius: 6px; display: flex; gap: 8px; }
.ent i { font-style: normal; color: #9fb0e0; width: 26px; text-align: right; flex: none; }
.ent.scan { background: #3a4a8a; }
.ent.hit { background: #d64545; color: #fff; font-weight: 700; animation: pop .3s; }
.ent.hit i { color: #fff; }
/* 結果 */
.stars { font-size: 60px; letter-spacing: 12px; text-align: center; line-height: 1; height: 64px; }
.stars span { display: inline-block; color: #3a4a8a; }
.stars span.on { color: #ffd54f; animation: pop .4s; text-shadow: 0 0 18px #ffb300; }
.total { text-align: center; font-size: 44px; font-weight: 700; color: #fff; line-height: 1.2; }
.rule { background: #f4f7ff; color: #1c2340; border-radius: 14px; padding: 10px 12px; height: 132px; }
.rule b { display: block; font-size: 20px; color: #24459b; margin-bottom: 4px; }
.rule span { font-size: 17px; line-height: 1.4; display: block; }
/* タイトル */
#title { position: absolute; inset: 0; z-index: 40; background: linear-gradient(#0b1030, #25336d); text-align: center; }
#title h1 { margin: 34px 0 0; font-size: 58px; letter-spacing: 4px; color: #ffd54f; text-shadow: 0 5px 0 #7a5a00; }
#title p { margin: 8px 0 0; font-size: 22px; }
#moon { position: absolute; right: 70px; top: 40px; width: 90px; height: 90px; border-radius: 50%; box-shadow: -22px 12px 0 0 #ffe9a3 inset; }
#startBtn { position: absolute; left: 340px; top: 372px; width: 280px; height: 72px; font-size: 30px; border-radius: 20px; background: #ff8a3d; box-shadow: 0 7px 0 #b9541a; animation: pulse 1s infinite; }
#startBtn:active { transform: translateY(4px); box-shadow: 0 3px 0 #b9541a; }
#title .foot { position: absolute; left: 0; width: 960px; top: 492px; font-size: 18px; color: #c5d1f5; }
.float { position: absolute; z-index: 45; font-size: 28px; font-weight: 700; color: #ffd54f; text-shadow: 0 2px 0 #000; pointer-events: none; animation: floatUp .9s forwards; white-space: nowrap; }
@keyframes pulse { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.2); } }
@keyframes hop { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes pop { 0% { transform: scale(.4); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20% { transform: translateX(-10px); } 40% { transform: translateX(10px); } 60% { transform: translateX(-7px); } 80% { transform: translateX(7px); } }
@keyframes rot { to { transform: rotate(360deg); } }
@keyframes wobble { 0%, 100% { transform: rotate(-7deg); } 50% { transform: rotate(7deg); } }
@keyframes jitter { 0%, 100% { transform: translate(0, 0); } 25% { transform: translate(2px, -2px); } 75% { transform: translate(-2px, 2px); } }
@keyframes floatUp { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(-60px); opacity: 0; } }
/* どの画面の大きさでも、960×540 のゲーム全体を縮めて真ん中に表示する */
#fitbox { position: absolute; left: 0; top: 0; width: 960px; height: 540px; transform-origin: 0 0; }
</style>
</head>
<body>
<div id="fitbox">
<div id="stage">
<div id="hud">
<span class="step" id="st1">1 手で開ける</span>
<span class="step" id="st2">2 プログラム</span>
<span class="step" id="st3">3 予想</span>
<span class="step" id="st4">4 守る</span>
<span id="score">★ 0点</span>
<button id="mute" type="button">音 オン</button>
</div>
<div id="talk">
<div id="picoFace"></div>
<div id="talkText"></div>
<button id="next" type="button">次へ</button>
</div>
<div id="main"></div>
<div id="title">
<div id="moon"></div>
<h1>金庫とパスワード</h1>
<p>見習いホワイトハッカー、ミカヅキ博物館を守れ!</p>
<div id="titleArt"></div>
<button id="startBtn" type="button" class="btn">スタート</button>
<div class="foot">ここで使う技を試してよいのは、このゲームの中だけです。</div>
</div>
<canvas id="fx" width="960" height="540"></canvas>
</div>
</div>
<script>
(() => {
// 画面の大きさ(480×360 など)に合わせて、960×540 のゲーム全体を縮めて真ん中に表示する
const box = document.getElementById("fitbox");
const fit = () => {
const w = document.documentElement.clientWidth || window.innerWidth;
const h = document.documentElement.clientHeight || window.innerHeight;
const s = Math.min(w / 960, h / 540);
box.style.transform = "translate(" + ((w - 960 * s) / 2) + "px, " + ((h - 540 * s) / 2) + "px) scale(" + s + ")";
};
window.addEventListener("resize", fit);
fit();
})();
</script>
<script>
(() => {
"use strict";
const $ = (id) => document.getElementById(id);
const stage = $("stage"), main = $("main"), talkText = $("talkText"), nextBtn = $("next"), picoFace = $("picoFace");
const h = (tag, cls, text, parent) => {
const e = document.createElement(tag);
if (cls) e.className = cls;
if (text != null) e.textContent = text;
if (tag === "button") e.type = "button";
if (parent) parent.appendChild(e);
return e;
};
const at = (e, x, y, w) => {
e.style.position = "absolute"; e.style.left = x + "px"; e.style.top = y + "px";
if (w) e.style.width = w + "px";
return e;
};
const pad = (n, len) => String(n).padStart(len, "0");
const fmtJa = (n) => {
if (n >= 1e12) return Math.round(n / 1e12).toLocaleString("ja-JP") + "兆";
if (n >= 1e8) return (n / 1e8 >= 10 ? Math.round(n / 1e8).toLocaleString("ja-JP") : (n / 1e8).toFixed(1)) + "億";
if (n >= 1e4) return Math.round(n / 1e4).toLocaleString("ja-JP") + "万";
return Math.round(n).toLocaleString("ja-JP");
};
// ---------- 音(Web Audio で合成。鳴らなくてもゲームは止まらない) ----------
let ac = null, muted = false;
const initAudio = () => {
try {
if (!ac) { const C = window.AudioContext || window.webkitAudioContext; if (C) ac = new C(); }
if (ac && ac.state === "suspended") { const p = ac.resume(); if (p && p.catch) p.catch(() => {}); }
} catch (e) { ac = null; }
};
const tone = (freq, dur, type, vol, delay, slideTo) => {
if (!ac || muted) return;
try {
const t = ac.currentTime + (delay || 0);
const o = ac.createOscillator(), g = ac.createGain();
o.type = type || "square";
o.frequency.setValueAtTime(freq, t);
if (slideTo) o.frequency.exponentialRampToValueAtTime(slideTo, t + dur);
g.gain.setValueAtTime(0.0001, t);
g.gain.exponentialRampToValueAtTime(vol || 0.08, t + 0.01);
g.gain.exponentialRampToValueAtTime(0.0001, t + dur);
o.connect(g); g.connect(ac.destination);
o.start(t); o.stop(t + dur + 0.03);
} catch (e) { /* 音が出なくても続ける */ }
};
const sClick = () => tone(660, 0.07, "square", 0.06);
const sKey = (d) => tone(420 + d * 45, 0.08, "triangle", 0.1);
const sPick = () => { tone(520, 0.07, "square", 0.06); tone(780, 0.1, "square", 0.06, 0.07); };
const sBad = () => { tone(180, 0.22, "sawtooth", 0.08, 0, 90); };
const sOpen = () => { [523, 659, 784, 1047, 1319].forEach((f, i) => tone(f, 0.16, "square", 0.07, i * 0.08)); tone(1568, 0.5, "triangle", 0.1, 0.4); };
const sLock = () => { tone(140, 0.25, "square", 0.1); tone(100, 0.4, "square", 0.1, 0.18); tone(1200, 0.08, "triangle", 0.08, 0.02); };
const sStar = () => { tone(988, 0.1, "square", 0.07); tone(1319, 0.28, "square", 0.07, 0.1); };
const sWin = () => { [523, 523, 523, 659, 784, 659, 784, 1047].forEach((f, i) => tone(f, 0.18, "square", 0.07, i * 0.13)); };
const sLaugh = () => { [500, 400, 500, 400].forEach((f, i) => tone(f, 0.09, "sawtooth", 0.06, i * 0.1)); };
// ---------- 動きの土台(requestAnimationFrame 1本で回す) ----------
const anims = [];
let scene = 0, last = 0;
const run = (fn) => { const my = scene; anims.push((dt, ts) => (my === scene ? fn(dt, ts) : false)); };
const after = (ms, fn) => { let t = 0; run((dt) => { t += dt * 1000; if (t >= ms) { fn(); return false; } return true; }); };
const fx = $("fx").getContext("2d");
const parts = [];
let fxDirty = false;
const COLORS = ["#ffd54f", "#ff8a3d", "#4fd1e8", "#7ee2a8", "#ff7eb6", "#ffffff"];
const burst = (x, y, n) => {
for (let i = 0; i < n; i++) {
const a = Math.random() * Math.PI * 2, s = 120 + Math.random() * 340;
parts.push({ x, y, vx: Math.cos(a) * s, vy: Math.sin(a) * s - 200, r: Math.random() * 6, vr: (Math.random() - 0.5) * 14, c: COLORS[i % COLORS.length], life: 1.1 + Math.random() * 0.9, s: 6 + Math.random() * 7 });
}
};
// 画面に表示されている位置を、ゲームの中の座標(960×540)になおす(画面に合わせて縮めているため)
const inStage = (el) => {
const r = el.getBoundingClientRect(), s = stage.getBoundingClientRect(), k = 960 / s.width;
return { left: (r.left - s.left) * k, top: (r.top - s.top) * k, width: r.width * k, height: r.height * k };
};
const burstAt = (el, n) => { const r = inStage(el); burst(r.left + r.width / 2, r.top + r.height / 2, n); };
const drawFx = (dt) => {
if (!parts.length && !fxDirty) return;
fx.clearRect(0, 0, 960, 540);
fxDirty = parts.length > 0;
for (let i = parts.length - 1; i >= 0; i--) {
const p = parts[i];
p.life -= dt; p.vy += 700 * dt; p.x += p.vx * dt; p.y += p.vy * dt; p.r += p.vr * dt;
if (p.life <= 0 || p.y > 560) { parts.splice(i, 1); continue; }
fx.save(); fx.translate(p.x, p.y); fx.rotate(p.r); fx.globalAlpha = Math.min(1, p.life * 2);
fx.fillStyle = p.c; fx.fillRect(-p.s / 2, -p.s / 3, p.s, p.s * 0.66); fx.restore();
}
};
const frame = (ts) => {
const dt = Math.min(0.1, last ? (ts - last) / 1000 : 0);
last = ts;
for (let i = anims.length - 1; i >= 0; i--) { if (anims[i](dt, ts) === false) anims.splice(i, 1); }
drawFx(dt);
requestAnimationFrame(frame);
};
requestAnimationFrame(frame);
const floatText = (text, el, color) => {
const r = inStage(el);
const f = h("div", "float", text, stage);
f.style.left = Math.max(10, Math.min(820, r.left + r.width / 2 - 40)) + "px";
f.style.top = Math.max(50, r.top - 10) + "px";
if (color) f.style.color = color;
setTimeout(() => f.remove(), 950);
};
// ---------- 絵(インライン SVG) ----------
const PICO_SVG = '<svg viewBox="0 0 80 80" width="100%" height="100%"><line x1="40" y1="6" x2="40" y2="18" stroke="#1c2340" stroke-width="4"/><circle cx="40" cy="7" r="6" fill="#ffd54f" stroke="#1c2340" stroke-width="3"/><rect x="3" y="34" width="10" height="18" rx="4" fill="#1c2340"/><rect x="67" y="34" width="10" height="18" rx="4" fill="#1c2340"/><rect x="9" y="17" width="62" height="54" rx="20" fill="#4fd1e8" stroke="#1c2340" stroke-width="4"/><rect x="17" y="27" width="46" height="32" rx="13" fill="#effcff"/><circle cx="30" cy="40" r="5" fill="#1c2340"/><circle cx="50" cy="40" r="5" fill="#1c2340"/><circle cx="31.500" cy="38.500" r="1.600" fill="#fff"/><circle cx="51.500" cy="38.500" r="1.600" fill="#fff"/><path d="M32 49 Q40 56 48 49" fill="none" stroke="#1c2340" stroke-width="3" stroke-linecap="round"/><circle cx="23" cy="48" r="3" fill="#ffb3c7"/><circle cx="57" cy="48" r="3" fill="#ffb3c7"/></svg>';
picoFace.innerHTML = PICO_SVG;
const starPts = (cx, cy, R, r) => {
const pts = [];
for (let i = 0; i < 10; i++) { const a = -Math.PI / 2 + i * Math.PI / 5, q = i % 2 ? r : R; pts.push((cx + Math.cos(a) * q).toFixed(1) + "," + (cy + Math.sin(a) * q).toFixed(1)); }
return pts.join(" ");
};
const SAFE_SVG = '<svg viewBox="0 0 300 290">' +
'<rect x="36" y="268" width="44" height="18" rx="4" fill="#161d33"/><rect x="220" y="268" width="44" height="18" rx="4" fill="#161d33"/>' +
'<rect class="body" x="8" y="8" width="284" height="264" rx="20" fill="#5a70a0" stroke="#161d33" stroke-width="6"/>' +
'<rect x="30" y="18" width="240" height="50" rx="8" fill="#0a0f1c" stroke="#161d33" stroke-width="4"/>' +
'<g class="cells"></g><text class="msg" x="150" y="54" text-anchor="middle" font-size="30"></text>' +
'<rect x="40" y="80" width="220" height="176" rx="8" fill="#0f1526"/>' +
'<ellipse cx="150" cy="236" rx="80" ry="14" fill="#c98a12"/><ellipse cx="112" cy="226" rx="26" ry="8" fill="#ffd54f" stroke="#c98a12" stroke-width="3"/><ellipse cx="190" cy="228" rx="26" ry="8" fill="#ffd54f" stroke="#c98a12" stroke-width="3"/><ellipse cx="150" cy="218" rx="26" ry="8" fill="#ffe58a" stroke="#c98a12" stroke-width="3"/>' +
'<polygon points="' + starPts(150, 150, 50, 22) + '" fill="#ffd54f" stroke="#c98a12" stroke-width="4" stroke-linejoin="round"/>' +
'<g class="door"><rect x="40" y="80" width="220" height="176" rx="8" fill="#8ea3cc" stroke="#161d33" stroke-width="5"/>' +
'<rect x="30" y="100" width="16" height="30" rx="3" fill="#161d33"/><rect x="30" y="206" width="16" height="30" rx="3" fill="#161d33"/>' +
'<g class="dial"><circle cx="150" cy="168" r="54" fill="#e6ecf7" stroke="#161d33" stroke-width="5"/>' +
'<rect x="143" y="118" width="14" height="100" rx="6" fill="#161d33"/><rect x="100" y="161" width="100" height="14" rx="6" fill="#161d33"/><circle cx="150" cy="168" r="14" fill="#ffb93d" stroke="#161d33" stroke-width="4"/><circle cx="150" cy="124" r="5" fill="#ff5a5a"/></g></g>' +
'<g class="chain"><line x1="30" y1="90" x2="270" y2="250" stroke="#aab3c7" stroke-width="14" stroke-dasharray="20 8"/><line x1="270" y1="90" x2="30" y2="250" stroke="#aab3c7" stroke-width="14" stroke-dasharray="20 8"/>' +
'<path d="M128 156 v-16 a22 22 0 0 1 44 0 v16" fill="none" stroke="#7a5a00" stroke-width="10"/><rect x="114" y="154" width="72" height="56" rx="10" fill="#ffc533" stroke="#7a5a00" stroke-width="5"/><circle cx="150" cy="176" r="8" fill="#7a5a00"/><rect x="146" y="178" width="8" height="18" rx="3" fill="#7a5a00"/></g>' +
'</svg>';
const makeSafe = (parent, n, width) => {
const el = h("div", "safe", null, parent);
el.style.width = width + "px";
el.innerHTML = SAFE_SVG;
const cellG = el.querySelector(".cells"), msgT = el.querySelector(".msg");
let cells = [];
const api = {
el,
setLen(len) {
const cw = len <= 4 ? 44 : len <= 6 ? 36 : 28, fs = len <= 6 ? 34 : 28;
let s = "";
for (let i = 0; i < len; i++) s += '<text x="' + (150 + (i - (len - 1) / 2) * cw) + '" y="55" text-anchor="middle" font-size="' + fs + '"></text>';
cellG.innerHTML = s;
cells = Array.from(cellG.querySelectorAll("text"));
},
set(str, mode) {
msgT.textContent = "";
cellG.setAttribute("class", "cells " + (mode || ""));
for (let i = 0; i < cells.length; i++) cells[i].textContent = str[i] || "";
},
msg(text, mode) {
for (let i = 0; i < cells.length; i++) cells[i].textContent = "";
msgT.setAttribute("class", "msg " + (mode || ""));
msgT.textContent = text;
},
open() { el.classList.remove("spin"); el.classList.add("open"); },
close() { el.classList.remove("open", "locked", "spin"); },
spin(on) { el.classList.toggle("spin", on); },
lock() { el.classList.remove("spin"); el.classList.add("locked"); },
shake() { el.classList.remove("shake"); void el.offsetWidth; el.classList.add("shake"); },
};
api.setLen(n);
return api;
};
const GACHA_SVG = '<svg viewBox="0 0 200 220">' +
'<line x1="100" y1="8" x2="100" y2="30" stroke="#231942" stroke-width="6"/><circle cx="100" cy="9" r="8" fill="#ff5a5a" stroke="#231942" stroke-width="4"/>' +
'<rect x="12" y="132" width="36" height="16" rx="8" fill="#6b3fc4" stroke="#231942" stroke-width="5"/><rect x="152" y="132" width="36" height="16" rx="8" fill="#6b3fc4" stroke="#231942" stroke-width="5"/>' +
'<path d="M12 128 L2 118 M12 152 L2 162" stroke="#231942" stroke-width="6" stroke-linecap="round"/><path d="M188 128 L198 118 M188 152 L198 162" stroke="#231942" stroke-width="6" stroke-linecap="round"/>' +
'<rect x="64" y="190" width="24" height="26" rx="5" fill="#231942"/><rect x="112" y="190" width="24" height="26" rx="5" fill="#231942"/>' +
'<rect x="50" y="118" width="100" height="78" rx="12" fill="#6b3fc4" stroke="#231942" stroke-width="6"/><circle cx="100" cy="158" r="18" fill="#ffe14f" stroke="#231942" stroke-width="5"/><line x1="100" y1="158" x2="110" y2="146" stroke="#231942" stroke-width="5" stroke-linecap="round"/>' +
'<rect x="36" y="28" width="128" height="94" rx="16" fill="#8a5be0" stroke="#231942" stroke-width="6"/>' +
'<g class="eyesA"><rect x="56" y="56" width="34" height="24" rx="5" fill="#ffe14f" stroke="#231942" stroke-width="4"/><rect x="110" y="56" width="34" height="24" rx="5" fill="#ffe14f" stroke="#231942" stroke-width="4"/><circle cx="76" cy="69" r="6" fill="#231942"/><circle cx="124" cy="69" r="6" fill="#231942"/><line x1="52" y1="44" x2="92" y2="54" stroke="#231942" stroke-width="7" stroke-linecap="round"/><line x1="148" y1="44" x2="108" y2="54" stroke="#231942" stroke-width="7" stroke-linecap="round"/></g>' +
'<g class="eyesX"><path d="M60 56 L88 80 M88 56 L60 80 M112 56 L140 80 M140 56 L112 80" stroke="#231942" stroke-width="7" stroke-linecap="round"/></g>' +
'<rect x="68" y="92" width="64" height="18" rx="4" fill="#fff" stroke="#231942" stroke-width="4"/><path d="M84 92 V110 M100 92 V110 M116 92 V110" stroke="#231942" stroke-width="3"/>' +
'</svg>';
const makeGacha = (parent, width) => {
const el = h("div", "gacha", null, parent);
el.style.width = width + "px";
el.innerHTML = GACHA_SVG;
return { el, set(state) { el.className = "gacha " + (state || ""); } };
};
// ---------- 進行・点数 ----------
let score = 0, misses = 0, startMs = 0, started = false, keyHandler = null, nextCb = null;
let SECN = 0, SEC = "000";
const newSecret = () => { SECN = 400 + Math.floor(Math.random() * 500); SEC = pad(SECN, 3); };
const scoreEl = $("score");
const addScore = (n, el) => {
score += n;
scoreEl.textContent = "★ " + score + "点";
if (el) floatText("+" + n + "点", el);
};
const miss = () => { misses++; };
const setStage = (n) => {
for (let i = 1; i <= 4; i++) $("st" + i).className = "step" + (i < n ? " done" : i === n ? " now" : "");
};
const newScene = (n) => { scene++; main.innerHTML = ""; keyHandler = null; setStage(n); };
const say = (lines, label, cb) => {
talkText.textContent = Array.isArray(lines) ? lines.join("\n") : lines;
picoFace.classList.remove("hop"); void picoFace.offsetWidth; picoFace.classList.add("hop");
if (label) { nextBtn.textContent = label + " ▶"; nextBtn.style.visibility = "visible"; nextCb = cb; }
else { nextBtn.style.visibility = "hidden"; nextCb = null; }
};
const seq = (list, done) => {
let i = 0;
const step = () => { if (i >= list.length) { done(); return; } const cur = list[i++]; say(cur, "次へ", step); };
step();
};
nextBtn.addEventListener("click", () => {
const cb = nextCb;
if (!cb) return;
nextCb = null; nextBtn.style.visibility = "hidden";
sClick(); cb();
});
$("mute").addEventListener("click", () => {
muted = !muted;
$("mute").textContent = muted ? "音 オフ" : "音 オン";
if (!muted) { initAudio(); sClick(); }
});
document.addEventListener("keydown", (e) => { if (started && keyHandler) keyHandler(e); });
// ---------- はじまり ----------
const intro = () => {
newScene(0);
const safe = makeSafe(main, 3, 270); at(safe.el, 345, 60);
safe.set("???");
seq([
["ぼくはピコ。ここはミカヅキ博物館です。", "きみは見習いホワイトハッカーですね。"],
["ドロボウより先に、金庫の弱いところを見つけて直す。", "それが今日の任務です。"],
], stage1);
};
// ---------- 場面1:手で開ける ----------
const stage1 = () => {
newScene(1);
const safe = makeSafe(main, 3, 280); at(safe.el, 110, 4);
safe.set("___");
const info = at(h("div", "panel", null, main), 60, 286, 400);
const cnt = h("div", "big", "試した数 0 / 1000通り", info);
const chips = h("div", "chips", null, info);
const pace = h("div", "lbl", "", info);
const keys = at(h("div", "keys", null, main), 580, 40);
let cur = "", tries = 0, busy = false;
const t0 = performance.now();
const paceMin = () => Math.max(1, Math.round((performance.now() - t0) / 1000 / Math.max(1, tries) * 1000 / 60));
const finish = (lucky) => {
busy = true;
if (lucky) {
say(["すごい運です! でも、いつも当たるとはかぎりません。", "かならず開ける方法を、コンピューターで試しましょう。"], "プログラムを組む", stage2);
} else {
addScore(50, cnt);
say(["手で1000通りは大変です。このペースだと約" + paceMin() + "分かかります。", "コンピューターにやらせてみましょう。"], "プログラムを組む", stage2);
}
};
const check = () => {
tries++;
cnt.textContent = "試した数 " + tries + " / 1000通り";
if (cur === SEC) {
safe.set(cur, "ok"); safe.open(); sOpen(); burstAt(safe.el, 80); addScore(300, safe.el);
finish(true);
return;
}
safe.set(cur, "bad"); safe.shake(); sBad();
h("span", "chip", cur + " ×", chips);
if (tries >= 2) pace.textContent = "このペースだと、全部試すのに約" + paceMin() + "分";
after(480, () => {
cur = ""; safe.set("___");
if (tries >= 4) finish(false); else busy = false;
});
};
const press = (d) => {
if (busy || cur.length >= 3) return;
cur += d; sKey(Number(d));
safe.set(cur.padEnd(3, "_"));
if (cur.length === 3) { busy = true; after(220, check); }
};
const erase = () => { if (busy) return; cur = cur.slice(0, -1); safe.set(cur.padEnd(3, "_")); sClick(); };
["1", "2", "3", "4", "5", "6", "7", "8", "9"].forEach((d) => h("button", "key", d, keys).addEventListener("click", () => press(d)));
h("button", "key sub", "1つ消す", keys).addEventListener("click", erase);
h("button", "key", "0", keys).addEventListener("click", () => press("0"));
keyHandler = (e) => {
if (e.key >= "0" && e.key <= "9" && e.key.length === 1) press(e.key);
else if (e.key === "Backspace") erase();
};
say(["まずは手で開けてみましょう。番号は3けたです。", "数字を3つ押すと、その番号を試します。"]);
};
// ---------- 場面2:プログラムで開ける ----------
const stage2 = () => {
newScene(2);
const board = at(h("div", "panel", null, main), 24, 2, 540);
board.style.height = "398px";
h("div", "hat", "▶ 実行が押されたとき", board);
const c = h("div", "cblk", null, board);
const line = h("div", null, null, c);
const slotN = h("span", "slot", "?", line);
line.appendChild(document.createTextNode(" 回 くりかえす"));
const cin = h("div", "cin", null, c);
const slotA = h("span", "slot", "?", cin);
h("div", "lbl", "ブロックを押すと、上の「?」にはまります", board).style.margin = "12px 0 8px";
const rowN = h("div", null, null, board), rowA = h("div", null, null, board);
const runBtn = h("button", "btn go", "▶ 実行", board);
runBtn.style.marginTop = "4px"; runBtn.style.width = "170px";
runBtn.disabled = true;
const safe = makeSafe(main, 3, 270); at(safe.el, 628, 0);
safe.set("000");
const read = at(h("div", "panel", null, main), 590, 272, 346);
const rCnt = h("div", "big", "試した回数 0回", read);
const rSpd = h("div", "big yel", "速さ —", read);
const NUMS = [10, 100, 1000];
const ACTS = [{ id: "next", t: "次の番号を試す" }, { id: "same", t: "同じ番号を試す" }, { id: "dance", t: "おどる" }];
let selN = 0, selA = null, running = false, fails = 0;
const blocks = [];
const refresh = () => { runBtn.disabled = running || !selN || !selA; blocks.forEach((b) => { b.disabled = running; }); };
NUMS.forEach((n) => {
const b = h("button", "blk num", String(n), rowN); blocks.push(b);
b.addEventListener("click", () => { selN = n; slotN.textContent = String(n); slotN.className = "slot"; void slotN.offsetWidth; slotN.className = "slot filled"; sPick(); refresh(); });
});
ACTS.forEach((a) => {
const b = h("button", "blk act", a.t, rowA); blocks.push(b);
b.addEventListener("click", () => { selA = a; slotA.textContent = a.t; slotA.className = "slot"; void slotA.offsetWidth; slotA.className = "slot filled"; sPick(); refresh(); });
});
const fail = (lines) => {
fails++; miss(); safe.spin(false); sBad(); safe.shake();
running = false; refresh();
say(lines);
};
const success = (sec) => {
safe.set(SEC, "ok"); safe.open(); sOpen(); burstAt(safe.el, 120);
addScore(Math.max(80, 200 - fails * 40), safe.el);
say([(SECN + 1) + "回目で開きました! かかった時間は" + sec.toFixed(1) + "秒です。", "全部の番号を順番に試す。これが「総当たり」です。"], "次へ", () => {
say(["今のは、目で見えるようにゆっくり回しました。", "本気を出すと、1秒に何回試せるでしょうか?"], "本気モード!", turbo);
});
};
const turbo = () => {
safe.close(); safe.spin(true);
rSpd.textContent = "速さ はかっています…";
let count = 0, n = 0, hits = 0, f = 0;
const t0 = performance.now();
run(() => {
const s = performance.now();
// 1フレームに5ミリ秒だけ、本当に番号を試す(長く回しつづけない)
while (performance.now() - s < 5) {
for (let k = 0; k < 500; k++) { if (n === SECN) hits++; n = n === 999 ? 0 : n + 1; }
count += 500;
}
f++;
safe.set(pad(Math.floor(Math.random() * 1000), 3));
rCnt.textContent = "試した回数 " + count.toLocaleString("ja-JP") + "回";
if (f % 3 === 0) tone(600 + (f % 12) * 90, 0.03, "square", 0.04);
const el = (performance.now() - t0) / 1000;
if (el < 0.9) return true;
const rate = count / el;
safe.spin(false); safe.set(SEC, "ok"); safe.open(); sOpen(); burstAt(safe.el, 160);
rSpd.textContent = "速さ 1秒に約" + fmtJa(rate) + "回";
addScore(50, read);
say(["このコンピューターは、1秒に約" + fmtJa(rate) + "回も試せました。", "金庫は" + hits.toLocaleString("ja-JP") + "回も開いています。3けたは弱すぎます。"], "次へ", stage3);
return false;
});
};
runBtn.addEventListener("click", () => {
if (running || !selN || !selA) return;
running = true; refresh(); sClick();
safe.close(); say(["プログラムを実行しています…"]);
const N = selN, act = selA.id;
if (act === "dance") {
let t = 0, k = 0;
rSpd.textContent = "速さ —";
run((dt) => {
t += dt;
const want = Math.min(8, Math.floor(t / 0.16));
while (k < want) {
k++;
const nt = at(h("div", "note", k % 2 ? "♪" : "♫", main), 640 + Math.random() * 230, 60 + Math.random() * 120);
setTimeout(() => nt.remove(), 1000);
tone([523, 659, 784, 659][k % 4], 0.12, "triangle", 0.09);
safe.shake();
}
rCnt.textContent = "おどった回数 " + Math.min(N, Math.floor(N * t / 1.4)) + "回";
if (t < 1.5) return true;
fail(["楽しいおどりでした! でも、金庫は開きません。", "番号を試す命令を選びましょう。"]);
return false;
});
return;
}
const limit = act === "next" && N === 1000 ? SECN : N - 1;
const rate = N === 1000 ? 250 : N / 1.2;
let t = 0, beep = 0;
safe.spin(true);
rSpd.textContent = "速さ 1秒に" + Math.round(rate) + "回";
run((dt) => {
t += dt; beep += dt;
const i = Math.min(limit, Math.floor(t * rate));
safe.set(act === "same" ? "000" : pad(i, 3));
rCnt.textContent = "試した回数 " + (i + 1) + "回";
if (beep > 0.05) { beep = 0; tone(300 + (i / Math.max(1, limit)) * 900, 0.03, "square", 0.04); }
if (i < limit) return true;
if (act === "same") fail(["ずっと「000」だけを試していました。", "番号を1つずつ進める命令が必要です。"]);
else if (N < 1000) fail([N + "回では足りませんでした。" + pad(N - 1, 3) + "で止まっています。", "3けたの番号は、000から999まで何通りありますか?"]);
else success(t);
return false;
});
});
say(["総当たりのプログラムを組みましょう。", "ブロックを2つ選んで「実行」を押してください。"]);
};
// ---------- 場面3:予想 ----------
const DIGITS = "0123456789", ALNUM = "abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789";
const rnd = (n, alpha) => { const src = alpha ? ALNUM : DIGITS; let s = ""; for (let i = 0; i < n; i++) s += src[Math.floor(Math.random() * src.length)]; return s; };
const LOCKS = [
{ name: "4けたの数字", n: 4, combos: "1万通り", total: 1e4, time: "0.01秒", dur: 0.5, clock: (p) => "時間 " + (0.01 * p).toFixed(3) + "秒" },
{ name: "6けたの数字", n: 6, combos: "100万通り", total: 1e6, time: "約1秒", dur: 1.0, clock: (p) => "時間 " + p.toFixed(2) + "秒",
choices: ["約1分", "約1秒", "約1時間"], ok: 1, exp: ["約1秒でした。けたを2つ増やすと、100倍になります。", "それでも、ガチャロボにはまだ短いようです。"] },
{ name: "8けたの数字", n: 8, combos: "1億通り", total: 1e8, time: "約2分", dur: 2.0, clock: (p) => "早送り ▶▶ " + Math.round(100 * p) + "秒",
choices: ["約2分", "約2日", "約2年"], ok: 0, exp: ["100秒、つまり約2分でした。", "数字だけだと、8けたでも安心できません。"] },
{ name: "英数字8文字", n: 8, alpha: true, combos: "約218兆通り", total: 218e12, time: "約7年", dur: 3.0, clock: (p) => "早送り ▶▶ " + Math.max(1, Math.ceil(7 * p)) + "年目", holds: true,
choices: ["約7時間", "約7日", "約7年"], ok: 2, exp: ["約7年! ガチャロボは、とちゅうでさびて止まりました。", "文字の種類を増やすと、通りの数が一気に増えます。"] },
];
const stage3 = () => {
newScene(3);
const robo = makeGacha(main, 120); at(robo.el, 16, 2);
const plate = at(h("div", "plate", null, main), 146, 24, 190);
h("div", "lbl", "ガチャロボの速さ", plate);
h("div", "big yel", "1秒に100万回", plate);
const safe = makeSafe(main, 4, 236); at(safe.el, 62, 150);
safe.set("0000");
const qBox = at(h("div", null, null, main), 350, 0, 285);
const qName = h("div", "qname", "", qBox), qSub = h("div", "big", "", qBox);
const chWrap = h("div", null, null, qBox);
const read = at(h("div", "panel", null, main), 350, 300, 285);
const rCnt = h("div", "big", "試した回数 0回", read), rClk = h("div", "big yel", "時間 0秒", read);
const board = at(h("div", "panel", null, main), 652, 0, 296);
h("div", "big", "記録ボード", board);
const addRow = (L) => {
const r = h("div", "row", null, board);
h("em", null, L.time, r); h("b", null, L.name, r); h("span", null, L.combos, r);
};
addRow({ name: "3けたの数字", combos: "1000通り", time: "0.001秒" });
const sim = (L, done) => {
safe.close(); safe.setLen(L.n); safe.spin(true); robo.set("attack");
let t = 0, f = 0;
run((dt) => {
t += dt; f++;
const p = Math.min(1, t / L.dur);
if (f % 2 === 0) safe.set(rnd(L.n, L.alpha));
rCnt.textContent = "試した回数 " + fmtJa(L.total * p) + "回";
rClk.textContent = L.clock(p);
if (f % 4 === 0) tone(300 + p * 900, 0.03, "square", 0.04);
if (p < 1) return true;
safe.spin(false);
if (L.holds) { robo.set("dizzy"); safe.msg("開かない!", "ok"); sLock(); }
else { robo.set("laugh"); safe.set(rnd(L.n, false), "bad"); safe.open(); sLaugh(); after(900, () => robo.set("")); }
addRow(L);
done();
return false;
});
};
const ask = (idx) => {
if (idx >= LOCKS.length) {
say(["けたを長く、文字の種類を多く。", "これが、総当たりに強いパスワードです。"], "次へ", stage4);
return;
}
const L = LOCKS[idx];
robo.set(""); safe.close(); safe.setLen(L.n); safe.set("_".repeat(L.n));
qName.textContent = L.name; qSub.textContent = L.combos;
rCnt.textContent = "試した回数 0回"; rClk.textContent = "時間 0秒";
chWrap.innerHTML = "";
if (!L.choices) {
say(["金庫を4けたにしました。1万通りです。", "ガチャロボが開けるまでの時間を見てみましょう。"], "スタート", () => {
say(["ガチャロボが総当たりをしています…"]);
sim(L, () => say(["0.01秒! 4けたでも、あっという間に開きました。", "ここからは、かかる時間を予想してください。"], "次へ", () => ask(idx + 1)));
});
return;
}
say(["今度は「" + L.name + "」。" + L.combos + "です。", "全部試すのに、どれくらいかかるでしょう?"]);
const btns = L.choices.map((c, i) => {
const b = h("button", "btn choice", c, chWrap);
b.addEventListener("click", () => {
btns.forEach((x) => { x.disabled = true; });
b.classList.add("pick"); sPick();
say(["ガチャロボが総当たりをしています…"]);
sim(L, () => {
const ok = i === L.ok;
btns[L.ok].classList.add("right");
if (ok) { sStar(); addScore(100, b); burstAt(b, 40); } else { b.classList.add("wrong"); miss(); addScore(20, b); }
say([(ok ? "正解! " : "ざんねん! ") + L.exp[0], L.exp[1]], "次へ", () => ask(idx + 1));
});
});
return b;
});
};
seq([["ここからは、敵ロボの「ガチャロボ」が相手です。", "ガチャロボは、1秒に100万回も番号を試せます。"]], () => ask(0));
};
// ---------- 場面4:守る ----------
const stage4 = () => {
newScene(4);
const safe = makeSafe(main, 3, 260); at(safe.el, 40, 40);
safe.set("___");
const wrap = at(h("div", null, null, main), 345, 30, 300);
const robo = makeGacha(main, 180); at(robo.el, 720, 20);
const bub = at(h("div", "bubble", "ガチャチャ! 総当たりで開けてやる!", main), 680, 232, 262);
const PARTS = [
{ id: "buzz", t: "まちがえるたびにブザー", s: "ビーッと大きな音が鳴る" },
{ id: "lock", t: "3回まちがえたらロック", s: "それ以上は試せなくなる" },
{ id: "gold", t: "金庫を金色にぬる", s: "ピカピカで強そうに見える" },
];
let fails = 0;
const cards = PARTS.map((P) => {
const b = h("button", "card", null, wrap);
h("b", null, P.t, b); h("span", null, P.s, b);
b.addEventListener("click", () => attack(P, b));
return b;
});
const retry = (b) => {
safe.close(); safe.el.classList.remove("golden"); safe.set("___"); robo.set("");
bub.textContent = "ガチャチャ! もう1回だ!";
b.classList.remove("pick");
cards.forEach((x) => { x.disabled = x === b || x.dataset.used === "1"; });
b.dataset.used = "1";
say(["もう一度、パーツを選んでください。", "試す回数をへらせるのは、どれでしょう?"]);
};
const attack = (P, b) => {
cards.forEach((x) => { x.disabled = true; });
b.classList.add("pick"); sPick();
say(["ガチャロボが総当たりをしています…"]);
robo.set("attack"); bub.textContent = "000から順番に試すぞ!";
if (P.id === "gold") safe.el.classList.add("golden");
if (P.id === "lock") {
[0, 1, 2].forEach((k) => after(500 + k * 650, () => { safe.set(pad(k, 3), "bad"); safe.shake(); sBad(); }));
after(2500, () => {
safe.lock(); safe.msg("ロック", "bad"); sLock(); robo.set("dizzy");
bub.textContent = "ガガ…あと997通りも…";
b.classList.add("good"); burstAt(safe.el, 140);
addScore(Math.max(50, 150 - fails * 50), safe.el);
say(["3回でロック! 残りの997通りは、もう試せません。", "「何回も試させない」は、とても強い守り方です。"], "次へ", stage4b);
});
return;
}
let t = 0, beep = 0;
safe.spin(true);
run((dt) => {
t += dt; beep += dt;
const i = Math.min(SECN, Math.floor(t * 500));
safe.set(pad(i, 3));
if (beep > 0.09) { beep = 0; if (P.id === "buzz") tone(170, 0.07, "sawtooth", 0.07); else tone(300 + i, 0.03, "square", 0.04); }
if (i < SECN) return true;
safe.set(SEC, "bad"); safe.open(); sLaugh(); robo.set("laugh");
bub.textContent = "ガチャチャ! 開いたぞ!";
fails++; miss();
say(P.id === "buzz"
? ["ブザーは鳴りましたが、ガチャロボは止まりません。", "全部の番号を試されてしまいました。"]
: ["ピカピカになりましたが、強さは同じでした。", "見た目では、総当たりを止められません。"], "選び直す", () => retry(b));
return false;
});
};
say(["今度は守る番です。金庫は3けたのままにします。", "総当たりを止めるパーツを、1つ選んでください。"]);
};
const LIST = ["123456", "password", "123456789", "qwerty", "111111", "abc123", "iloveyou", "P@ssw0rd", "同じ文字のくりかえし", "名前(人・ペット・会社)", "誕生日の数字"];
const ROUNDS = [
{ cards: [
{ t: "123456", s: "数字を順番に", hit: 1, why: ["リストの1番目でした。1回目で当てられます。", "これでは、ロックがあっても守れません。"] },
{ t: "password", s: "英語で「パスワード」", hit: 2, why: ["リストの2番目でした。2回目で当てられます。", "これでは、ロックがあっても守れません。"] },
{ t: "nk5Tw9qZ", s: "でたらめな8文字", hit: 0 }],
ok: ["リストにありません! でたらめな8文字は強いです。", "総当たりに切りかえても、何年もかかります。"] },
{ cards: [
{ t: "sora-kujira-pan-27", s: "関係のない言葉3つと数字", hit: 0 },
{ t: "mikazuki", s: "博物館の名前", hit: 10, why: ["名前は、まっ先に予想されます。", "自分や家族、ペットの名前も同じです。"] },
{ t: "19750401", s: "館長の誕生日", hit: 11, why: ["誕生日は、調べれば分かってしまいます。", "8けたの数字は、総当たりでも約2分でした。"] }],
ok: ["リストにありません! 18文字もあるので総当たりも無理です。", "言葉をつなげると、長くても覚えやすくなります。"] },
{ cards: [
{ t: "P@ssw0rd", s: "記号と数字も入っている", hit: 8, why: ["強そうに見えて、リストの8番目でした。", "よくある文字の入れかえは、ロボも知っています。"] },
{ t: "Yuki7-odoru-Tako", s: "長くて、いろいろ混ざっている", hit: 0 },
{ t: "aaaaaaaaaaaa", s: "12文字もあって長い", hit: 9, why: ["長くても、同じ文字だけではすぐ当てられます。", "長さと、予想されにくさの両方が必要です。"] }],
ok: ["守りきりました! ガチャロボは降参です。", "長くて、よく使われていないものが強いパスワードです。"] },
];
const stage4b = () => {
newScene(4);
const listP = at(h("div", "panel", null, main), 20, 2, 300);
h("div", "big", "ガチャロボのリスト", listP);
h("div", "lbl", "よく使われるパスワード", listP);
const ents = LIST.map((t, i) => { const e = h("div", "ent", null, listP); h("i", null, String(i + 1), e); h("span", null, t, e); return e; });
const wrap = at(h("div", null, null, main), 338, 4, 330);
const rTitle = h("div", "qname", "", wrap);
rTitle.style.marginBottom = "8px";
const cardBox = h("div", null, null, wrap);
const safe = makeSafe(main, 8, 200); at(safe.el, 716, 0);
const robo = makeGacha(main, 120); at(robo.el, 690, 196);
const bub = at(h("div", "bubble", "リストの上から試すぞ!", main), 812, 214, 138);
bub.style.fontSize = "16px";
const round = (r) => {
if (r >= ROUNDS.length) { result(); return; }
const R = ROUNDS[r];
let wrongs = 0;
rTitle.textContent = "第" + (r + 1) + "回戦 (全3回)";
cardBox.innerHTML = "";
const reset = () => {
ents.forEach((e) => { e.className = "ent"; });
safe.close(); safe.set("********"); robo.set(""); bub.textContent = "リストの上から試すぞ!";
};
reset();
const cards = R.cards.map((C) => {
const b = h("button", "card pw", null, cardBox);
h("b", null, C.t, b); h("span", null, C.s, b);
b.addEventListener("click", () => {
cards.forEach((x) => { x.disabled = true; });
b.classList.add("pick"); sPick(); robo.set("attack");
say(["ガチャロボがリストを上から試しています…"]);
let k = 0, t = 0;
run((dt) => {
t += dt;
if (t < 0.13) return true;
t = 0;
if (k > 0) ents[k - 1].className = "ent";
if (k >= LIST.length) {
robo.set("dizzy"); bub.textContent = "リストにない…\n何年もかかる…";
safe.msg("守った!", "ok"); sStar(); sLock();
b.classList.add("good"); burstAt(b, 90);
addScore(wrongs === 0 ? 100 : wrongs === 1 ? 50 : 20, b);
say(R.ok, r === ROUNDS.length - 1 ? "結果を見る" : "次へ", () => round(r + 1));
return false;
}
ents[k].className = "ent scan"; tone(500 + k * 40, 0.04, "square", 0.05);
k++;
if (k === C.hit) {
ents[k - 1].className = "ent hit";
safe.set(C.t.slice(0, 8).padEnd(8, " "), "bad"); safe.open(); sBad(); sLaugh(); robo.set("laugh");
bub.textContent = k + "番目で当たり! ガチャチャ!";
wrongs++; miss();
say(C.why, "選び直す", () => {
reset(); b.classList.remove("pick"); b.dataset.used = "1";
cards.forEach((x) => { x.disabled = x.dataset.used === "1"; });
say(["もう一度、パスワードを選んでください。", "リストにないのは、どれでしょう?"]);
});
return false;
}
return true;
});
});
return b;
});
say(["金庫のパスワードを、3つの中から選んでください。", "リストにあると、すぐに当てられてしまいます。"]);
};
seq([["ガチャロボは作戦を変えました。次の金庫は文字で開きます。", "「よく使われるパスワード」のリストを、上から試す作戦です。"]], () => round(0));
};
// ---------- 結果 ----------
const result = () => {
newScene(5);
const sec = Math.round((performance.now() - startMs) / 1000);
const bonus = Math.max(0, 300 - Math.floor(Math.max(0, sec - 300) / 2));
const stars = misses === 0 ? 3 : misses <= 2 ? 2 : 1;
const starBox = at(h("div", "stars", null, main), 0, 0, 960);
const sp = [0, 1, 2].map(() => h("span", null, "★", starBox));
const total = at(h("div", "total", "", main), 0, 66, 960);
const detail = at(h("div", "big", "", main), 0, 122, 960);
detail.style.textAlign = "center";
detail.textContent = "まちがい " + misses + "回 / タイム " + Math.floor(sec / 60) + "分" + (sec % 60) + "秒 / タイムボーナス +" + bonus + "点";
const RULES = [
["1 長く、種類を多く", "数字だけにしないで、英字や記号も混ぜて長くする。"],
["2 何回も試させない", "3回まちがえたらロック。総当たりを止められる。"],
["3 よくあるものは使わない", "123456、名前、誕生日は、まっ先に試される。"],
];
RULES.forEach((r, i) => { const d = at(h("div", "rule", null, main), 24 + i * 308, 162, 296); h("b", null, r[0], d); h("span", null, r[1], d); });
const note = at(h("div", "lbl", "総当たりを試してよいのは、このゲームの中だけです。\nここに出てきたパスワードは、本物には使わないでください。", main), 24, 306, 620);
note.style.lineHeight = "1.5"; note.style.whiteSpace = "pre-line";
const again = at(h("button", "btn go", "もう一度遊ぶ", main), 700, 308, 230);
again.style.height = "64px";
again.addEventListener("click", () => { sClick(); begin(); });
const finalScore = score + bonus;
total.textContent = score + "点";
sp.forEach((s, i) => { if (i < stars) after(300 + i * 350, () => { s.className = "on"; sStar(); }); });
after(1500, () => {
score = finalScore; scoreEl.textContent = "★ " + score + "点";
total.textContent = finalScore + "点";
sWin(); burst(480, 200, 200);
});
say(["任務クリアです! 博物館の金庫は強くなりました。", "3つの守り方を、自分のパスワードにも使ってください。"]);
};
const begin = () => {
score = 0; misses = 0; startMs = performance.now(); newSecret();
scoreEl.textContent = "★ 0点";
intro();
};
// タイトルの絵
const art = $("titleArt");
const tSafe = makeSafe(art, 3, 190); at(tSafe.el, 385, 170);
tSafe.set("???");
const tPico = at(h("div", null, null, art), 250, 250, 110); tPico.innerHTML = PICO_SVG; tPico.style.height = "110px"; tPico.style.animation = "hop 1.2s infinite";
const tRobo = makeGacha(art, 130); at(tRobo.el, 600, 215); tRobo.set("attack");
nextBtn.style.visibility = "hidden";
setStage(0);
$("startBtn").addEventListener("click", () => {
initAudio();
started = true;
$("title").style.display = "none";
sOpen();
begin();
});
})();
</script>
</body>
</html>