lets make a game in html, the game is based off of counter strikes case opening system where players have a random chance to get an item of different rarities. Instead of weapon skins, I want a set of randomly generated but somewhat realistic looking 3D planets and stars as the items. Players will click a spin button and see the different planets scrolling across the screen and the scrolling will slow down until it lands and the player will unlock whatever they landed on. Unlocks will be catalogued in an encyclopedia accessible through a button on the side. The encyclopedia will have all obtainable objects from the set of generated planets and stars in a nice looking display however objects that have yet to be obtained will be blacked out and the name will be question marks until the player obtains it through rolls. The game should run from a single html file and need no further setup, all assets generated dynamically by code.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Below is a single-file “case opener” web-game.
Just drop it in any folder, double-click, and play – no assets, no build-step, no server.
Everything (planets, stars, animation, catalogue, persistence) is produced on the fly in pure HTML + CSS + JS.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cosmic Case-Opener</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/* ---------- GENERAL LOOK ---------- */
:root{
--bg:#0b0d17;
--panel:#111320;
--txt:#e1e6ff;
}
*{box-sizing:border-box;margin:0;padding:0;font-family:Arial,Helvetica,sans-serif}
body{
display:flex;height:100vh;background:var(--bg);color:var(--txt);overflow:hidden;
}
/* ---------- RIGHT SIDE : ENCYCLOPEDIA ---------- */
#side{
width:320px;min-width:260px;background:var(--panel);padding:24px;overflow-y:auto;
}
#catalog{display:grid;grid-template-columns:repeat(3,1fr);gap:18px;margin-top:18px;}
.tile{
width:90px;height:90px;border-radius:50%;border:2px solid #555;position:relative;
display:flex;align-items:center;justify-content:center;cursor:pointer;
}
.tile.locked{background:#000;}
.tile.locked::after{content:"???";color:#666;font-size:14px;}
.tooltip{
position:absolute;bottom:110%;left:50%;transform:translateX(-50%);
background:#000b;color:#fff;padding:4px 8px;font-size:12px;border-radius:4px;
white-space:nowrap;opacity:0;pointer-events:none;transition:.2s;
}
.tile:hover .tooltip{opacity:1;}
/* ---------- LEFT SIDE : GAME AREA ---------- */
#game{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;}
#reelWrap{
width:640px;max-width:95vw;height:130px;overflow:hidden;border:4px solid #ffffff22;
background:#0003;border-radius:8px;position:relative;
}
#reel{display:flex;align-items:center;height:100%;}
.thumb{
width:110px;height:110px;margin:0 10px;border-radius:50%;flex:none;border:3px solid transparent;
}
#spin{
padding:12px 40px;font-size:24px;border:none;border-radius:6px;background:#3b82f6;
color:#fff;cursor:pointer;transition:.2s;
}
#spin:active{transform:scale(.96);}
</style>
</head>
<body>
<!-- ---------- ENCYCLOPEDIA ---------- -->
<section id="side">
<h2>Encyclopedia 📖</h2>
<small>Discover every celestial body!</small>
<div id="catalog"></div>
</section>
<!-- ---------- GAME AREA ---------- -->
<section id="game">
<div id="reelWrap"><div id="reel"></div></div>
<button id="spin">SPIN 🚀</button>
</section>
<script>
/* =====================================================
CONFIG & UTILS
===================================================== */
const RARITIES = [
{name:"Common", color:"#9d9d9d", weight:50},
{name:"Uncommon", color:"#1eff00", weight:30},
{name:"Rare", color:"#0070dd", weight:15},
{name:"Epic", color:"#a335ee", weight:4},
{name:"Legendary", color:"#ff8000", weight:1}
];
const TOTAL_OBJECTS = 60; // size of the catalogue
const VISIBLE_THUMBS = 7; // how many items you can see while spinning
const STORAGE_KEY = "cosmic_unlocks";
const unlocked = JSON.parse(localStorage.getItem(STORAGE_KEY) || "{}"); // {id:true}
/* =====================================================
PLANET / STAR GENERATOR
===================================================== */
function hsl(h,s,l){return`hsl(${h},${s}%,${l}%)`;}
function rnd(min,max){return Math.random()*(max-min)+min;}
function drawBody(seed,type,size=100){
const cv=document.createElement("canvas");cv.width=cv.height=size;
const cx=cv.getContext("2d");cx.translate(size/2,size/2);
if(type==="star"){
// glowing ball
const grad=cx.createRadialGradient(0,0,0,0,0,size/2);
grad.addColorStop(0,"#fff");
grad.addColorStop(.4,hsl(seed.h,100,seed.l));
grad.addColorStop(1,"#000");
cx.fillStyle=grad;
cx.beginPath();cx.arc(0,0,size/2,0,Math.PI*2);cx.fill();
// small spikes
cx.strokeStyle=hsl(seed.h,100,seed.l);cx.lineWidth=1.5;
for(let i=0;i<8;i++){cx.rotate(Math.PI/4);cx.beginPath();cx.moveTo(0,0);cx.lineTo(size/2,0);cx.stroke();}
}else{ // planet
const g=cx.createRadialGradient(-size*.15,-size*.15,0,0,0,size/2);
g.addColorStop(0,hsl(seed.h,seed.s,seed.l+20));
g.addColorStop(1,hsl(seed.h,seed.s,seed.l-20));
cx.fillStyle=g;
cx.beginPath();cx.arc(0,0,size/2,0,Math.PI*2);cx.fill();
// continents/clouds
for(let i=0;i<12;i++){
cx.fillStyle=`hsla(${seed.h+rnd(-20,20)},${seed.s+rnd(-10,10)}%,${seed.l+rnd(-10,10)}%,.6)`;
cx.beginPath();cx.arc(rnd(-size/3,size/3),rnd(-size/3,size/3),rnd(size*.05,size*.18),0,Math.PI*2);
cx.fill();
}
// side-shade
const shade=cx.createRadialGradient(size*.25,size*.25,size*.1,size*.65,size*.65,size*.75);
shade.addColorStop(0,"rgba(0,0,0,0)");shade.addColorStop(1,"rgba(0,0,0,.55)");
cx.fillStyle=shade;cx.beginPath();cx.arc(0,0,size/2,0,Math.PI*2);cx.fill();
}
return cv.toDataURL();
}
/* =====================================================
CATALOG CREATION
===================================================== */
function randName(){
const s=["al","or","tu","zan","ix","os","ar","li","ve","ron","ae","un","ion","oth","ir"];
let n="";const len=2+Math.floor(Math.random()*3);
for(let i=0;i<len;i++)n+=s[Math.floor(Math.random()*s.length)];
return n[0].toUpperCase()+n.slice(1);
}
const catalog=[]; // master list of objects
(function buildCatalog(){
for(let i=0;i<TOTAL_OBJECTS;i++){
const rarity = weightedRarity();
const type = Math.random()<0.8 ? "planet" : "star";
const seed = {h:Math.floor(Math.random()*360),s:40+rnd(0,40),l:30+rnd(0,20)};
const img = drawBody(seed,type,90);
catalog.push({id:i,type,rarity,name:randName(),img});
}
})();
function weightedRarity(){
const roll=Math.random()*100;let sum=0;
for(const r of RARITIES){sum+=r.weight;if(roll<sum)return r;}
return RARITIES[0];
}
/* =====================================================
ENCYCLOPEDIA RENDER
===================================================== */
const catDOM=document.getElementById("catalog");
function renderCatalog(){
catDOM.innerHTML="";
catalog.forEach(o=>{
const t=document.createElement("div");
t.className="tile"+(unlocked[o.id]?"":" locked");
if(unlocked[o.id]){
t.style.background=`url(${o.img}) center/cover`;
t.style.borderColor=o.rarity.color;
}
const tip=document.createElement("span");
tip.className="tooltip";
tip.textContent=unlocked[o.id]?`${o.name} (${o.rarity.name})`:"Unknown";
t.appendChild(tip);
catDOM.appendChild(t);
});
}
renderCatalog();
/* =====================================================
REEL / SPIN LOGIC
===================================================== */
const reel=document.getElementById("reel");
let spinning=false;
document.getElementById("spin").addEventListener("click",spin);
function spin(){
if(spinning) return;
spinning=true;
// 1) fresh sequence for the reel
reel.innerHTML="";
const sequence=[];
for(let i=0;i<50;i++) sequence.push(randCatalogItem());
const winner = weightedCatalogPick(); // what user will land on
sequence.push(...catalog.slice(0,VISIBLE_THUMBS)); // filler
sequence.push(winner);
// 2) build DOM for sequence
sequence.forEach(o=>{
const img=document.createElement("img");
img.src=o.img; img.className="thumb"; img.style.borderColor=o.rarity.color;
reel.appendChild(img);
});
// 3) perform animation
const itemW = 130; // thumb width + margins
const travel = (sequence.length - VISIBLE_THUMBS)*itemW;
const duration = 4000;
reel.style.transition=`transform ${duration}ms cubic-bezier(.1,.1,0,1)`;
requestAnimationFrame(()=>reel.style.transform=`translateX(-${travel}px)`);
// 4) finish
setTimeout(()=>{reel.style.transition="";reel.style.transform="";
reward(winner);spinning=false;},duration+100);
}
function randCatalogItem(){return catalog[Math.floor(Math.random()*catalog.length)];}
function weightedCatalogPick(){
const bag=[];
RARITIES.forEach(r=>{
catalog.filter(o=>o.rarity===r).forEach(o=>bag.push(...Array(r.weight).fill(o)));
});
return bag[Math.floor(Math.random()*bag.length)];
}
/* =====================================================
REWARD / PERSISTENCE
===================================================== */
function reward(item){
const first=!unlocked[item.id];
if(first){
unlocked[item.id]=true;
localStorage.setItem(STORAGE_KEY,JSON.stringify(unlocked));
renderCatalog();
alert(`🎉 NEW DISCOVERY!\n${item.name} – ${item.rarity.name}`);
}else{
alert(`Duplicate 💤 (${item.name})`);
}
}
</script>
</body>
</html>
How it works
On load, a fixed catalogue of 60 celestial bodies is procedurally generated (no images on disk).
• Planets: simple 2-D “3-D-looking” spheres with gradients, blotches, and a dark-side shade.
• Stars : bright radial gradient + little spikes.
Each object gets a rarity (Common → Legendary) based on weighted odds.
Clicking “SPIN” scrolls a strip of thumbnails (like the CS:GO case reel) with a predetermined winning item inserted near the end. CSS transition eases it to a stop.
When you land on something, it’s written to localStorage → persists across refreshes.
The encyclopedia grid shows unlocked thumbnails in colour; the rest are blacked-out with “???”.
All contained in one file – just open it and have fun!