Download task_042/solution/code/index.html from Lego-X/UXInteract: direct link, hf CLI and curl.
- Browser
- Download file 9.86 kB
-
https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_042/solution/code/index.html
- Command line
-
hf download hf://datasets/Lego-X/UXInteract/task_042/solution/code/index.html
-
curl -L -o index.html https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_042/solution/code/index.html
9.86 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Oxygen Not Included (Mini)</title> | |
| <style> | |
| body { font-family: system-ui, sans-serif; background: #0b0f14; color: #cfe8ff; text-align: center; margin: 0; padding: 12px; } | |
| h1 { color: #5ad1e6; font-size: 22px; } | |
| #hud { font-size: 15px; margin: 6px; } | |
| #grid { display: grid; gap: 1px; justify-content: center; margin: 12px auto; background: #04060a; width: max-content; } | |
| .cell { width: 28px; height: 28px; font-size: 14px; display: flex; align-items: center; justify-content: center; cursor: pointer; } | |
| .rock { background: #2b2f36; } /* undug rock */ | |
| .dark { background: #04060a; } /* unknown / fog: not yet dug */ | |
| .open { background: #16313f; } /* dug, lit space */ | |
| .oxygenCell { background: #1f6f4f; } /* resource: oxygen */ | |
| .waterCell { background: #1f4f8f; } /* resource: water */ | |
| .dup { outline: 2px solid #ffd166; } | |
| .dup.selected { outline: 3px solid #ff5a5a; } | |
| #log { color: #8fb3c9; min-height: 20px; margin-top: 8px; } | |
| button { padding: 6px 14px; border: none; border-radius: 6px; background: #5ad1e6; color: #04060a; cursor: pointer; } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>Oxygen Not Included (Mini)</h1> | |
| <div id="hud"> | |
| Environmental Oxygen: <span id="oxygen">100</span>% | |
| <span id="dupStats"></span> | |
| </div> | |
| <div id="grid"></div> | |
| <div> | |
| <button data-expand="up">View Up</button><button data-expand="down">View Down</button> | |
| <button data-expand="left">View Left</button><button data-expand="right">View Right</button> | |
| </div> | |
| <p id="log">Select a duplicant, then click an adjacent rock to dig.</p> | |
| <dialog id="printPrompt" data-testid="print-prompt"><p>Print a new duplicant?</p><button data-answer-print="yes">Print</button><button data-answer-print="no">Not Now</button></dialog> | |
| <script> | |
| const COLS = 16, ROWS = 12; | |
| let cols = COLS; | |
| const gridEl = document.getElementById('grid'); | |
| const oxygenEl = document.getElementById('oxygen'); | |
| const dupStatsEl = document.getElementById('dupStats'); | |
| const logEl = document.getElementById('log'); | |
| gridEl.style.gridTemplateColumns = 'repeat(' + cols + ', 28px)'; | |
| let map = []; // each cell: {type:'rock'|'open'|'oxygen'|'water', known:bool} | |
| let cellsEl = []; | |
| let duplicants = []; // colonists with move + dig skills | |
| let selected = null; | |
| let oxygen = 100; | |
| let virtualTime = 0, printClock = 0, printPending = false; | |
| let testMode = false; | |
| const SICK_THRESHOLD = 20; // oxygen/water below threshold -> duplicant gets sick | |
| function buildMap() { | |
| cols = COLS; | |
| map = []; | |
| for (let r = 0; r < ROWS; r++) { | |
| const row = []; | |
| for (let c = 0; c < cols; c++) { | |
| // top two rows start as open known space; rest is unknown rock (dark/fog) | |
| const open = r < 2; | |
| row.push({ type: open ? 'open' : 'rock', known: open }); | |
| } | |
| map.push(row); | |
| } | |
| } | |
| function render() { | |
| gridEl.style.gridTemplateColumns = 'repeat(' + cols + ', 28px)'; | |
| gridEl.innerHTML = ''; | |
| cellsEl = []; | |
| for (let r = 0; r < map.length; r++) { | |
| const rowEl = []; | |
| for (let c = 0; c < cols; c++) { | |
| const cell = document.createElement('div'); | |
| const m = map[r][c]; | |
| cell.className = 'cell ' + ( | |
| !m.known ? 'dark' : | |
| m.type === 'oxygen' ? 'oxygenCell' : | |
| m.type === 'water' ? 'waterCell' : | |
| m.type === 'rock' ? 'rock' : 'open'); | |
| cell.dataset.r = r; cell.dataset.c = c; | |
| cell.addEventListener('click', () => onCellClick(r, c)); | |
| gridEl.appendChild(cell); | |
| rowEl.push(cell); | |
| } | |
| cellsEl.push(rowEl); | |
| } | |
| drawDuplicants(); | |
| } | |
| function drawDuplicants() { | |
| document.querySelectorAll('.dup').forEach(e => e.classList.remove('dup', 'selected')); | |
| duplicants.forEach(d => { | |
| const el = cellsEl[d.r][d.c]; | |
| el.classList.add('dup'); | |
| if (d === selected) el.classList.add('selected'); | |
| el.textContent = d.sick ? '🤒' : '🙂'; | |
| }); | |
| } | |
| function spawnDuplicant() { | |
| duplicants.push({ r: 0, c: Math.floor(Math.random() * COLS), water: 100, stamina: 100, sick: false }); | |
| render(); | |
| } | |
| function onCellClick(r, c) { | |
| const clickedDup = duplicants.find(d => d.r === r && d.c === c); | |
| if (clickedDup) { selected = clickedDup; drawDuplicants(); return; } | |
| if (!selected) { logEl.textContent = 'Select a duplicant first.'; return; } | |
| const target = map[r][c]; | |
| if (target.known && target.type !== 'rock') { | |
| const dr = r - selected.r, dc = c - selected.c; | |
| if (Math.abs(dc) <= 1 && dr >= -1 && dr <= 1) { | |
| selected.r = r; selected.c = c; applyGravity(selected); render(); | |
| } else logEl.textContent = 'Move one tile at a time through explored space; upward movement is limited to one tile.'; | |
| return; | |
| } | |
| // dig command: must be adjacent (can reach up to 3 cells higher) | |
| const dr = r - selected.r, dc = c - selected.c; | |
| if (Math.abs(dc) <= 1 && dr >= -3 && dr <= 1 && map[r][c].type === 'rock') { | |
| digCell(selected, r, c); | |
| } else { | |
| logEl.textContent = 'That rock is out of digging range.'; | |
| } | |
| } | |
| function digCell(dup, r, c) { | |
| // reveal the cell; digging costs water (dehydration); may expose a resource | |
| const roll = Math.random(); | |
| const resource = map[r][c].resource; | |
| map[r][c] = { type: resource || (roll < 0.2 ? 'oxygen' : roll < 0.35 ? 'water' : 'open'), known: true }; | |
| dup.water = Math.max(0, dup.water - 8); // digging dehydrates faster | |
| applyGravity(dup); | |
| if (map[r][c].type === 'oxygen') { oxygen = Math.min(100, oxygen + 12); logEl.textContent = 'Found an oxygen resource!'; } | |
| else if (map[r][c].type === 'water') { dup.water = Math.min(100, dup.water + 25); logEl.textContent = 'Found a water resource!'; } | |
| else { logEl.textContent = 'Dug out a new space.'; } | |
| dup.sick = oxygen <= SICK_THRESHOLD || dup.water <= SICK_THRESHOLD; | |
| render(); updateHud(); | |
| } | |
| // gravity: duplicant falls down through open space | |
| function applyGravity(dup) { | |
| while (dup.r + 1 < map.length && map[dup.r + 1][dup.c].known && map[dup.r + 1][dup.c].type !== 'rock') { | |
| dup.r++; | |
| } | |
| } | |
| function moveTick() { | |
| // ambient oxygen drops, duplicants slowly dehydrate; check sickness threshold | |
| oxygen = Math.max(0, oxygen - 1); | |
| duplicants.forEach(d => { | |
| d.water = Math.max(0, d.water - 1); | |
| d.sick = (oxygen <= SICK_THRESHOLD || d.water <= SICK_THRESHOLD); | |
| }); | |
| updateHud(); | |
| drawDuplicants(); | |
| } | |
| function updateHud() { | |
| oxygenEl.textContent = oxygen; | |
| dupStatsEl.textContent = ' · ' + duplicants.map((d, i) => | |
| 'Duplicant ' + (i + 1) + ' dehydration=' + (100 - d.water) + (d.sick ? ' (sick)' : '')).join(' · '); | |
| } | |
| buildMap(); | |
| spawnDuplicant(); | |
| render(); | |
| updateHud(); | |
| function advanceTime(ms) { | |
| virtualTime += ms; printClock += ms; | |
| while (virtualTime >= 1000) { moveTick(); virtualTime -= 1000; } | |
| if (printClock >= 10000) { | |
| printPending = true; printClock %= 10000; | |
| document.getElementById('printPrompt').show(); | |
| } | |
| } | |
| function answerPrint(yes) { | |
| if (printPending && yes) spawnDuplicant(); | |
| printPending = false; | |
| document.getElementById('printPrompt').close(); | |
| updateHud(); | |
| } | |
| document.querySelectorAll('[data-answer-print]').forEach(button => button.addEventListener('click', () => answerPrint(button.dataset.answerPrint === 'yes'))); | |
| setInterval(() => { if (!testMode) advanceTime(1000); }, 1000); | |
| function ensureCell(r,c) { | |
| while(r < 0){ map.unshift(Array.from({length:cols},()=>({type:'rock',known:false}))); duplicants.forEach(d=>d.r++); r++; } | |
| while(r >= map.length) map.push(Array.from({length:cols},()=>({type:'rock',known:false}))); | |
| while(c < 0){ map.forEach(row=>row.unshift({type:'rock',known:false})); duplicants.forEach(d=>d.c++); cols++; c++; } | |
| while(c >= cols){ map.forEach(row=>row.push({type:'rock',known:false})); cols++; } | |
| render(); | |
| return [r,c]; | |
| } | |
| document.querySelectorAll('[data-expand]').forEach(button => button.addEventListener('click', () => { | |
| const d=button.dataset.expand; | |
| if(d==='up') ensureCell(-1,0); else if(d==='down') ensureCell(map.length,0); | |
| else if(d==='left') ensureCell(0,-1); else ensureCell(0,cols); | |
| })); | |
| window.gameTest = { | |
| reset(config={}) { | |
| testMode=true; | |
| logEl.textContent = 'Select a duplicant, then click an adjacent rock to dig.'; | |
| document.getElementById('printPrompt').close(); | |
| buildMap(); duplicants=[]; selected=null; oxygen=config.oxygen??100; virtualTime=0; printPending=false; | |
| for(const pos of config.openCells||[]) if(map[pos[0]]?.[pos[1]]) map[pos[0]][pos[1]]={type:'open',known:true}; | |
| for(const cell of config.resourceCells||[]) if(map[cell.r]?.[cell.c]) map[cell.r][cell.c]={type:'rock',known:false,resource:cell.type}; | |
| printClock=0; spawnDuplicant(); selected=duplicants[0]; | |
| if(config.duplicant){Object.assign(selected,config.duplicant);applyGravity(selected);} render(); updateHud(); return this.state(); | |
| }, | |
| move(r,c) { [r,c]=ensureCell(r,c); if(!selected)selected=duplicants[0]; if(map[r][c].known&&map[r][c].type!=='rock') onCellClick(r,c); return this.state(); }, | |
| dig(r,c) { [r,c]=ensureCell(r,c); if(!selected)selected=duplicants[0]; if(map[r][c].type==='rock') onCellClick(r,c); return this.state(); }, | |
| step(ms) { advanceTime(ms); return this.state(); }, | |
| answerPrint(yes) { answerPrint(yes); return this.state(); }, | |
| state() { return { oxygen, duplicants:duplicants.map(d=>({...d})), resources:{oxygen,water:duplicants.reduce((n,d)=>n+d.water,0)}, dimensions:{rows:map.length,cols}, printPending, map:map.map(row=>row.map(c=>({...c}))) }; } | |
| }; | |
| </script> | |
| </body> | |
| </html> | |