Below is a complete, self-contained web game (“Space Miner”) packed into a single HTML file.
Just copy-paste everything into a file called index.html, open it in a browser, and start clicking!
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>🚀 Space Miner – Idle Clicker</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&display=swap');
*{box-sizing:border-box;margin:0;padding:0}
body{
font-family:'Orbitron',sans-serif;
background:#000 url('https://i.imgur.com/nf8KZtF.jpg') center/cover fixed;
color:#e0e0e0;
display:flex;flex-direction:column;align-items:center;min-height:100vh
}
h1{margin:20px 0;font-size:2.2rem;text-shadow:0 0 8px #0ff}
#game{
background:rgba(0,0,0,.6);
padding:20px 30px;
border:2px solid #0ff;
border-radius:12px;
width:350px;
}
#stats{margin-bottom:15px}
#stats div{margin:6px 0;font-size:1.1rem}
#clickBtn{
width:100%;padding:18px;margin:10px 0;
font-size:1.2rem;font-weight:700;cursor:pointer;
background:#222;border:2px solid #0ff;border-radius:10px;color:#0ff;
}
#clickBtn:hover{background:#111}
.shopItem{
background:#111;margin:8px 0;padding:10px 12px;border-radius:8px;
border:1px solid #555;display:flex;justify-content:space-between;align-items:center;
cursor:pointer;transition:background .2s,border-color .2s;
}
.shopItem:hover{background:#222;border-color:#0ff}
.shopItem.locked{opacity:.35;pointer-events:none}
.shopItem span{font-size:.95rem}
#footer{margin-top:12px;font-size:.8rem;color:#888}
button.reset{
margin-top:15px;padding:6px 10px;border:1px solid #f55;background:#400;color:#fff;
border-radius:6px;cursor:pointer
}
</style>
</head>
<body>
<h1>🚀 Space Miner</h1>
<div id="game">
<div id="stats">
<div>Ore: <span id="ore">0</span></div>
<div>Ore / Click: <span id="opc">1</span></div>
<div>Ore / Sec: <span id="ops">0</span></div>
<div>Sector Level: <span id="sector">1</span></div>
</div>
<button id="clickBtn">Mine Asteroid</button>
<h3>Upgrades</h3>
<div id="shop"></div>
<button class="reset" id="warpBtn">🌌 Warp to New Sector (Soft Reset)</button>
<div id="footer">Progress auto-saves every 5 seconds.</div>
</div>
<script>
/* ========== Game State ========== */
const G = {
ore: 0,
totalOre: 0,
orePerClick: 1,
orePerSec: 0,
sector: 1, // prestige level
upgrades: [
{ id:'pickaxe', name:'🔨 Titanium Pickaxe', baseCost: 15, lvl:0,
desc:'+1 Ore / Click', effect:(u)=>G.orePerClick += 1 },
{ id:'empDrill', name:'⚡ EMP Drill', baseCost: 100, lvl:0,
desc:'+10 Ore / Click', effect:(u)=>G.orePerClick += 10 },
{ id:'drone', name:'🤖 Mining Drone', baseCost: 50, lvl:0,
desc:'+1 Ore / Sec', effect:(u)=>G.orePerSec += 1 },
{ id:'fleet', name:'🚀 Drone Fleet', baseCost: 400, lvl:0,
desc:'+10 Ore / Sec', effect:(u)=>G.orePerSec += 10 },
{ id:'quantum', name:'💎 Quantum Extractor', baseCost:1500, lvl:0,
desc:'+100 Ore / Click & +50 Ore / Sec', locked:true,
effect:(u)=>{ G.orePerClick+=100; G.orePerSec+=50 } },
]
};
/* ========== Helpers ========== */
const el = id=>document.getElementById(id);
const fmt = n=>Math.floor(n).toLocaleString();
/* ========== Rendering ========== */
function renderStats(){
el('ore').textContent = fmt(G.ore);
el('opc').textContent = fmt(G.orePerClick);
el('ops').textContent = fmt(G.orePerSec);
el('sector').textContent= G.sector;
}
function cost(u){ return Math.floor(u.baseCost * Math.pow(1.7, u.lvl)) }
function maybeUnlock(){
// Unlock Quantum once total ore ≥ 10k in current run
const q = G.upgrades.find(u=>u.id==='quantum');
if(q.locked && G.totalOre >= 10000){
q.locked=false;
buildShop();
}
}
/* ========== Building Shop UI ========== */
const shopDiv = el('shop');
function buildShop(){
shopDiv.innerHTML='';
G.upgrades.forEach(u=>{
const d=document.createElement('div');
d.className='shopItem' + (u.locked?' locked':'');
d.onclick=()=>buyUpgrade(u);
d.innerHTML=`
<span>${u.name}<br>
<small>${u.desc}</small></span>
<strong id="${u.id}_cost">${fmt(cost(u))}</strong>
`;
shopDiv.appendChild(d);
});
}
function updateShopCosts(){
G.upgrades.forEach(u=>{
el(u.id+'_cost').textContent = fmt(cost(u));
});
}
/* ========== Core Mechanics ========== */
el('clickBtn').onclick=()=>{
G.ore += G.orePerClick * G.sector;
G.totalOre += G.orePerClick * G.sector;
renderStats();
maybeUnlock();
};
function buyUpgrade(u){
const c = cost(u);
if(G.ore < c) return;
G.ore -= c;
u.lvl++;
u.effect(u);
renderStats();
updateShopCosts();
}
function tick(){ // 1-second heartbeat
if(G.orePerSec>0){
const delta = G.orePerSec * G.sector;
G.ore += delta;
G.totalOre += delta;
renderStats();
maybeUnlock();
}
}
setInterval(tick,1000);
/* ========== Prestige / Soft Reset ========== */
el('warpBtn').onclick=()=>{
if(confirm("Warping resets upgrades but grants +1 Sector Level.\nProceed?")){
G.sector++;
G.ore=0; G.totalOre=0;
G.orePerClick=1; G.orePerSec=0;
G.upgrades.forEach(u=>{u.lvl=0; if(u.id==='quantum')u.locked=true;});
buildShop(); renderStats(); save();
}
};
/* ========== Persistence ========== */
const STORAGE_KEY="spaceMinerSave";
function save(){localStorage.setItem(STORAGE_KEY,JSON.stringify(G));}
function load(){
const data = JSON.parse(localStorage.getItem(STORAGE_KEY)||'null');
if(!data) return;
Object.assign(G,data);
/* Function references are lost after JSON parse – restore them */
G.upgrades.forEach(u=>{
const base = UPGRADE_DEFS.find(d=>d.id===u.id);
Object.assign(u, base);
});
}
const UPGRADE_DEFS = JSON.parse(JSON.stringify(G.upgrades)); // keep originals
load();
buildShop(); renderStats();
setInterval(save,5000);
</script>
</body>
</html>
Have fun tweaking or expanding it—add new upgrades, graphics, or even enemies if you like. Happy coding and good mining! 🚀🪨