Riichi/frontend/pages/riichi/chap5.html
2026-02-25 16:59:57 +01:00

199 lines
No EOL
5 KiB
HTML

<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Tuto Riichi</title>
<link rel="stylesheet" href="/frontend/css/style.css">
<link rel="stylesheet" href="/frontend/css/text.css">
<link rel="stylesheet" href="/frontend/css/speech-bubble.css">
<link rel="stylesheet" href="/frontend/css/hand.css">
<style>
#menu {
position: relative;
z-index: 10;
}
#mascotte {
position: absolute;
top: 670px;
right: 100px;
z-index: 999;
transform: scaleX(-1);
cursor: pointer;
}
#mascotte img {
width: 250px;
height: auto;
display: block;
}
.speech-bubble {
position: absolute;
top: 250px;
right: 170px;
z-index: 1;
display: none;
}
.speech-bubble.visible {
display: flex;
}
#tiles-container {
display: flex;
justify-content: center;
align-items: flex-start;
gap: 10px;
padding: 20px;
}
:root {
--game_radius: 1100px;
}
#game-center {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
}
#game {
position: relatives;
width: var(--game_radius);
height: var(--game_radius);
}
#hand-0 {
position: absolute;
transform: translate(-50%, 50%);
bottom: -10%;
left: 50%;
display: flex;
flex-direction: row;
align-items: flex-end;
gap: 5px;
padding: 20px 0 0 20px;
}
#hand-1 {
position: absolute;
transform: translate(-50%, -400%) rotate(-90deg) translate(0%, 450%);
bottom: -10%;
left: 50%;
display: flex;
flex-direction: row;
align-items: flex-end;
gap: 5px;
padding: 20px 0 0 20px;
}
#hand-2 {
position: absolute;
transform: translate(-50%, -400%) rotate(180deg) translate(0%, 450%);
bottom: -10%;
left: 50%;
display: flex;
flex-direction: row;
align-items: flex-end;
gap: 5px;
padding: 20px 0 0 20px;
}
#hand-3 {
position: absolute;
transform: translate(-50%, -400%) rotate(90deg) translate(0%, 450%);
bottom: -10%;
left: 50%;
display: flex;
flex-direction: row;
align-items: flex-end;
gap: 5px;
padding: 20px 0 0 20px;
}
</style>
</head>
<body>
<div id="menu"></div>
<h1>Chapitre 5</h1>
<div class="speech-bubble">
<div class="speech-text" id="speech-text"></div>
</div>
<div id="mascotte"></div>
<div id="game-center">
<div id="game">
<div id="hand-0"></div>
<div id="hand-1"></div>
<div id="hand-2"></div>
<div id="hand-3"></div>
</div>
</div>
<script src="/frontend/js/fr/texts.js"></script>
<script>
// Charger le menu
fetch('/components/menu.html')
.then(r => r.text())
.then(html => document.getElementById('menu').innerHTML = html);
// Afficher la mascotte et le texte
const mascolteEl = document.getElementById('mascotte');
mascolteEl.innerHTML = '<img src="/img/tilineau/idle.png" alt="Tilineau">';
document.getElementById('speech-text').innerHTML = texts.riichi.chap5;
// Toggle bulle de dialogue au clic sur la mascotte
const speechBubble = document.querySelector('.speech-bubble');
mascolteEl.addEventListener('click', () => {
speechBubble.classList.toggle('visible');
mascolteEl.innerHTML = speechBubble.classList.contains('visible')
? '<img class="explaining" src="/img/tilineau/explaining.png" alt="Tilineau">'
: '<img src="/img/tilineau/idle.png" alt="Tilineau">';
});
// Initialiser une partie au chargement du chapitre 5
fetch('/api/game/start', { method: 'POST' })
.then(r => r.json())
.then(data => {
console.log('Réponse API', data);
if (data.state && data.state.hand_player) {
displayHand(data.state.hand_player, 'hand-0');
// joueur 1
fetch('/api/game/hand/1')
.then(r => r.json())
.then(botData => {
if (botData.hand) {
displayHand(botData.hand, 'hand-1');
}
});
// joueur 2
fetch('/api/game/hand/2')
.then(r => r.json())
.then(botData => {
if (botData.hand) {
displayHand(botData.hand, 'hand-2');
}
});
// joueur 3
fetch('/api/game/hand/3')
.then(r => r.json())
.then(botData => {
if (botData.hand) {
displayHand(botData.hand, 'hand-3');
}
});
}
})
.catch(e => console.error('Erreur initialisation partie', e));
function displayHand(hand, displayId) {
const display = document.getElementById(displayId);
display.innerHTML = '';
hand.forEach(tile => {
const tileDiv = document.createElement('div');
tileDiv.innerHTML = tile.svg;
display.appendChild(tileDiv);
});
}
</script>
</body>
</html>