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

gestion de la présence d'un seul comissaire priseur

parent 7767c770
Branches
No related tags found
No related merge requests found
...@@ -2,6 +2,8 @@ console.log('le bundle-auctioneer a été généré'); ...@@ -2,6 +2,8 @@ console.log('le bundle-auctioneer a été généré');
const socket = io(); const socket = io();
let winnerId;
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");
...@@ -9,7 +11,16 @@ const buttonStart = document.getElementById("start"); ...@@ -9,7 +11,16 @@ const buttonStart = document.getElementById("start");
const buttonSale = document.getElementById("sale"); const buttonSale = document.getElementById("sale");
buttonSale.addEventListener("click", saleProduct); buttonSale.addEventListener("click", saleProduct);
const ident = document.getElementById("ident-auc");
socket.emit("auctioneer"); socket.emit("auctioneer");
socket.on("alreadyAuct", () => alreadyAuctioneer());
function alreadyAuctioneer() {
const prod = document.getElementById("prod-auc");
ident.textContent = "Connexion refusée, il y a déjà un comissaire-priseur";
prod.style.display = "none";
}
const prixActuel = document.getElementById("prixactuel"); const prixActuel = document.getElementById("prixactuel");
prixActuel.textContent = inputValue.value+""; prixActuel.textContent = inputValue.value+"";
...@@ -26,20 +37,22 @@ function emptyInput() { ...@@ -26,20 +37,22 @@ function emptyInput() {
inputName.addEventListener("input", emptyInput); inputName.addEventListener("input", emptyInput);
buttonStart.addEventListener("click", startEnchere); buttonStart.addEventListener("click", startEnchere);
const ident = document.getElementById("ident-auc");
function startEnchere() { function startEnchere() {
prixActuel.textContent = inputValue.value+""; prixActuel.textContent = inputValue.value+"";
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("changePrix", (nouveauPrix, sock) => updatePrix(nouveauPrix, sock)); socket.on("changePrix", (nouveauPrix, sock) => {
updatePrix(nouveauPrix, sock);
winnerId = sock;
});
waitForNewEnchere(true); waitForNewEnchere(true);
} }
function saleProduct() { function saleProduct() {
ident.textContent = `Fin de l'enchère. Un ${inputName.value} à ${prixActuel.textContent}`; ident.textContent = `Fin de l'enchère. Un ${inputName.value} à ${prixActuel.textContent}`;
socket.emit("adjuge"); socket.emit("adjuge", winnerId);
waitForNewEnchere(false); waitForNewEnchere(false);
} }
......
...@@ -6,6 +6,8 @@ const ident = document.getElementById("ident-bid"); ...@@ -6,6 +6,8 @@ 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");
let prixActuel = 0;
displayButton("none"); displayButton("none");
const buttons = document.querySelectorAll("button"); const buttons = document.querySelectorAll("button");
for(const button of buttons) { for(const button of buttons) {
...@@ -17,7 +19,6 @@ function displayButton(display) { ...@@ -17,7 +19,6 @@ function displayButton(display) {
divButtons.style.display = display; divButtons.style.display = display;
} }
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);
...@@ -41,12 +42,17 @@ function selectPrice(event) { ...@@ -41,12 +42,17 @@ function selectPrice(event) {
const selectedPrix = parseInt(event.target.textContent); const selectedPrix = parseInt(event.target.textContent);
prixActuel += selectedPrix; prixActuel += selectedPrix;
socket.emit("prixActuel", prixActuel); socket.emit("prixActuel", prixActuel);
socket.on("winner", () => win()); socket.on("adjuge", () => finishEnchere());
ident.textContent = `Vous avez fait une enchère de +${selectedPrix}€`; ident.textContent = `Vous avez fait une enchère de +${selectedPrix}€`;
} }
function finishEnchere() {
ident.textContent = `Enchères terminé, l'enchère a été remporté par une autre personne`;
displayButton("none");
}
function win() { function win() {
console.log("ici win"); console.log("ici");
ident.textContent = `Enchères terminé, vous avez remporté l'enchère`; ident.textContent = `Enchères terminé, vous avez remporté l'enchère`;
displayButton("none"); displayButton("none");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment