Mise à jour de 'flask_base/templates/pokemon.html'
This commit is contained in:
@@ -1,17 +1,17 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="fr">
|
<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>
|
<body>
|
||||||
|
|
||||||
<header>
|
|
||||||
<img src="../static/pinguin(1).gif" alt="Mascotte animée" class="header-gif" />
|
|
||||||
<h1>Jeu type pokemon</h1>
|
|
||||||
{% include 'header.html' %}
|
{% include 'header.html' %}
|
||||||
|
|
||||||
</header>
|
|
||||||
|
|
||||||
<div class="battle">
|
<div class="battle">
|
||||||
<h2>Combat Pokémon-like (simple)</h2>
|
<h1>PROPRIMON</h1>
|
||||||
<style>
|
<style>
|
||||||
#log {
|
#log {
|
||||||
width: 90%;
|
width: 90%;
|
||||||
@@ -32,11 +32,11 @@
|
|||||||
<div class="leaderboard">
|
<div class="leaderboard">
|
||||||
<h2>Classement des joueurs</h2>
|
<h2>Classement des joueurs</h2>
|
||||||
<div id="leaderboardDiv">
|
<div id="leaderboardDiv">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="battle">
|
<div class="battle">
|
||||||
<h2>Proprimon</h2>
|
<h2>Battez les logiciels propriétaires en utilisant leur alter-ego libre !</h2>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div id = "scoreDiv">Score: 0</div>
|
<div id = "scoreDiv">Score: 0</div>
|
||||||
@@ -78,6 +78,22 @@
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//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;
|
let score = 0;
|
||||||
const max = outils_list.length;
|
const max = outils_list.length;
|
||||||
let playerInv = [];
|
let playerInv = [];
|
||||||
|
let lastEnnemyNumber = -1;
|
||||||
|
let ennemyNumber = -1;
|
||||||
|
|
||||||
const log = document.getElementById("log");
|
const log = document.getElementById("log");
|
||||||
const ennemyName = document.getElementById("ennemyName");
|
const ennemyName = document.getElementById("ennemyName");
|
||||||
@@ -144,13 +162,14 @@
|
|||||||
function setCombat(){
|
function setCombat(){
|
||||||
enemyHp = 30;
|
enemyHp = 30;
|
||||||
updateUI();
|
updateUI();
|
||||||
|
lastEnnemyNumber = ennemyNumber;
|
||||||
ennemyNumber = Math.floor(Math.random()*max);
|
ennemyNumber = Math.floor(Math.random()*max);
|
||||||
//il faut que l'ennemi soit dans le against d'un des items du joueur
|
//il faut que l'ennemi soit dans le against d'un des items du joueur
|
||||||
let found = false;
|
let found = false;
|
||||||
while(!found){
|
while(!found){
|
||||||
ennemyNumber = Math.floor(Math.random()*max);
|
ennemyNumber = Math.floor(Math.random()*max);
|
||||||
for(let i=0; i<playerInv.length; i++){
|
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;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -183,6 +202,20 @@
|
|||||||
addLog(`${ennemyName.textContent} est vaincu !`);
|
addLog(`${ennemyName.textContent} est vaincu !`);
|
||||||
addRandomItemToInventory();
|
addRandomItemToInventory();
|
||||||
score += 1;
|
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();
|
setCombat();
|
||||||
addLog("\nUn nouvel ennemi sauvage apparaît !");
|
addLog("\nUn nouvel ennemi sauvage apparaît !");
|
||||||
return;
|
return;
|
||||||
@@ -201,15 +234,23 @@
|
|||||||
updateUI();
|
updateUI();
|
||||||
|
|
||||||
if (playerHp <= 0) {
|
if (playerHp <= 0) {
|
||||||
|
let nom = prompt("Entrez votre nom pour le classement");
|
||||||
|
if(nom){
|
||||||
addLog("Vous êtes K.O.");
|
addLog("Vous êtes K.O.");
|
||||||
addLog(`Score final : ${score} ennemis vaincus.`);
|
addLog(`Score final : ${score} ennemis vaincus.`);
|
||||||
attacksDiv.innerHTML = ""; // Remove attack buttons
|
attacksDiv.innerHTML = ""; // Remove attack buttons
|
||||||
fetch("/api/leaderboard", {
|
fetch("/api/leaderboard", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {"Content-Type": "application/json"},
|
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 êtes K.O");
|
||||||
|
addLog(`Score final : ${score} ennemis vaincus.`);
|
||||||
|
attacksDiv.innerHTML = ""; // Remove attack buttons
|
||||||
|
}
|
||||||
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,12 +290,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("runBtn").onclick = () => {
|
document.getElementById("runBtn").onclick = () => {
|
||||||
|
let nom = prompt("Entrez votre nom pour le classement");
|
||||||
|
if(nom){
|
||||||
addLog("Vous avez fui le combat !");
|
addLog("Vous avez fui le combat !");
|
||||||
fetch("/api/leaderboard", {
|
fetch("/api/leaderboard", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {"Content-Type": "application/json"},
|
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
|
attacksDiv.innerHTML = ""; // Remove attack buttons
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user