Purchase delays
This commit is contained in:
@ -14,7 +14,7 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main class="container-fluid container">
|
||||
<main class="container-fluid main-container">
|
||||
<h1 class="mt-1 mb-2">
|
||||
FairHopper Visualisation Client
|
||||
</h1>
|
||||
|
||||
@ -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 `
|
||||
<div class="card product">
|
||||
<div class="card product" id="product-${product.id}">
|
||||
<img src="img/products/${product.name}.jpeg" class="card-img-topx" alt="${product.name}">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">${product.name}</h5>
|
||||
@ -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);
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user