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-scale=1.0">
|
| 6 |
+
<title>Jeu des 3 Gobelets - Thimble Game</title>
|
| 7 |
+
<!-- Importation de FontAwesome pour les icônes -->
|
| 8 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 9 |
+
|
| 10 |
+
<style>
|
| 11 |
+
:root {
|
| 12 |
+
--primary-color: #ff4757;
|
| 13 |
+
--secondary-color: #2ed573;
|
| 14 |
+
--bg-color: #2f3542;
|
| 15 |
+
--table-color: #1e3728; /* Vert table de jeu */
|
| 16 |
+
--cup-color: #f1c40f;
|
| 17 |
+
--cup-border: #d4ac0d;
|
| 18 |
+
--text-color: #ffffff;
|
| 19 |
+
--accent-color: #3742fa;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
* {
|
| 23 |
+
box-sizing: border-box;
|
| 24 |
+
margin: 0;
|
| 25 |
+
padding: 0;
|
| 26 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
body {
|
| 30 |
+
background-color: var(--bg-color);
|
| 31 |
+
color: var(--text-color);
|
| 32 |
+
display: flex;
|
| 33 |
+
flex-direction: column;
|
| 34 |
+
min-height: 100vh;
|
| 35 |
+
overflow-x: hidden;
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
/* En-tête */
|
| 39 |
+
header {
|
| 40 |
+
background-color: rgba(0, 0, 0, 0.8);
|
| 41 |
+
padding: 1rem 2rem;
|
| 42 |
+
display: flex;
|
| 43 |
+
justify-content: space-between;
|
| 44 |
+
align-items: center;
|
| 45 |
+
box-shadow: 0 2px 10px rgba(0,0,0,0.3);
|
| 46 |
+
z-index: 100;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
h1 {
|
| 50 |
+
font-size: 1.5rem;
|
| 51 |
+
display: flex;
|
| 52 |
+
align-items: center;
|
| 53 |
+
gap: 10px;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
.anycoder-link {
|
| 57 |
+
color: var(--secondary-color);
|
| 58 |
+
text-decoration: none;
|
| 59 |
+
font-weight: bold;
|
| 60 |
+
font-size: 0.9rem;
|
| 61 |
+
border: 1px solid var(--secondary-color);
|
| 62 |
+
padding: 5px 10px;
|
| 63 |
+
border-radius: 4px;
|
| 64 |
+
transition: all 0.3s ease;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.anycoder-link:hover {
|
| 68 |
+
background-color: var(--secondary-color);
|
| 69 |
+
color: #fff;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
/* Zone principale du jeu */
|
| 73 |
+
main {
|
| 74 |
+
flex: 1;
|
| 75 |
+
display: flex;
|
| 76 |
+
flex-direction: column;
|
| 77 |
+
align-items: center;
|
| 78 |
+
justify-content: center;
|
| 79 |
+
background: radial-gradient(circle at center, var(--table-color), #0f1f15);
|
| 80 |
+
padding: 20px;
|
| 81 |
+
position: relative;
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
/* Panneau de contrôle et score */
|
| 85 |
+
.game-info {
|
| 86 |
+
background: rgba(0, 0, 0, 0.5);
|
| 87 |
+
padding: 15px 30px;
|
| 88 |
+
border-radius: 50px;
|
| 89 |
+
display: flex;
|
| 90 |
+
gap: 20px;
|
| 91 |
+
margin-bottom: 40px;
|
| 92 |
+
backdrop-filter: blur(5px);
|
| 93 |
+
border: 1px solid rgba(255,255,255,0.1);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
.score-box {
|
| 97 |
+
font-size: 1.2rem;
|
| 98 |
+
font-weight: bold;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
.score-value {
|
| 102 |
+
color: var(--secondary-color);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
.status-message {
|
| 106 |
+
color: #fff;
|
| 107 |
+
font-weight: 500;
|
| 108 |
+
text-align: center;
|
| 109 |
+
min-width: 200px;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
/* Table de jeu */
|
| 113 |
+
.game-table {
|
| 114 |
+
position: relative;
|
| 115 |
+
width: 100%;
|
| 116 |
+
max-width: 800px;
|
| 117 |
+
height: 300px;
|
| 118 |
+
display: flex;
|
| 119 |
+
justify-content: center;
|
| 120 |
+
align-items: flex-end;
|
| 121 |
+
padding-bottom: 20px;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
/* Les gobelets */
|
| 125 |
+
.cup-container {
|
| 126 |
+
position: absolute;
|
| 127 |
+
bottom: 0;
|
| 128 |
+
width: 100px;
|
| 129 |
+
height: 140px;
|
| 130 |
+
cursor: pointer;
|
| 131 |
+
transition: transform 0.4s ease-in-out; /* Animation fluide pour le mélange */
|
| 132 |
+
z-index: 10;
|
| 133 |
+
/* Les positions seront définies par JS, mais voici une base */
|
| 134 |
+
left: 50%;
|
| 135 |
+
transform: translateX(-50%);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
.cup-body {
|
| 139 |
+
width: 100%;
|
| 140 |
+
height: 100%;
|
| 141 |
+
background: linear-gradient(135deg, var(--cup-color), var(--cup-border));
|
| 142 |
+
border-radius: 5px 5px 40px 40px;
|
| 143 |
+
position: relative;
|
| 144 |
+
box-shadow: 0 10px 20px rgba(0,0,0,0.5);
|
| 145 |
+
display: flex;
|
| 146 |
+
justify-content: center;
|
| 147 |
+
align-items: center;
|
| 148 |
+
overflow: visible;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
/* Effet de brillance/relief sur le gobelet */
|
| 152 |
+
.cup-body::after {
|
| 153 |
+
content: '';
|
| 154 |
+
position: absolute;
|
| 155 |
+
top: 0;
|
| 156 |
+
left: 10px;
|
| 157 |
+
width: 20px;
|
| 158 |
+
height: 90%;
|
| 159 |
+
background: rgba(255,255,255,0.2);
|
| 160 |
+
border-radius: 50px;
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
/* Intérieur du gobelet (pour masquer la boule) */
|
| 164 |
+
.cup-inside {
|
| 165 |
+
position: absolute;
|
| 166 |
+
top: 5px;
|
| 167 |
+
left: 5px;
|
| 168 |
+
right: 5px;
|
| 169 |
+
height: 100%;
|
| 170 |
+
background: #000;
|
| 171 |
+
border-radius: 0 0 35px 35px;
|
| 172 |
+
z-index: -1;
|
| 173 |
+
opacity: 0.3;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
/* La boule */
|
| 177 |
+
.ball {
|
| 178 |
+
position: absolute;
|
| 179 |
+
bottom: 10px;
|
| 180 |
+
width: 40px;
|
| 181 |
+
height: 40px;
|
| 182 |
+
background: radial-gradient(circle at 30% 30%, #ff6b6b, #c0392b);
|
| 183 |
+
border-radius: 50%;
|
| 184 |
+
box-shadow: 0 5px 15px rgba(0,0,0,0.5);
|
| 185 |
+
z-index: 5; /* Derrière le gobelet si le gobelet est opaque, mais ici on gère l'affichage */
|
| 186 |
+
display: none; /* Cachée par défaut ou gérée par JS */
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/* Animation de soulèvement du gobelet */
|
| 190 |
+
.cup-container.lift .cup-body {
|
| 191 |
+
transform: translateY(-80px);
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
/* Ombre au sol */
|
| 195 |
+
.shadow {
|
| 196 |
+
position: absolute;
|
| 197 |
+
bottom: -10px;
|
| 198 |
+
left: 10%;
|
| 199 |
+
width: 80%;
|
| 200 |
+
height: 10px;
|
| 201 |
+
background: rgba(0,0,0,0.4);
|
| 202 |
+
border-radius: 50%;
|
| 203 |
+
filter: blur(3px);
|
| 204 |
+
transition: transform 0.4s;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
.cup-container.lift .shadow {
|
| 208 |
+
transform: scale(0.5);
|
| 209 |
+
opacity: 0.2;
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
/* Boutons */
|
| 213 |
+
.btn {
|
| 214 |
+
background-color: var(--accent-color);
|
| 215 |
+
color: white;
|
| 216 |
+
border: none;
|
| 217 |
+
padding: 12px 30px;
|
| 218 |
+
font-size: 1.1rem;
|
| 219 |
+
border-radius: 30px;
|
| 220 |
+
cursor: pointer;
|
| 221 |
+
box-shadow: 0 4px 15px rgba(55, 66, 250, 0.4);
|
| 222 |
+
transition: transform 0.2s, background-color 0.2s;
|
| 223 |
+
margin-top: 50px;
|
| 224 |
+
}
|
| 225 |
+
|
| 226 |
+
.btn:hover {
|
| 227 |
+
background-color: #5352ed;
|
| 228 |
+
transform: translateY(-2px);
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
.btn:disabled {
|
| 232 |
+
background-color: #747d8c;
|
| 233 |
+
cursor: not-allowed;
|
| 234 |
+
transform: none;
|
| 235 |
+
box-shadow: none;
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
/* Responsive */
|
| 239 |
+
@media (max-width: 600px) {
|
| 240 |
+
.cup-container {
|
| 241 |
+
width: 70px;
|
| 242 |
+
height: 100px;
|
| 243 |
+
}
|
| 244 |
+
.game-table {
|
| 245 |
+
height: 200px;
|
| 246 |
+
}
|
| 247 |
+
.game-info {
|
| 248 |
+
flex-direction: column;
|
| 249 |
+
gap: 10px;
|
| 250 |
+
text-align: center;
|
| 251 |
+
}
|
| 252 |
+
}
|
| 253 |
+
</style>
|
| 254 |
+
</head>
|
| 255 |
+
<body>
|
| 256 |
+
|
| 257 |
+
<header>
|
| 258 |
+
<h1><i class="fas fa-dice"></i> Jeu des Gobelets</h1>
|
| 259 |
+
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="anycoder-link">Built with anycoder</a>
|
| 260 |
+
</header>
|
| 261 |
+
|
| 262 |
+
<main>
|
| 263 |
+
<div class="game-info">
|
| 264 |
+
<div class="status-message" id="statusMessage">Prêt à jouer ?</div>
|
| 265 |
+
<div class="score-box">Score: <span id="scoreValue" class="score-value">0</span></div>
|
| 266 |
+
</div>
|
| 267 |
+
|
| 268 |
+
<div class="game-table" id="gameTable">
|
| 269 |
+
<!-- La boule sera positionnée absolument sous les gobelets -->
|
| 270 |
+
<div class="ball" id="ball"></div>
|
| 271 |
+
|
| 272 |
+
<!-- Gobelet 0 -->
|
| 273 |
+
<div class="cup-container" id="cup0" onclick="handleCupClick(0)">
|
| 274 |
+
<div class="cup-body">
|
| 275 |
+
<div class="cup-inside"></div>
|
| 276 |
+
</div>
|
| 277 |
+
<div class="shadow"></div>
|
| 278 |
+
</div>
|
| 279 |
+
|
| 280 |
+
<!-- Gobelet 1 -->
|
| 281 |
+
<div class="cup-container" id="cup1" onclick="handleCupClick(1)">
|
| 282 |
+
<div class="cup-body">
|
| 283 |
+
<div class="cup-inside"></div>
|
| 284 |
+
</div>
|
| 285 |
+
<div class="shadow"></div>
|
| 286 |
+
</div>
|
| 287 |
+
|
| 288 |
+
<!-- Gobelet 2 -->
|
| 289 |
+
<div class="cup-container" id="cup2" onclick="handleCupClick(2)">
|
| 290 |
+
<div class="cup-body">
|
| 291 |
+
<div class="cup-inside"></div>
|
| 292 |
+
</div>
|
| 293 |
+
<div class="shadow"></div>
|
| 294 |
+
</div>
|
| 295 |
+
</div>
|
| 296 |
+
|
| 297 |
+
<button class="btn" id="startBtn" onclick="startGame()">Commencer la partie</button>
|
| 298 |
+
</main>
|
| 299 |
+
|
| 300 |
+
<script>
|
| 301 |
+
// Variables d'état du jeu
|
| 302 |
+
let score = 0;
|
| 303 |
+
let isShuffling = false;
|
| 304 |
+
let canPick = false;
|
| 305 |
+
let ballPosition = 1; // 0, 1 ou 2 (Centre par défaut)
|
| 306 |
+
|
| 307 |
+
// Configuration des positions (en pourcentage de la largeur de la table)
|
| 308 |
+
const positions = [15, 50, 85]; // Gauche, Centre, Droite
|
| 309 |
+
|
| 310 |
+
// Éléments DOM
|
| 311 |
+
const cups = [
|
| 312 |
+
document.getElementById('cup0'),
|
| 313 |
+
document.getElementById('cup1'),
|
| 314 |
+
document.getElementById('cup2')
|
| 315 |
+
];
|
| 316 |
+
const ball = document.getElementById('ball');
|
| 317 |
+
const startBtn = document.getElementById('startBtn');
|
| 318 |
+
const statusMsg = document.getElementById('statusMessage');
|
| 319 |
+
const scoreDisplay = document.getElementById('scoreValue');
|
| 320 |
+
|
| 321 |
+
// Initialisation des positions visuelles
|
| 322 |
+
function initPositions() {
|
| 323 |
+
cups.forEach((cup, index) => {
|
| 324 |
+
cup.style.left = `${positions[index]}%`;
|
| 325 |
+
cup.style.transform = 'translateX(-50%)';
|
| 326 |
+
cup.classList.remove('lift');
|
| 327 |
+
});
|
| 328 |
+
updateBallPosition();
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
// Met à jour la position de la boule pour qu'elle soit sous le bon gobelet
|
| 332 |
+
function updateBallPosition() {
|
| 333 |
+
// Trouver quel gobelet est actuellement à la position logique où se trouve la boule
|
| 334 |
+
// Note: Dans notre logique, 'ballPosition' est l'index du gobelet qui cache la boule.
|
| 335 |
+
// Mais visuellement, les gobelets bougent.
|
| 336 |
+
|
| 337 |
+
// Simplification : On place la boule visuellement sous le gobelet qui a l'index 'ballPosition'
|
| 338 |
+
// Comme les gobelets ont des ID fixes (cup0, cup1, cup2), on place la balle sous l'élément DOM correspondant.
|
| 339 |
+
|
| 340 |
+
const targetCup = cups[ballPosition];
|
| 341 |
+
const cupRect = targetCup.getBoundingClientRect();
|
| 342 |
+
const tableRect = document.getElementById('gameTable').getBoundingClientRect();
|
| 343 |
+
|
| 344 |
+
// Calculer la position relative à la table
|
| 345 |
+
// On centre la boule par rapport au gobelet
|
| 346 |
+
const ballLeft = targetCup.offsetLeft + (targetCup.offsetWidth / 2) - 20; // 20 est la moitié de la largeur de la balle
|
| 347 |
+
|
| 348 |
+
ball.style.left = `${ballLeft}px`;
|
| 349 |
+
ball.style.bottom = '20px';
|
| 350 |
+
ball.style.display = 'block';
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
// Fonction utilitaire pour attendre (sleep)
|
| 354 |
+
function sleep(ms) {
|
| 355 |
+
return new Promise(resolve => setTimeout(resolve, ms));
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
// Mélanger les gobelets (Algorithme d'échange)
|
| 359 |
+
async function shuffleCups() {
|
| 360 |
+
isShuffling = true;
|
| 361 |
+
canPick = false;
|
| 362 |
+
statusMsg.textContent = "Regardez bien...";
|
| 363 |
+
startBtn.disabled = true;
|
| 364 |
+
|
| 365 |
+
// Nombre de swaps
|
| 366 |
+
const swaps = 5 + Math.floor(Math.random() * 5); // 5 à 10 swaps
|
| 367 |
+
let speed = 500; // Vitesse initiale en ms
|
| 368 |
+
|
| 369 |
+
for (let i = 0; i < swaps; i++) {
|
| 370 |
+
// Choisir deux gobelets au hasard à échanger
|
| 371 |
+
let idx1 = Math.floor(Math.random() * 3);
|
| 372 |
+
let idx2 = Math.floor(Math.random() * 3);
|
| 373 |
+
while (idx1 === idx2) {
|
| 374 |
+
idx2 = Math.floor(Math.random() * 3);
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
// Échanger les positions visuelles
|
| 378 |
+
// On stocke les positions actuelles (left %)
|
| 379 |
+
let pos1 = cups[idx1].style.left;
|
| 380 |
+
let pos2 = cups[idx2].style.left;
|
| 381 |
+
|
| 382 |
+
cups[idx1].style.left = pos2;
|
| 383 |
+
cups[idx2].style.left = pos1;
|
| 384 |
+
|
| 385 |
+
// Attendre un peu avant le prochain mouvement
|
| 386 |
+
await sleep(speed);
|
| 387 |
+
|
| 388 |
+
// Accélérer légèrement à chaque swap pour rendre difficile
|
| 389 |
+
if (speed > 200) speed -= 30;
|
| 390 |
+
}
|
| 391 |
+
|
| 392 |
+
isShuffling = false;
|
| 393 |
+
canPick = true;
|
| 394 |
+
statusMsg.textContent = "Où est la boule ?";
|
| 395 |
+
}
|
| 396 |
+
|
| 397 |
+
// Démarrer le jeu
|
| 398 |
+
async function startGame() {
|
| 399 |
+
// Révéler la boule au début
|
| 400 |
+
ballPosition = Math.floor(Math.random() * 3); // Choisir un gobelet aléatoire
|
| 401 |
+
|
| 402 |
+
// S'assurer que tout est remis à zéro
|
| 403 |
+
initPositions();
|
| 404 |
+
|
| 405 |
+
// Lever le gobelet pour montrer la boule
|
| 406 |
+
cups[ballPosition].classList.add('lift');
|
| 407 |
+
statusMsg.textContent = "Mémorisez la position...";
|
| 408 |
+
startBtn.disabled = true;
|
| 409 |
+
|
| 410 |
+
await sleep(1500); // Attendre 1.5 seconde
|
| 411 |
+
|
| 412 |
+
// Cacher la boule (baisser le gobelet)
|
| 413 |
+
cups[ballPosition].classList.remove('lift');
|
| 414 |
+
|
| 415 |
+
await sleep(500);
|
| 416 |
+
|
| 417 |
+
// Commencer le mélange
|
| 418 |
+
await shuffleCups();
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
// Gérer le clic sur un gobelet
|
| 422 |
+
function handleCupClick(index) {
|
| 423 |
+
if (!canPick || isShuffling) return;
|
| 424 |
+
|
| 425 |
+
canPick = false; // Empêcher les clics multiples
|
| 426 |
+
const clickedCup = cups[index];
|
| 427 |
+
|
| 428 |
+
// Lever le gobelet cliqué
|
| 429 |
+
clickedCup.classList.add('lift');
|
| 430 |
+
|
| 431 |
+
if (index === ballPosition) {
|
| 432 |
+
// Gagné
|
| 433 |
+
score += 10;
|
| 434 |
+
statusMsg.textContent = "Bravo ! Vous avez trouvé ! +10 points";
|
| 435 |
+
statusMsg.style.color = "var(--secondary-color)";
|
| 436 |
+
} else {
|
| 437 |
+
// Perdu
|
| 438 |
+
statusMsg.textContent = "Perdu ! La boule était ailleurs.";
|
| 439 |
+
statusMsg.style.color = "var(--primary-color)";
|
| 440 |
+
|
| 441 |
+
// Montrer où était la vraie boule après un délai
|
| 442 |
+
setTimeout(() => {
|
| 443 |
+
cups[ballPosition].classList.add('lift');
|
| 444 |
+
}, 500);
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
// Mettre à jour le score
|
| 448 |
+
scoreDisplay.textContent = score;
|
| 449 |
+
startBtn.disabled = false;
|
| 450 |
+
startBtn.textContent = "Rejouer";
|
| 451 |
+
}
|
| 452 |
+
|
| 453 |
+
// Initialisation au chargement
|
| 454 |
+
window.onload = () => {
|
| 455 |
+
initPositions();
|
| 456 |
+
ball.style.display = 'none'; // Cacher la boule au tout début
|
| 457 |
+
};
|
| 458 |
+
|
| 459 |
+
// Gestion du redimensionnement pour garder la boule alignée
|
| 460 |
+
window.onresize = () => {
|
| 461 |
+
if (!isShuffling) {
|
| 462 |
+
updateBallPosition();
|
| 463 |
+
}
|
| 464 |
+
};
|
| 465 |
+
|
| 466 |
+
</script>
|
| 467 |
+
</body>
|
| 468 |
+
</html>
|