Skip to content

Test game #47

Open
Open

Description

@omarherveri23-rgb
<title>Mega City Builder 2.0</title> <style> *{box-sizing:border-box} body{ margin:0;background:#172b40;color:white; font-family:Arial;text-align:center; } header{ background:#123c63;padding:15px; } h1{margin:5px;color:#ffe45c} .stats{ display:flex;justify-content:center; flex-wrap:wrap;gap:12px;padding:12px; background:#244d69; } .stat{ background:#102d43;padding:10px; border-radius:10px; } .controls{ padding:10px;background:#183c53; } button{ padding:10px;margin:4px; border:0;border-radius:8px; background:#ffc83d;font-weight:bold; cursor:pointer; } button:active{transform:scale(.95)} #shop{ display:flex;flex-wrap:wrap; justify-content:center;gap:3px; padding:10px; } #shop button{background:#e4efff} #map{ display:grid; grid-template-columns:repeat(15,minmax(35px,1fr)); gap:3px;padding:8px; max-width:1000px;margin:auto; background:#254b36; } .tile{ aspect-ratio:1; background:#549b48; border:1px solid #397b39; display:flex;align-items:center; justify-content:center; font-size:clamp(18px,3vw,30px); cursor:pointer; } .tile:hover{background:#82c76c} footer{padding:20px} </style>

🏙️ MEGA CITY BUILDER 2.0

Build the biggest city in the world!

💰 Money: $10000
👥 Population: 0
🏢 Buildings: 0
⭐ Level: 1

🛒 BUILDING SHOP

🚜 Bulldozer ⬆️ Upgrade 💰 Collect $500 💾 SAVE 📂 LOAD 🔄 NEW GAME 🌙 Day/Night

Choose a building to start!

🌆 Your city is growing!

Build houses, roads, skyscrapers and more!

<script> let money=10000; let population=0; let level=1; let selected=null; let night=false; const items=[ { id:"house",name:"House",emoji:"🏠",price:100,pop:5}, { id:"big_house",name:"Big House",emoji:"🏡",price:250,pop:12}, { id:"office",name:"Office",emoji:"🏢",price:500,pop:30}, { id:"tower",name:"Tower",emoji:"🏙️",price:1000,pop:100}, { id:"mega_tower",name:"Mega Tower",emoji:"🌆",price:2500,pop:300}, { id:"tree",name:"Tree",emoji:"🌳",price:50,pop:0}, { id:"park",name:"Park",emoji:"🌲",price:150,pop:0}, { id:"hospital",name:"Hospital",emoji:"🏥",price:800,pop:20}, { id:"school",name:"School",emoji:"🏫",price:600,pop:15}, { id:"mall",name:"Mall",emoji:"🏬",price:1200,pop:40}, { id:"store",name:"Store",emoji:"🏪",price:300,pop:5}, { id:"hotel",name:"Hotel",emoji:"🏨",price:1500,pop:60}, { id:"stadium",name:"Stadium",emoji:"🏟️",price:3000,pop:100}, { id:"bank",name:"Bank",emoji:"🏦",price:2000,pop:50}, { id:"factory",name:"Factory",emoji:"🏭",price:1800,pop:20}, { id:"fire",name:"Fire Station",emoji:"🚒",price:700,pop:10}, { id:"police",name:"Police",emoji:"🚓",price:700,pop:10}, { id:"road",name:"Road",emoji:"🛣️",price:30,pop:0}, { id:"car",name:"Car",emoji:"🚗",price:200,pop:0}, { id:"airport",name:"Airport",emoji:"✈️",price:5000,pop:200} ]; let grid=Array(300).fill(null); const map=document.getElementById("map"); const shop=document.getElementById("shop"); function update(){ document.getElementById("money").textContent=money; document.getElementById("pop").textContent=population; document.getElementById("buildings").textContent= grid.filter(x=>x!==null).length; level=1+Math.floor(population/100); document.getElementById("level").textContent=level; } function draw(){ map.innerHTML=""; grid.forEach((item,index)=>{ let tile=document.createElement("div"); tile.className="tile"; tile.textContent=item?item.emoji:""; tile.title=item?item.name:"Empty land"; tile.onclick=()=>place(index); map.appendChild(tile); }); } function buildShop(){ items.forEach(item=>{ let b=document.createElement("button"); b.textContent=item.emoji+" "+item.name+" ($"+item.price+")"; b.onclick=()=>selectItem(item.id); shop.appendChild(b); }); } function selectItem(id){ selected=id; let item=items.find(x=>x.id===id); document.getElementById("message").textContent= id==="bulldozer"?"🚜 Choose something to remove": id==="upgrade"?"⬆️ Choose a building to upgrade": "Selected: "+item.name+" - $"+item.price; } function place(index){ let message=document.getElementById("message"); if(selected==="bulldozer"){ if(!grid[index]){ message.textContent="Nothing to remove!"; return; } population-=grid[index].pop; money+=Math.floor(grid[index].price/2); grid[index]=null; message.textContent="Building removed! Half your money returned."; } else if(selected==="upgrade"){ let old=grid[index]; if(!old){ message.textContent="Choose a building first!"; return; } if(money<500){ message.textContent="You need $500!"; return; } money-=500; population+=old.pop; old.pop*=2; old.name="Upgraded "+old.name; old.emoji="⭐"+old.emoji; message.textContent="Building upgraded!"; } else{ let item=items.find(x=>x.id===selected); if(!item)return; if(grid[index]){ message.textContent="That land is occupied!"; return; } if(money

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions