Difficulty picker (Easy/Normal/Hard) and a balance pass
Difficulty: - TD.DIFFICULTIES (starting credits, lives, enemy hp/shield, kill reward), validated create-room / newgame option, state carries it; solo menu picker and co-op lobby picker (44px segmented control, reachable on every layout), HUD/room/end-screen labels, best-wave record per map AND difficulty (Normal keeps the legacy key), Play again keeps the running game's difficulty for host and guest Balance (12 bot runs, deterministic, 48/48 games replay identically in QA): - Normal ~71% bot wins at wave 30 (was 94%), Easy 100%, Hard 25% on open - credits tamed: reward growth 3% -> 2% per wave, clear bonus 10+2n -> 10+n, hp scaling eased, Rootkit pays 60 (was 100) but is tougher, flyers slower; unspent credits at wave 30: 1309 -> 335 - IDS Sniper is now a slow heavy hitter (essential, no longer sufficient: IDS-only dies by wave 7); Mortar, Arc and Filter buffed - Orbital Uplink price step per owned unit 30% (buy and upgrade) - remaining imbalances documented in docs/BALANCE.md Tests: difficulty (19) and balance (8) unit suites, 14-difficulty e2e, layout matrix reachability of the picker. 156 unit tests, 17 e2e scenarios. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tb8pW2KAN4oFkh1aK1BfD8
This commit is contained in:
parent
28502984ec
commit
b4ae6cb57d
19 changed files with 1348 additions and 156 deletions
|
|
@ -35,7 +35,7 @@
|
|||
bounds: 'Out of bounds', obstacle: 'That node is dead. Pick another cell', occupied: 'Something is already there', spawn: "Can't build on a gateway",
|
||||
core: "Can't build on the server", monster: 'A packet is in the way', blocks: 'That would seal the route. Leave a path!', gold: 'Not enough credits',
|
||||
over: 'The game is over', no_tower: 'That tower no longer exists', max: 'Already at max level', not_host: 'Only the host can do that',
|
||||
bad_map: 'Unknown map', bad_type: 'Unknown tower', bad_cmd: 'Invalid command', not_won: 'Nothing to continue',
|
||||
bad_map: 'Unknown map', bad_difficulty: 'Unknown difficulty', bad_type: 'Unknown tower', bad_cmd: 'Invalid command', not_won: 'Nothing to continue',
|
||||
};
|
||||
const MODE_NAMES = { first: 'First', last: 'Last', strong: 'Strongest', close: 'Closest' };
|
||||
|
||||
|
|
@ -43,6 +43,7 @@
|
|||
const app = {
|
||||
ctrl: null, renderer: null, screen: 'menu', inGame: false,
|
||||
mapId: store.get('nw.map', 'open'),
|
||||
difficulty: 'normal', // the player's pick for the NEXT game (the running game's is ctrl.view.difficulty); loaded below
|
||||
selType: null, selTower: 0,
|
||||
hover: null, pending: null, preview: null, valid: true, previewDirty: true, lastPreviewAt: 0,
|
||||
zoomed: false, last: {}, names: {}, started: false, lastBossCheck: 0, bossMusic: false,
|
||||
|
|
@ -54,6 +55,7 @@
|
|||
const renderer = new NW.Renderer(canvas);
|
||||
app.renderer = renderer;
|
||||
if (!TD.MAPS[app.mapId]) app.mapId = 'open';
|
||||
{ const d = store.get('nw.difficulty', 'normal'); app.difficulty = TD.isDifficulty(d) ? d : 'normal'; } // (a stored value that is not a difficulty any more is normal)
|
||||
|
||||
// ------------------------------------------------------------------ small UI helpers
|
||||
let lastToast = '', lastToastAt = 0;
|
||||
|
|
@ -149,6 +151,7 @@
|
|||
ctrl.on('newgame', () => {
|
||||
resetSelection(); app.endShown = false; app.last.state = 'playing'; adoptBoard(); $('end').hidden = true;
|
||||
app.bossMusic = false; if (app.inGame) Audio.music('battle'); // a new game starts its music on every client, not only on the one that pressed Play again (code-5)
|
||||
if (ctrl.kind === 'remote') renderPlayers(); // (the room header names the difficulty, which a new game may have changed)
|
||||
});
|
||||
adoptBoard(true);
|
||||
}
|
||||
|
|
@ -171,7 +174,7 @@
|
|||
cancelPending(); // a co-op join that is still connecting must not take this game over (code-3)
|
||||
leaveRemote(true);
|
||||
app.mapId = mapId; store.set('nw.map', mapId);
|
||||
const c = new NW.LocalController({ map: mapId });
|
||||
const c = new NW.LocalController({ map: mapId, difficulty: app.difficulty });
|
||||
useController(c);
|
||||
app.inGame = true; app.started = true; app.endShown = false; app.last = {};
|
||||
resetSelection(); setScreen('playing'); showOverlay(null);
|
||||
|
|
@ -428,14 +431,15 @@
|
|||
|
||||
function renderWavePanel(view) {
|
||||
const n = view.wave + 1;
|
||||
const key = n + ':' + view.state;
|
||||
const dif = viewDifficulty(view);
|
||||
const key = n + ':' + view.state + ':' + dif;
|
||||
if (app.last.waveKey === key) return;
|
||||
app.last.waveKey = key;
|
||||
const box = $('nextwave');
|
||||
if (view.state !== 'playing') { box.textContent = ''; return; }
|
||||
if (n % 10 === 9 || n % 10 === 0) Audio.preload('boss'); // the boss theme is fetched a wave or two ahead, so it starts with the boss instead of seconds later (code-12)
|
||||
const sum = TD.waveSummary(n);
|
||||
let html = '<div class="panel"><h4>Next · wave ' + n + '</h4><div class="wv">';
|
||||
let html = '<div class="panel"><h4>Next · wave ' + n + '<span class="dtag" data-d="' + dif + '" title="Difficulty">' + esc(diffName(dif)) + '</span></h4><div class="wv">';
|
||||
let air = false;
|
||||
for (const g of sum) {
|
||||
const d = TD.ENEMIES[g.k];
|
||||
|
|
@ -467,7 +471,8 @@
|
|||
const ctrl = app.ctrl, box = $('players');
|
||||
if (!ctrl || ctrl.kind !== 'remote') { box.hidden = true; return; }
|
||||
box.hidden = false;
|
||||
let html = '<div class="panel"><h4>Room ' + esc(ctrl.room || '') + ' <span id="plPing" class="muted"></span></h4>'; // (every server string is escaped before it goes into HTML, code-28)
|
||||
const dif = viewDifficulty(ctrl.view);
|
||||
let html = '<div class="panel"><h4>Room ' + esc(ctrl.room || '') + '<span class="dtag" data-d="' + dif + '" title="Difficulty">' + esc(diffName(dif)) + '</span> <span id="plPing" class="muted"></span></h4>'; // (every server string is escaped before it goes into HTML, code-28)
|
||||
for (const p of ctrl.players) {
|
||||
html += '<div class="pl"><span class="dot" style="background:' + slotColor(p.slot) + '"></span><span class="pn"></span>' +
|
||||
(ctrl.you && p.pid === ctrl.you.pid ? '<span class="you">(you)</span>' : '') + (p.host ? '<span class="you">host</span>' : '') + (p.online ? '' : '<span class="off">offline</span>') + '</div>';
|
||||
|
|
@ -551,11 +556,12 @@
|
|||
const won = view.state === 'won';
|
||||
$('endTitle').textContent = won ? 'Server secured!' : 'Breach!';
|
||||
$('endTitle').style.color = won ? 'var(--green)' : 'var(--red)';
|
||||
const best = store.get('nw.best.' + ctrl.board.mapId, 0);
|
||||
if (view.wave > best) store.set('nw.best.' + ctrl.board.mapId, view.wave); // a win counts too (code-25)
|
||||
const dif = viewDifficulty(view), bk = bestKey(ctrl.board.mapId, dif);
|
||||
const best = +store.get(bk, 0) || 0;
|
||||
if (view.wave > best) store.set(bk, view.wave); // a win counts too (code-25)
|
||||
$('endText').textContent = won ? 'You held the line through wave ' + view.wave + '. Every packet was filtered.' : 'The server fell on wave ' + view.wave + '.';
|
||||
const walls = view.towers.filter((t) => t.type === 'wall').length;
|
||||
const rows = [['Wave', view.wave], ['Packets killed', view.kills], ['Turrets', view.towers.length - walls], ['Firewalls', walls], ['Integrity left', view.lives], ['Best (map)', Math.max(best, view.wave)]];
|
||||
const rows = [['Wave', view.wave], ['Packets killed', view.kills], ['Turrets', view.towers.length - walls], ['Firewalls', walls], ['Integrity left', view.lives], ['Difficulty', diffName(dif)], ['Best on ' + diffName(dif), Math.max(best, view.wave)]];
|
||||
$('endStats').innerHTML = rows.map((r) => '<div><span>' + r[0] + '</span><b>' + esc(r[1]) + '</b></div>').join(''); // (in co-op these numbers come from the server)
|
||||
syncEndButtons();
|
||||
$('btnContinue').hidden = !won;
|
||||
|
|
@ -958,6 +964,55 @@
|
|||
$('pausedTag').addEventListener('click', () => { Audio.sfx('click'); app.ctrl.ctl('pause', false); });
|
||||
$('netChip').addEventListener('click', () => { if (app.ctrl && app.ctrl.kind === 'remote') { Audio.sfx('click'); invite(); } }); // room code chip: tap to invite
|
||||
|
||||
// ------------------------------------------------------------------ difficulty
|
||||
// The picker (menu, and the co-op lobby for the host) sets app.difficulty, the pick for the NEXT game, and remembers it. A game that is
|
||||
// running keeps its own (view.difficulty): Play again repeats that one, and every screen about the running game shows it.
|
||||
const diffName = (id) => (TD.DIFFICULTIES[id] ? TD.DIFFICULTIES[id].name : String(id));
|
||||
const viewDifficulty = (view) => (view && TD.isDifficulty(view.difficulty) ? view.difficulty : 'normal');
|
||||
// The best wave per map AND difficulty. Normal keeps the key the game always used (nw.best.<map>), so every record from before
|
||||
// difficulties existed is simply the normal one and nothing is lost or migrated; easy and hard get their own suffix.
|
||||
const bestKey = (map, dif) => 'nw.best.' + map + (dif === 'normal' ? '' : '.' + dif);
|
||||
// What a difficulty changes, worded from the table (so a retune cannot leave this text wrong).
|
||||
function diffSummary(id) {
|
||||
const d = TD.DIFFICULTIES[id], out = [];
|
||||
if (!d) return '';
|
||||
const pct = (m) => Math.round(Math.abs(m - 1) * 100) + '%';
|
||||
if (d.gold !== 1) out.push(pct(d.gold) + (d.gold > 1 ? ' more' : ' fewer') + ' starting credits');
|
||||
if (d.lives !== 1) out.push(pct(d.lives) + (d.lives > 1 ? ' more' : ' less') + ' integrity');
|
||||
if (d.hp !== 1) out.push('packets ' + pct(d.hp) + (d.hp < 1 ? ' weaker' : ' tougher'));
|
||||
if (d.reward !== 1) out.push('kills pay ' + pct(d.reward) + (d.reward > 1 ? ' more' : ' less'));
|
||||
return out.length ? out.join(', ') : 'The standard game.';
|
||||
}
|
||||
const diffBoxes = () => [$('diffPick'), $('lobbyDiff')].filter(Boolean);
|
||||
function buildDiffPickers() {
|
||||
for (const box of diffBoxes()) {
|
||||
box.textContent = '';
|
||||
for (const id of TD.DIFFICULTY_ORDER) {
|
||||
const b = document.createElement('button');
|
||||
b.type = 'button'; b.dataset.diff = id; b.setAttribute('role', 'radio');
|
||||
b.textContent = diffName(id);
|
||||
b.title = diffSummary(id);
|
||||
b.addEventListener('click', () => { Audio.sfx('click'); chooseDifficulty(id); });
|
||||
box.appendChild(b);
|
||||
}
|
||||
}
|
||||
chooseDifficulty(app.difficulty, true);
|
||||
}
|
||||
function chooseDifficulty(id, silent) {
|
||||
if (!TD.isDifficulty(id)) id = 'normal';
|
||||
app.difficulty = id;
|
||||
if (!silent) store.set('nw.difficulty', id);
|
||||
for (const box of diffBoxes()) for (const b of box.children) b.setAttribute('aria-checked', b.dataset.diff === id ? 'true' : 'false');
|
||||
renderDiffNote();
|
||||
}
|
||||
// One line under the picker: what the picked difficulty does; while a game is running, which one that game is on.
|
||||
function renderDiffNote() {
|
||||
const n = $('diffNote'); if (!n) return;
|
||||
const cur = app.inGame && app.ctrl ? viewDifficulty(app.ctrl.view) : null;
|
||||
n.className = 'diffnote' + (cur ? ' live' : '');
|
||||
n.textContent = cur ? 'This game: ' + diffName(cur) + (cur !== app.difficulty ? ' \u00b7 next game: ' + diffName(app.difficulty) : '') : diffSummary(app.difficulty);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------ menu / lobby
|
||||
function buildMapPicker() {
|
||||
const box = $('mapPick'); box.textContent = '';
|
||||
|
|
@ -965,7 +1020,7 @@
|
|||
const def = TD.MAPS[id];
|
||||
const b = document.createElement('button');
|
||||
b.type = 'button'; b.className = 'mapcard'; b.dataset.map = id; b.setAttribute('role', 'radio');
|
||||
b.innerHTML = '<canvas width="208" height="128"></canvas><span class="nm"></span><span class="df">DIFFICULTY <b></b></span>';
|
||||
b.innerHTML = '<canvas width="208" height="128"></canvas><span class="nm"></span><span class="df">RATING <b></b></span>';
|
||||
b.querySelector('.nm').textContent = def.name;
|
||||
b.querySelector('.df b').textContent = '●'.repeat(def.difficulty) + '○'.repeat(3 - def.difficulty);
|
||||
drawMapPreview(b.querySelector('canvas'), def);
|
||||
|
|
@ -997,6 +1052,7 @@
|
|||
$('btnCloseMenu').hidden = !app.inGame;
|
||||
$('btnSolo').lastChild.textContent = app.inGame ? 'New solo game' : 'Play solo';
|
||||
showOverlay('menu');
|
||||
renderDiffNote();
|
||||
if (!app.inGame) Audio.music('theme');
|
||||
updateResumeButton();
|
||||
}
|
||||
|
|
@ -1028,8 +1084,9 @@
|
|||
|
||||
$('btnAgain').addEventListener('click', () => {
|
||||
Audio.sfx('click');
|
||||
if (app.ctrl.kind === 'local') { app.ctrl.newGame(app.ctrl.mapId); Audio.music('battle'); }
|
||||
else { app.ctrl.newGame(app.ctrl.board.mapId); }
|
||||
// Play again keeps the difficulty of the game that just ended (not the menu's pick, which is for a NEW game)
|
||||
if (app.ctrl.kind === 'local') { app.ctrl.newGame(app.ctrl.mapId, app.ctrl.difficulty); Audio.music('battle'); }
|
||||
else { app.ctrl.newGame(app.ctrl.board.mapId, app.ctrl.difficulty); }
|
||||
});
|
||||
$('btnContinue').addEventListener('click', () => { app.ctrl.send({ c: 'continue' }); $('end').hidden = true; app.endShown = false; Audio.music('battle'); });
|
||||
$('btnEndMenu').addEventListener('click', () => { if (app.ctrl.kind === 'remote') leaveToMenu(); else { app.inGame = false; previewMap(app.mapId); setScreen('menu'); openMenu(); } });
|
||||
|
|
@ -1045,7 +1102,7 @@
|
|||
$('btnCoop').addEventListener('click', () => { Audio.unlock(); openLobby(); });
|
||||
$('btnLobbyBack').addEventListener('click', () => { cancelPending(); lobbyMsg(''); if (app.inGame) closeOverlayToGame(); else openMenu(); });
|
||||
$('inCode').addEventListener('input', (e) => { e.target.value = e.target.value.toUpperCase().replace(/[^A-Z0-9]/g, '').slice(0, 4); });
|
||||
$('btnCreate').addEventListener('click', () => connectRemote({ room: null, map: app.mapId }));
|
||||
$('btnCreate').addEventListener('click', () => connectRemote({ room: null, map: app.mapId, difficulty: app.difficulty }));
|
||||
$('btnJoin').addEventListener('click', () => {
|
||||
const code = $('inCode').value.trim().toUpperCase();
|
||||
if (!/^[A-Z0-9]{4}$/.test(code)) { lobbyMsg('Enter the 4 character room code.', true); return; }
|
||||
|
|
@ -1072,7 +1129,7 @@
|
|||
const name = ($('inName').value || store.get('nw.name', '') || '').trim().slice(0, 16) || 'Player';
|
||||
store.set('nw.name', name);
|
||||
lobbyMsg('Connecting…');
|
||||
const rc = new NW.RemoteController({ pid: getPid(), name, room: opts.room, map: opts.map, resume: !!opts.resume });
|
||||
const rc = new NW.RemoteController({ pid: getPid(), name, room: opts.room, map: opts.map, difficulty: opts.difficulty, resume: !!opts.resume });
|
||||
pendingRc = rc; setLobbyBusy(true);
|
||||
const saveSession = () => { sess.set('nw.room', rc.room); store.set('nw.session', { pid: getPid(), room: rc.room, name, ts: Date.now() }); };
|
||||
let first = true;
|
||||
|
|
@ -1088,7 +1145,7 @@
|
|||
resetSelection(); setScreen('playing'); showOverlay(null);
|
||||
onPlayers(rc.players);
|
||||
try { root.history.replaceState(null, '', root.location.pathname + '?room=' + encodeURIComponent(rc.room)); } catch (e) { /* ignore */ }
|
||||
toast('Room ' + rc.room + (rc.players.length < 2 ? '. Send the invite link to your partner!' : ''), 'good');
|
||||
toast('Room ' + rc.room + ' \u00b7 ' + diffName(viewDifficulty(rc.view)) + (rc.players.length < 2 ? '. Send the invite link to your partner!' : ''), 'good'); // (a joiner learns the host's difficulty here)
|
||||
Audio.music('battle'); requestWakeLock();
|
||||
firstRunHelp(); // an invited player is new to the game too (code-26)
|
||||
} else { toast('Reconnected', 'good'); adoptBoard(); }
|
||||
|
|
@ -1232,7 +1289,7 @@
|
|||
|
||||
// ------------------------------------------------------------------ boot
|
||||
function boot() {
|
||||
buildPalette(); buildMapPicker();
|
||||
buildPalette(); buildMapPicker(); buildDiffPickers();
|
||||
{ const keys = TD.TOWER_ORDER.map((t) => TD.TOWERS[t].key); $('helpKeys').textContent = keys[0] + '\u2013' + keys[keys.length - 1]; }
|
||||
previewMap(app.mapId);
|
||||
setScreen('menu'); showOverlay('menu');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue