diff --git a/encheres/client/src/html/bidder.html b/encheres/client/src/html/bidder.html index 1a8d26d570174297b188cf037daf2b4f3ec047f1..45fa2128400239b7c3a00a98b4b5fdf7cafe9022 100644 --- a/encheres/client/src/html/bidder.html +++ b/encheres/client/src/html/bidder.html @@ -16,7 +16,7 @@ <div class="item">Prix actuel : <span class="prix"></span> </div> </div> - <div class="price-options"> + <div id="buttons" class="price-options"> <p>Enchères possibles :</p> <button class="price-button">20€</button> <button class="price-button">50€</button> diff --git a/encheres/client/src/scripts/auctioneer.js b/encheres/client/src/scripts/auctioneer.js index f57fcb111f9c4f19123fb32963487231a0324d17..0f9fb0a81d5108d8fe1fc4ba698223e6ce1983c7 100644 --- a/encheres/client/src/scripts/auctioneer.js +++ b/encheres/client/src/scripts/auctioneer.js @@ -5,7 +5,11 @@ const socket = io(); const inputName = document.getElementById("name"); const inputValue = document.getElementById("value"); const buttonStart = document.getElementById("start"); + const buttonSale = document.getElementById("sale"); +buttonSale.addEventListener("click", saleProduct); + +socket.emit("auctioneer"); const prixActuel = document.getElementById("prixactuel"); prixActuel.textContent = inputValue.value+"€"; @@ -29,8 +33,14 @@ function startEnchere() { buttonSale.disabled = false; ident.textContent = `Debut de l'enchère pour ${inputName.value} à ${inputValue.value}€`; socket.emit("infos", inputName.value, inputValue.value); - socket.on("prixActuel", (nouveauPrix, sock) => updatePrix(nouveauPrix, sock)); - waitForNewEnchere(); + socket.on("changePrix", (nouveauPrix, sock) => updatePrix(nouveauPrix, sock)); + 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) { @@ -38,10 +48,10 @@ function updatePrix(nouveauPrix, sock) { ident.textContent = `Nouvelle enchère réçu de ${sock}`; } -function waitForNewEnchere() { - inputName.disabled = true; - inputValue.disabled = true; - buttonStart.disabled = true; +function waitForNewEnchere(disabled) { + inputName.disabled = disabled; + inputValue.disabled = disabled; + buttonStart.disabled = disabled; } diff --git a/encheres/client/src/scripts/bidder.js b/encheres/client/src/scripts/bidder.js index 6a453739450b0b920fb64572105f769f68f69110..b4f8bc2871f6c8caf7ede5cac247a192ab47af1c 100644 --- a/encheres/client/src/scripts/bidder.js +++ b/encheres/client/src/scripts/bidder.js @@ -6,31 +6,50 @@ const ident = document.getElementById("ident-bid"); const description = document.getElementsByClassName("description"); 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; socket.on("infos", (name, value) => { ident.textContent = `Une nouvelle enchère commence`; enchereBegin(name, value); + displayButton("block"); + socket.on("changePrix", (nouveauPrix) => {changePrix(nouveauPrix)}); }); +function changePrix(nouveauPrix) { + prix[0].textContent = nouveauPrix+"€"; + prixActuel = nouveauPrix; +} + function enchereBegin(name, value) { description[0].textContent = name; 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) { const selectedPrix = parseInt(event.target.textContent); prixActuel += selectedPrix; - prix[0].textContent = 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}€`; } +function win() { + console.log("ici win"); + ident.textContent = `Enchères terminé, vous avez remporté l'enchère`; + displayButton("none"); +} +