Mise à jour de 'flask_base/templates/pokemon.html'

This commit is contained in:
serguei
2025-12-05 05:03:39 +00:00
parent 653d588374
commit 64bf7c3021

View File

@@ -1,17 +1,17 @@
<!DOCTYPE html>
<html lang="fr">
{% include 'head.html' %}
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jeu Pokémon</title>
<link rel="stylesheet" href="../static/style.css">
</head>
<body>
<header>
<img src="../static/pinguin(1).gif" alt="Mascotte animée" class="header-gif" />
<h1>Jeu type pokemon</h1>
{% include 'header.html' %}
</header>
{% include 'header.html' %}
<div class="battle">
<h2>Combat Pokémon-like (simple)</h2>
<h1>PROPRIMON</h1>
<style>
#log {
width: 90%;
@@ -32,11 +32,11 @@
<div class="leaderboard">
<h2>Classement des joueurs</h2>
<div id="leaderboardDiv">
</div>
</div>
<div class="battle">
<h2>Proprimon</h2>
<h2>Battez les logiciels propriétaires en utilisant leur alter-ego libre !</h2>
<div class="row">
<div id = "scoreDiv">Score: 0</div>
@@ -77,6 +77,22 @@
leaderboardDiv.appendChild(entryDiv);
});
});
//refresh every 10 seconds
setInterval(() => {
fetch("/api/leaderboard")
.then(response => response.json())
.then(data => {
leaderboardData = data["leaderboard"];
leaderboardData.sort((a, b) => b.score - a.score); // trier par score décroissant
leaderboardDiv.innerHTML = "";
leaderboardData.forEach((entry, index) => {
const entryDiv = document.createElement("div");
entryDiv.textContent = `${index + 1}. ${entry.name} - ${entry.score} ennemis vaincus`;
leaderboardDiv.appendChild(entryDiv);
});
});
}, 10000);
@@ -91,6 +107,8 @@
let score = 0;
const max = outils_list.length;
let playerInv = [];
let lastEnnemyNumber = -1;
let ennemyNumber = -1;
const log = document.getElementById("log");
const ennemyName = document.getElementById("ennemyName");
@@ -144,13 +162,14 @@
function setCombat(){
enemyHp = 30;
updateUI();
lastEnnemyNumber = ennemyNumber;
ennemyNumber = Math.floor(Math.random()*max);
//il faut que l'ennemi soit dans le against d'un des items du joueur
let found = false;
while(!found){
ennemyNumber = Math.floor(Math.random()*max);
for(let i=0; i<playerInv.length; i++){
if(getAgainstNames(playerInv[i].name) == outils_list[ennemyNumber].against_name){
if(getAgainstNames(playerInv[i].name) == outils_list[ennemyNumber].against_name && ennemyNumber != lastEnnemyNumber){
found = true;
break;
}
@@ -183,6 +202,20 @@
addLog(`${ennemyName.textContent} est vaincu !`);
addRandomItemToInventory();
score += 1;
if(score >= 50){
addLog("Félicitations ! Vous avez atteint le score maximum de 50 ennemis vaincus et remporté la partie !");
attacksDiv.innerHTML = ""; // Remove attack buttons
fetch("/api/leaderboard", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({name: prompt("Entrez votre nom"), score: score})
});
return;
}
updateUI();
attacksDiv.innerHTML = ""; // Clear attack buttons during transition
setCombat();
addLog("\nUn nouvel ennemi sauvage apparaît !");
return;
@@ -199,16 +232,24 @@
);
updateUI();
if (playerHp <= 0) {
addLog("Vous êtes K.O.");
addLog(`Score final : ${score} ennemis vaincus.`);
attacksDiv.innerHTML = ""; // Remove attack buttons
fetch("/api/leaderboard", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({name: prompt("Entrez votre nom"), score: score})
});
let nom = prompt("Entrez votre nom pour le classement");
if(nom){
addLog("Vous êtes K.O.");
addLog(`Score final : ${score} ennemis vaincus.`);
attacksDiv.innerHTML = ""; // Remove attack buttons
fetch("/api/leaderboard", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({name: nom, score: score})
});
}
else{
addLog("Vous êtes K.O");
addLog(`Score final : ${score} ennemis vaincus.`);
attacksDiv.innerHTML = ""; // Remove attack buttons
}
}
}, 500);
}
@@ -249,12 +290,18 @@
}
document.getElementById("runBtn").onclick = () => {
addLog("Vous avez fui le combat !");
fetch("/api/leaderboard", {
let nom = prompt("Entrez votre nom pour le classement");
if(nom){
addLog("Vous avez fui le combat !");
fetch("/api/leaderboard", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({name: prompt("Entrez votre nom"), score: score})
});
body: JSON.stringify({name: nom, score: score})
});
}
else{
addLog("Vous avez fui le combat !");
}
attacksDiv.innerHTML = ""; // Remove attack buttons
};