<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ma Petite Ville - City Builder</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #2c3e50;
color: white;
display: flex;
flex-direction: column;
align-items: center;
margin: 0;
}
#stats {
background: #34495e;
padding: 20px;
border-radius: 0 0 20px 20px;
display: flex;
gap: 30px;
font-size: 20px;
box-shadow: 0 4px 10px rgba(0,0,0,0.3);
margin-bottom: 20px;
}
.stat-item { font-weight: bold; }
.money { color: #2ecc71; }
.pop { color: #3498db; }
#game-grid {
display: grid;
grid-template-columns: repeat(10, 40px);
grid-template-rows: repeat(10, 40px);
gap: 2px;
background-color: #7f8c8d;
border: 5px solid #7f8c8d;
box-shadow: 0 0 20px rgba(0,0,0,0.5);
}
.cell {
width: 40px;
height: 40px;
background-color: #27ae60; /* Couleur herbe */
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
font-size: 20px;
transition: background 0.2s;
}
.cell:hover {
background-color: #2ecc71;
}
#controls {
margin-top: 20px;
display: flex;
gap: 10px;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border: none;
border-radius: 5px;
transition: transform 0.1s;
font-weight: bold;
}
button:active { transform: scale(0.95); }
.btn-house { background-color: #f1c40f; color: black; }
.btn-factory { background-color: #95a5a6; color: black; }
.btn-delete { background-color: #e74c3c; color: white; }
.selected {
outline: 3px solid white;
box-shadow: 0 0 10px white;
}
</style>
</head>
<body>
<h1>🏙️ Ma Petite Ville</h1>
<div id="stats">
<div class="stat-item">Argent: <span id="money" class="money">100</span> €</div>
<div class="stat-item">Population: <span id="pop" class="pop">0</span> 👥</div>
</div>
<div id="game-grid"></div>
<div id="controls">
<button id="houseBtn" class="btn-house" onclick="setTool('house')">🏠 Maison (20€)</button>
<button id="factoryBtn" class="btn-factory" onclick="setTool('factory')">🏭 Usine (50€)</button>
<button id="deleteBtn" class="btn-delete" onclick="setTool('delete')">🗑️ Détruire</button>
</div>
<p>L'usine génère de l'argent toutes les 2 secondes !</p>
<script>
// Variables de jeu
let money = 100;
let population = 0;
let currentTool = 'house';
let factoriesCount = 0;
let housesCount = 0;
const moneyEl = document.getElementById('money');
const popEl = document.getElementById('pop');
const grid = document.getElementById('game-grid');
// Initialisation de la grille (10x10)
function createGrid() {
for (let i = 0; i < 100; i++) {
const cell = document.createElement('div');
cell.classList.add('cell');
cell.onclick = () => placeBuilding(cell);
grid.appendChild(cell);
}
}
// Choisir l'outil
function setTool(tool) {
currentTool = tool;
document.querySelectorAll('button').forEach(btn => btn.classList.remove('selected'));
if(tool === 'house') document.getElementById('houseBtn').classList.add('selected');
if(tool === 'factory') document.getElementById('factoryBtn').classList.add('selected');
if(tool === 'delete') document.getElementById('deleteBtn').classList.add('selected');
}
// Placer un bâtiment
function placeBuilding(cell) {
if (currentTool === 'house') {
if (money >= 20 && cell.innerText === "") {
money -= 20;
population += 5;
housesCount++;
cell.innerText = "🏠";
}
} else if (currentTool === 'factory') {
if (money >= 50 && cell.innerText === "") {
money -= 50;
factoriesCount++;
cell.innerText = "🏭";
}
} else if (currentTool === 'delete') {
if (cell.innerText === "🏠") {
population -= 5;
housesCount--;
} else if (cell.innerText === "🏭") {
factoriesCount--;
}
cell.innerText = "";
}
updateStats();
}
// Mise à jour de l'affichage
function updateStats() {
moneyEl.innerText = money;
popEl.innerText = population;
}
// Boucle d'économie (Gagner de l'argent avec les usines)
setInterval(() => {
if (factoriesCount > 0) {
money += factoriesCount * 5; // Chaque usine rapporte 5€
updateStats();
}
}, 2000);
// Lancement
createGrid();
setTool('house');
</script>
</body>
</html>