Compare commits
2 Commits
fb4651ec23
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| afbb3d7436 | |||
| 21a7f111b2 |
@ -9,7 +9,6 @@ from hopper.models.config import (
|
|||||||
Settings,
|
Settings,
|
||||||
WSServerSettings,
|
WSServerSettings,
|
||||||
)
|
)
|
||||||
from hopper.models.product import Product
|
|
||||||
|
|
||||||
settings = Settings(
|
settings = Settings(
|
||||||
game=GameSettings(),
|
game=GameSettings(),
|
||||||
@ -21,14 +20,6 @@ settings = Settings(
|
|||||||
inacivity_watchdog=InactivityWatchdogSettings(),
|
inacivity_watchdog=InactivityWatchdogSettings(),
|
||||||
purchase_timeout=5,
|
purchase_timeout=5,
|
||||||
log_level=logging.INFO,
|
log_level=logging.INFO,
|
||||||
products=[
|
|
||||||
Product(name="CocaCola", id="cocacola-id"),
|
|
||||||
Product(name="Pepsi", id="pepsi-id"),
|
|
||||||
Product(name="Fanta", id="fanta-id"),
|
|
||||||
Product(name="Snickers", id="snickers-id"),
|
|
||||||
Product(name="Mars", id="mars-id"),
|
|
||||||
Product(name="Burek", id="burek-id"),
|
|
||||||
],
|
|
||||||
ws_server=WSServerSettings(
|
ws_server=WSServerSettings(
|
||||||
HOST="0.0.0.0",
|
HOST="0.0.0.0",
|
||||||
PORT=int(os.environ.get("FAIRHOPPER_WS_PORT", 8011)),
|
PORT=int(os.environ.get("FAIRHOPPER_WS_PORT", 8011)),
|
||||||
|
|||||||
@ -34,13 +34,6 @@ POST http://localhost:8010/player/test-player-pero/move/up
|
|||||||
POST http://localhost:8010/player/test-player-pero/move/down
|
POST http://localhost:8010/player/test-player-pero/move/down
|
||||||
###
|
###
|
||||||
|
|
||||||
# purchase product
|
|
||||||
POST http://localhost:8010/player/test-player-pero/product/purchase
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"product_id": "cocacola-id"
|
|
||||||
}
|
|
||||||
###
|
###
|
||||||
|
|
||||||
# move Mirko left
|
# move Mirko left
|
||||||
|
|||||||
@ -22,15 +22,6 @@
|
|||||||
<h1 class="mt-1 mb-2">
|
<h1 class="mt-1 mb-2">
|
||||||
FairHopper Visualisation Client
|
FairHopper Visualisation Client
|
||||||
</h1>
|
</h1>
|
||||||
<div id="purchase-container" class="purchase-container d-none">
|
|
||||||
<div class="d-flex header">
|
|
||||||
<h3>
|
|
||||||
Product selection
|
|
||||||
</h3>
|
|
||||||
<h3 id="purchase-countdown" class="countdown"></h3>
|
|
||||||
</div>
|
|
||||||
<div id="products-content" class="products-content"></div>
|
|
||||||
</div>
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-10">
|
<div class="col-10">
|
||||||
<div class="board-container">
|
<div class="board-container">
|
||||||
|
|||||||
@ -18,7 +18,7 @@ main.main-container {
|
|||||||
padding-bottom: 2px;
|
padding-bottom: 2px;
|
||||||
}
|
}
|
||||||
.flex-grid:last-of-type {
|
.flex-grid:last-of-type {
|
||||||
padding-bottom: 0px;
|
padding-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.cell {
|
.cell {
|
||||||
@ -56,44 +56,3 @@ ul.players {
|
|||||||
border-style: solid;
|
border-style: solid;
|
||||||
border-color: darkred transparent transparent transparent;
|
border-color: darkred transparent transparent transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
.purchase-container {
|
|
||||||
width: 50vw;
|
|
||||||
position: fixed;
|
|
||||||
top: 200px;
|
|
||||||
left: 50%;
|
|
||||||
padding: 20px;
|
|
||||||
transform: translateX(-50%);
|
|
||||||
background-color: darkred;
|
|
||||||
z-index: 999;
|
|
||||||
border-radius: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.purchase-container .header {
|
|
||||||
color: white;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.purchase-container .header .countdown {
|
|
||||||
margin-left: auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.purchase-container .products-content {
|
|
||||||
display: grid;
|
|
||||||
grid-gap: 10px;
|
|
||||||
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 {
|
|
||||||
margin: 20px;
|
|
||||||
max-height: 300px;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -179,14 +179,14 @@ class GameEngine:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def on_purchase_timer_tick(time_left) -> None:
|
def on_purchase_timer_tick(time_left) -> None:
|
||||||
logging.info(f"Product selection countdown timer tick, time left: {time_left}")
|
logging.info(
|
||||||
|
f"Product selection countdown timer tick, time left: {time_left}"
|
||||||
|
)
|
||||||
|
|
||||||
def on_purchase_timer_done() -> None:
|
def on_purchase_timer_done() -> None:
|
||||||
logging.info("Ding ding! Product selection countdown timer timeout")
|
logging.info("Ding ding! Product selection countdown timer timeout")
|
||||||
self._purchase_countdown_timer = None
|
self._purchase_countdown_timer = None
|
||||||
asyncio.run(
|
asyncio.run(self.ws_server.send_product_selection_timeout_message())
|
||||||
self.ws_server.send_product_selection_timeout_message()
|
|
||||||
)
|
|
||||||
self.game_state = GameState.RUNNING
|
self.game_state = GameState.RUNNING
|
||||||
asyncio.run(self.send_game_dump())
|
asyncio.run(self.send_game_dump())
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,13 @@ BOARD_DUMP_CHARS: dict[ObjectType, str] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def create_random_position(board_width: int, board_height: int) -> Position:
|
||||||
|
return Position(
|
||||||
|
x=random.randint(0, board_width - 1),
|
||||||
|
y=random.randint(0, board_height - 1),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LayerObject:
|
class LayerObject:
|
||||||
type_: ObjectType
|
type_: ObjectType
|
||||||
@ -102,10 +109,3 @@ class BoardLayout:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
return layers
|
return layers
|
||||||
|
|
||||||
|
|
||||||
def create_random_position(board_width: int, board_height: int) -> Position:
|
|
||||||
return Position(
|
|
||||||
x=random.randint(0, board_width - 1),
|
|
||||||
y=random.randint(0, board_height - 1),
|
|
||||||
)
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@ from dataclasses import dataclass
|
|||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from hopper.models.player import Player
|
from hopper.models.player import Player
|
||||||
from hopper.models.product import Product
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@ -46,5 +45,4 @@ class Settings:
|
|||||||
ws_server: WSServerSettings
|
ws_server: WSServerSettings
|
||||||
purchase_timeout: int = 10 # seconds
|
purchase_timeout: int = 10 # seconds
|
||||||
log_level: int = logging.INFO
|
log_level: int = logging.INFO
|
||||||
products: List[Product] = None
|
|
||||||
debug: Optional[DebugSettings] = None
|
debug: Optional[DebugSettings] = None
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
import uuid
|
|
||||||
from dataclasses import dataclass, field
|
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class Product:
|
|
||||||
name: str
|
|
||||||
id: str = field(default_factory=lambda: str(uuid.uuid4()))
|
|
||||||
description: Optional[str] = None
|
|
||||||
@ -10,9 +10,7 @@ from settings import settings
|
|||||||
|
|
||||||
|
|
||||||
class InactivityWatchdog(Thread):
|
class InactivityWatchdog(Thread):
|
||||||
def __init__(
|
def __init__(self, players: PlayerList, ws_server: WSServer = None) -> None:
|
||||||
self, players: PlayerList, ws_server: WSServer = None
|
|
||||||
) -> None:
|
|
||||||
self.players = players
|
self.players = players
|
||||||
self.ws_server = ws_server
|
self.ws_server = ws_server
|
||||||
self.stop_event = Event()
|
self.stop_event = Event()
|
||||||
|
|||||||
@ -9,7 +9,6 @@ from hopper.models.config import (
|
|||||||
WSServerSettings,
|
WSServerSettings,
|
||||||
)
|
)
|
||||||
from hopper.models.player import Player, Position
|
from hopper.models.player import Player, Position
|
||||||
from hopper.models.product import Product
|
|
||||||
|
|
||||||
settings = Settings(
|
settings = Settings(
|
||||||
game=GameSettings(),
|
game=GameSettings(),
|
||||||
@ -21,14 +20,6 @@ settings = Settings(
|
|||||||
inacivity_watchdog=InactivityWatchdogSettings(),
|
inacivity_watchdog=InactivityWatchdogSettings(),
|
||||||
purchase_timeout=5,
|
purchase_timeout=5,
|
||||||
log_level=logging.INFO,
|
log_level=logging.INFO,
|
||||||
products=[
|
|
||||||
Product(name="CocaCola", id="cocacola-id"),
|
|
||||||
Product(name="Pepsi", id="pepsi-id"),
|
|
||||||
Product(name="Fanta", id="fanta-id"),
|
|
||||||
Product(name="Snickers", id="snickers-id"),
|
|
||||||
Product(name="Mars", id="mars-id"),
|
|
||||||
Product(name="Burek", id="burek-id"),
|
|
||||||
],
|
|
||||||
ws_server=WSServerSettings(),
|
ws_server=WSServerSettings(),
|
||||||
debug=DebugSettings(
|
debug=DebugSettings(
|
||||||
PRINT_BOARD=True,
|
PRINT_BOARD=True,
|
||||||
|
|||||||
Reference in New Issue
Block a user