diff --git a/frontend/index.html b/frontend/index.html index 90db0eb..7c7014c 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -14,7 +14,7 @@ -
+

FairHopper Visualisation Client

diff --git a/frontend/js/frontend.js b/frontend/js/frontend.js index 000decd..a68e5e5 100644 --- a/frontend/js/frontend.js +++ b/frontend/js/frontend.js @@ -85,6 +85,8 @@ function renderDestination(position) { } function renderGameDump(data) { + closePurchaseWindow(); + createBoard(data.board); renderObstacles(data.layers); renderDestination(data.destination.position); @@ -101,7 +103,7 @@ function productPurchaseStart(products, purchaseTimeout) { const html = products .map((product) => { return ` -
+
${product.name}
${product.name}
@@ -121,16 +123,16 @@ function productPurchaseTimerTick(timeLeft) { purchaseTimeoutElement.innerText = timeLeft; } -function productPurchased(product) { - console.log("productPurchased:", product); -} - -function productPurchaseDone() { - console.log("productPurchaseDone"); +function closePurchaseWindow() { const container = document.getElementById("purchase-container"); container.classList.add("d-none"); } +function productPurchaseDone(product) { + const cardContainer = document.getElementById(`product-${product.id}`); + cardContainer.classList.add("selected"); +} + function wsConnect() { let ws = new WebSocket("ws://localhost:8011"); ws.onopen = () => { @@ -151,11 +153,8 @@ function wsConnect() { case "product_purchase_timer_tick": productPurchaseTimerTick(wsMessage.data.time_left); break; - case "product_purchased": - productPurchased(wsMessage.data); - break; case "product_purchase_done": - productPurchaseDone(); + productPurchaseDone(wsMessage.data.product); break; default: console.error("Unknown message:", wsMessage); diff --git a/frontend/styles.css b/frontend/styles.css index aebb515..c1b0fff 100644 --- a/frontend/styles.css +++ b/frontend/styles.css @@ -2,7 +2,7 @@ body { background-color: whitesmoke; } -main.container { +main.main-container { position: relative; } @@ -84,8 +84,13 @@ ul.players { grid-template-columns: 1fr 1fr 1fr; } +.purchase-container .products-content .product.selected { + background-color: pink; +} + .purchase-container .products-content .product .card-title { text-align: center; + font-size: 12pt; } .purchase-container .products-content .product img { diff --git a/hopper/engine.py b/hopper/engine.py index e2d3ce5..9493da8 100644 --- a/hopper/engine.py +++ b/hopper/engine.py @@ -212,6 +212,8 @@ class GameEngine: ) self._purchase_countdown_timer.start() + await asyncio.sleep(settings.game.PURCHASE_START_DELAY) + async def purchase_product(self, player: Player, product: Product) -> None: if not player.state == PlayerState.ON_DESTINATION: raise PurchaseForbiddenForPlayer() @@ -220,6 +222,7 @@ class GameEngine: await self.ws_server.send_product_purchase_done_message( player=player, product=product ) + await asyncio.sleep(settings.game.PURCHASE_FINISHED_DELAY) await self.reset_game() def _reset_player(self, player) -> None: diff --git a/hopper/models/config.py b/hopper/models/config.py index 7cb4ad2..9388c13 100644 --- a/hopper/models/config.py +++ b/hopper/models/config.py @@ -9,6 +9,8 @@ from hopper.models.product import Product @dataclass class GameSettings: MOVE_DELAY: float = 0.5 # seconds + PURCHASE_START_DELAY: float = 2 # seconds + PURCHASE_FINISHED_DELAY: float = 2 # seconds @dataclass