chore: remove happiness stat and migration code from game logic and UI
This commit is contained in:
+13
-41
@@ -1,39 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Tiny Tycoon 3D (Multiplayer)</title>
|
||||
<style>
|
||||
/* --- General Setup --- */
|
||||
body {
|
||||
margin: 0;
|
||||
margin: 0;
|
||||
overflow: hidden;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
||||
background-color: #1a202c;
|
||||
color: #e2e8f0;
|
||||
color: #e2e8f0;
|
||||
}
|
||||
#game-canvas { display: block; }
|
||||
|
||||
/* --- UI Panels --- */
|
||||
.ui-panel {
|
||||
position: absolute;
|
||||
position: absolute;
|
||||
background-color: rgba(45, 55, 72, 0.9);
|
||||
padding: 12px;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
|
||||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
#title-card { top: 20px; left: 50%; transform: translateX(-50%); padding: 8px 16px; font-size: 1.25rem; font-weight: bold; }
|
||||
#info-card { top: 20px; right: 20px; max-width: 250px; font-size: 0.875rem; }
|
||||
#info-card h3, #stats-panel h3, #players-panel h3 { font-weight: bold; font-size: 1.125rem; margin-top: 0; margin-bottom: 8px; color: white; }
|
||||
#info-card strong { color: #63b3ed; }
|
||||
#stats-panel { top: 20px; left: 20px; font-size: 1rem; min-width: 240px; }
|
||||
#stats-panel { top: 80px; left: 20px; font-size: 1rem; min-width: 240px; }
|
||||
#stats-panel div { margin-bottom: 4px; }
|
||||
#stats-panel span { font-weight: bold; }
|
||||
#money-stat { color: #48bb78; }
|
||||
#population-stat { color: #63b3ed; }
|
||||
#happiness-stat { color: #f6e05e; }
|
||||
#players-panel { top: 220px; left: 20px; max-width: 240px; }
|
||||
#players-panel { top: 200px; left: 20px; max-width: 240px; }
|
||||
#players-list .player-div { padding: 4px; font-size: 0.875rem; }
|
||||
#players-list .player-div.is-self { background-color: rgba(66, 153, 225, 0.5); border-radius: 4px; }
|
||||
#players-list .player-div strong { font-weight: bold; }
|
||||
@@ -41,7 +41,7 @@
|
||||
/* --- Build Menu --- */
|
||||
#ui-panel-bottom { bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; }
|
||||
.build-btn {
|
||||
padding: 10px 16px;
|
||||
padding: 10px 16px;
|
||||
border: 2px solid transparent;
|
||||
border-radius: 8px;
|
||||
background-color: #4a5568;
|
||||
@@ -49,7 +49,7 @@
|
||||
font-weight: 600;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease-in-out;
|
||||
display: flex;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 0.875rem;
|
||||
@@ -82,6 +82,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div id="game-container" class="hidden">
|
||||
<div id="title-card" class="ui-panel">Tiny Tycoon 3D</div>
|
||||
<div id="info-card" class="ui-panel">
|
||||
<h3>Controls</h3>
|
||||
<p><strong>Left-Click + Drag:</strong> Rotate</p>
|
||||
@@ -92,7 +93,6 @@
|
||||
<h3>My City</h3>
|
||||
<div>💰 Money: <span id="money-stat"></span></div>
|
||||
<div>👥 Population: <span id="population-stat"></span></div>
|
||||
<div>😊 Happiness: <span id="happiness-stat"></span></div>
|
||||
</div>
|
||||
<div id="players-panel" class="ui-panel">
|
||||
<h3>Players Online</h3>
|
||||
@@ -105,8 +105,6 @@
|
||||
<button class="build-btn" data-type="industrial" title="Cost: $500"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 22h16"/><path d="M6 18V8.103a2 2 0 0 1 .91-1.657l6-3.79a2 2 0 0 1 2.18 0l6 3.79A2 2 0 0 1 22 8.103V18"/><path d="m14 14-2-1-2 1"/><path d="M18 18h-4v-2h4v2Z"/></svg>Factory</button>
|
||||
<button class="build-btn" data-type="park" title="Cost: $80"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22v-8"/><path d="m17 8-1.5-1.5c-.9-.9-2.5-.9-3.4 0L12 6.6c-.9-.9-2.5-.9-3.4 0L7 8"/><path d="M12 22h-1a2 2 0 0 1-2-2v-4a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v4a2 2 0 0 1-2 2h-1Z"/></svg>Park</button>
|
||||
<button class="build-btn" data-type="powerplant" title="Cost: $1000"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 12v3"/><path d="M16.24 7.76 14.12 9.88"/><path d="m7.76 7.76 2.12 2.12"/><path d="m12 2 3.5 3.5"/><path d="m12 2-3.5 3.5"/><path d="M22 12h-3"/><path d="M5 12H2"/><path d="M19.07 19.07 16.95 16.95"/><path d="m4.93 19.07 2.12-2.12"/><path d="M12 22a10 10 0 1 0 0-20 10 10 0 0 0 0 20Z"/></svg>Power</button>
|
||||
<button class="build-btn" data-type="police" title="Cost: $600"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"></path></svg>Police</button>
|
||||
<button class="build-btn" data-type="stadium" title="Cost: $5000"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 8c-2.209 0-4 1.791-4 4s1.791 4 4 4 4-1.791 4-4-1.791-4-4-4z"/><path d="M22 12c0-5.523-4.477-10-10-10S2 6.477 2 12s4.477 10 10 10 10-4.477 10-10z"/><path d="M12 2v2"/><path d="M12 20v2"/><path d="M22 12h-2"/><path d="M4 12H2"/><path d="M19.071 4.929l-1.414 1.414"/><path d="M6.343 17.657l-1.414 1.414"/><path d="M19.071 19.071l-1.414-1.414"/><path d="M6.343 6.343l-1.414-1.414"/></svg>Stadium</button>
|
||||
<button class="build-btn" data-type="road" title="Cost: $20"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h16"/><path d="M4 12v-2a4 4 0 0 1 4-4h8a4 4 0 0 1 4 4v2"/><path d="M4 12v2a4 4 0 0 0 4 4h8a4 4 0 0 0 4-4v-2"/></svg>Road</button>
|
||||
<button class="build-btn" data-type="remove" title="Refund: 50%"><svg viewBox="0 0 24 24" fill="none" stroke="#fca5a5" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 4H8l-7 8 7 8h13a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2Z"></path><line x1="18" x2="12" y1="9" y2="15"></line><line x1="12" x2="18" y1="9" y2="15"></line></svg>Remove</button>
|
||||
</div>
|
||||
@@ -132,8 +130,7 @@
|
||||
const buildingData = {
|
||||
'residential': { cost: 100 }, 'commercial': { cost: 250 },
|
||||
'industrial': { cost: 500 }, 'park': { cost: 80 },
|
||||
'powerplant': { cost: 1000 }, 'road': { cost: 20 },
|
||||
'police': { cost: 600 }, 'stadium': { cost: 5000 }
|
||||
'powerplant': { cost: 1000 }, 'road': { cost: 20 }
|
||||
};
|
||||
const nicknameModal = document.getElementById('nickname-modal');
|
||||
const nicknameInput = document.getElementById('nickname-input');
|
||||
@@ -195,11 +192,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
function animate() {
|
||||
requestAnimationFrame(animate);
|
||||
controls.update();
|
||||
renderer.render(scene, camera);
|
||||
}
|
||||
function animate() { requestAnimationFrame(animate); controls.update(); renderer.render(scene, camera); }
|
||||
|
||||
// --- WebSocket Logic ---
|
||||
function connectWebSocket() {
|
||||
@@ -254,8 +247,6 @@
|
||||
case 'industrial': mainMaterial.color.set(0xa0aec0); break;
|
||||
case 'park': mainMaterial.color.set(0x48bb78); break;
|
||||
case 'powerplant': mainMaterial.color.set(0xf56565); break;
|
||||
case 'police': mainMaterial.color.set(0x4299e1); break;
|
||||
case 'stadium': mainMaterial.color.set(0xed8936); break;
|
||||
default: mainMaterial.color.set(0xffffff); break;
|
||||
}
|
||||
}
|
||||
@@ -307,22 +298,6 @@
|
||||
roadSurface.position.y = 0.05; buildingGroup.add(roadSurface);
|
||||
break;
|
||||
}
|
||||
case 'police': {
|
||||
const base = new THREE.Mesh(new THREE.BoxGeometry(gridCellSize * 0.8, 2, gridCellSize * 0.8), new THREE.MeshLambertMaterial({color: 0xedf2f7}));
|
||||
const roof = new THREE.Mesh(new THREE.BoxGeometry(gridCellSize * 0.9, 0.3, gridCellSize * 0.9), mainMaterial);
|
||||
base.position.y = 1;
|
||||
roof.position.y = 2.15;
|
||||
buildingGroup.add(base, roof);
|
||||
break;
|
||||
}
|
||||
case 'stadium': {
|
||||
const base = new THREE.Mesh(new THREE.CylinderGeometry(gridCellSize * 0.8, gridCellSize, 3, 32), mainMaterial);
|
||||
const field = new THREE.Mesh(new THREE.CylinderGeometry(gridCellSize * 0.5, gridCellSize * 0.6, 0.1, 32), new THREE.MeshLambertMaterial({color: 0x48bb78}));
|
||||
base.position.y = 1.5;
|
||||
field.position.y = 3.05;
|
||||
buildingGroup.add(base, field);
|
||||
break;
|
||||
}
|
||||
}
|
||||
buildingGroup.position.set(position.x, 0, position.z);
|
||||
buildingGroup.traverse(c => { if(c.isMesh) c.castShadow = true; });
|
||||
@@ -344,7 +319,6 @@
|
||||
document.querySelectorAll('.build-btn').forEach(button => {
|
||||
button.addEventListener('click', () => {
|
||||
const type = button.dataset.type;
|
||||
|
||||
currentBuildType = (currentBuildType === type) ? null : type;
|
||||
document.querySelectorAll('.build-btn').forEach(btn => btn.classList.toggle('active', btn === button && currentBuildType !== null));
|
||||
});
|
||||
@@ -367,13 +341,12 @@
|
||||
const playerDiv = document.createElement('div');
|
||||
playerDiv.className = 'player-div';
|
||||
if(name === nickname) playerDiv.classList.add('is-self');
|
||||
playerDiv.innerHTML = `<strong style="color: #${getPlayerColor(name).toString(16)}">${name}</strong>: $${Math.floor(p.money)} | Pop: ${p.population} | Hap: ${Math.round(p.happiness * 100)}%`;
|
||||
playerDiv.innerHTML = `<strong style="color: #${getPlayerColor(name).toString(16)}">${name}</strong>: $${Math.floor(p.money)} | Pop: ${p.population}`;
|
||||
listDiv.appendChild(playerDiv);
|
||||
|
||||
if (name === nickname) {
|
||||
document.getElementById('money-stat').textContent = `$${Math.floor(p.money)}`;
|
||||
document.getElementById('population-stat').textContent = p.population;
|
||||
document.getElementById('happiness-stat').textContent = `${Math.round(p.happiness * 100)}%`;
|
||||
document.querySelectorAll('.build-btn[data-type]').forEach(btn => {
|
||||
const type = btn.dataset.type;
|
||||
if (type !== 'remove' && buildingData[type]) {
|
||||
@@ -424,4 +397,3 @@
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user