Skip to content
Snippets Groups Projects
Commit 7767c770 authored by Mamadu-lamarana Bah's avatar Mamadu-lamarana Bah :speech_balloon:
Browse files

gestion de la fin de l'enchère

parent b90269f3
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<div class="item">Prix actuel : <span class="prix"></span> </div> <div class="item">Prix actuel : <span class="prix"></span> </div>
</div> </div>
<div class="price-options"> <div id="buttons" class="price-options">
<p>Enchères possibles :</p> <p>Enchères possibles :</p>
<button class="price-button">20€</button> <button class="price-button">20€</button>
<button class="price-button">50€</button> <button class="price-button">50€</button>
......
...@@ -5,7 +5,11 @@ const socket = io(); ...@@ -5,7 +5,11 @@ const socket = io();
const inputName = document.getElementById("name"); const inputName = document.getElementById("name");
const inputValue = document.getElementById("value"); const inputValue = document.getElementById("value");
const buttonStart = document.getElementById("start"); const buttonStart = document.getElementById("start");
const buttonSale = document.getElementById("sale"); const buttonSale = document.getElementById("sale");
buttonSale.addEventListener("click", saleProduct);
socket.emit("auctioneer");
const prixActuel = document.getElementById("prixactuel"); const prixActuel = document.getElementById("prixactuel");
prixActuel.textContent = inputValue.value+""; prixActuel.textContent = inputValue.value+"";
...@@ -29,8 +33,14 @@ function startEnchere() { ...@@ -29,8 +33,14 @@ function startEnchere() {
buttonSale.disabled = false; buttonSale.disabled = false;
ident.textContent = `Debut de l'enchère pour ${inputName.value} à ${inputValue.value}€`; ident.textContent = `Debut de l'enchère pour ${inputName.value} à ${inputValue.value}€`;
socket.emit("infos", inputName.value, inputValue.value); socket.emit("infos", inputName.value, inputValue.value);
socket.on("prixActuel", (nouveauPrix, sock) => updatePrix(nouveauPrix, sock)); socket.on("changePrix", (nouveauPrix, sock) => updatePrix(nouveauPrix, sock));
waitForNewEnchere(); waitForNewEnchere(true);
}
function saleProduct() {
ident.textContent = `Fin de l'enchère. Un ${inputName.value} à ${prixActuel.textContent}`;
socket.emit("adjuge");
waitForNewEnchere(false);
} }
function updatePrix(nouveauPrix, sock) { function updatePrix(nouveauPrix, sock) {
...@@ -38,10 +48,10 @@ function updatePrix(nouveauPrix, sock) { ...@@ -38,10 +48,10 @@ function updatePrix(nouveauPrix, sock) {
ident.textContent = `Nouvelle enchère réçu de ${sock}`; ident.textContent = `Nouvelle enchère réçu de ${sock}`;
} }
function waitForNewEnchere() { function waitForNewEnchere(disabled) {
inputName.disabled = true; inputName.disabled = disabled;
inputValue.disabled = true; inputValue.disabled = disabled;
buttonStart.disabled = true; buttonStart.disabled = disabled;
} }
...@@ -6,31 +6,50 @@ const ident = document.getElementById("ident-bid"); ...@@ -6,31 +6,50 @@ const ident = document.getElementById("ident-bid");
const description = document.getElementsByClassName("description"); const description = document.getElementsByClassName("description");
const prix = document.getElementsByClassName("prix"); const prix = document.getElementsByClassName("prix");
displayButton("none");
const buttons = document.querySelectorAll("button");
for(const button of buttons) {
button.addEventListener("click", selectPrice);
}
function displayButton(display) {
const divButtons = document.getElementById("buttons");
divButtons.style.display = display;
}
let prixActuel = 0; let prixActuel = 0;
socket.on("infos", (name, value) => { socket.on("infos", (name, value) => {
ident.textContent = `Une nouvelle enchère commence`; ident.textContent = `Une nouvelle enchère commence`;
enchereBegin(name, value); enchereBegin(name, value);
displayButton("block");
socket.on("changePrix", (nouveauPrix) => {changePrix(nouveauPrix)});
}); });
function changePrix(nouveauPrix) {
prix[0].textContent = nouveauPrix+"";
prixActuel = nouveauPrix;
}
function enchereBegin(name, value) { function enchereBegin(name, value) {
description[0].textContent = name; description[0].textContent = name;
prix[0].textContent = value+""; prix[0].textContent = value+"";
prixActuel += parseInt(prix[0].textContent); prixActuel = parseInt(prix[0].textContent);
} }
const buttons = document.querySelectorAll("button");
for(const button of buttons) {
button.addEventListener("click", selectPrice);
}
function selectPrice(event) { function selectPrice(event) {
const selectedPrix = parseInt(event.target.textContent); const selectedPrix = parseInt(event.target.textContent);
prixActuel += selectedPrix; prixActuel += selectedPrix;
prix[0].textContent = prixActuel;
socket.emit("prixActuel", prixActuel); socket.emit("prixActuel", prixActuel);
socket.on("prixActuel", (nouveauPrix) => {prix[0].textContent = nouveauPrix}); socket.on("winner", () => win());
ident.textContent = `Vous avez fait une enchère de +${selectedPrix}€`; ident.textContent = `Vous avez fait une enchère de +${selectedPrix}€`;
} }
function win() {
console.log("ici win");
ident.textContent = `Enchères terminé, vous avez remporté l'enchère`;
displayButton("none");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment