Update readme

This commit is contained in:
Eden Kirin
2023-04-02 19:52:47 +02:00
parent c30529c087
commit d4d03b78f9
3 changed files with 271 additions and 168 deletions

435
README.md
View File

@ -8,10 +8,10 @@
- Destination: center of a board (W / 2, H / 2) - Destination: center of a board (W / 2, H / 2)
- Initial player position: Random on board border - Initial player position: Random on board border
- Available moves: - Available moves:
- left - left
- right - right
- up - up
- down - down
- Optional on-board obstacles - Optional on-board obstacles
### Rules ### Rules
@ -24,6 +24,7 @@
## Game States ## Game States
```plantuml ```plantuml
scale 1024 width
hide empty description hide empty description
state "Start Game" as StartGame state "Start Game" as StartGame
@ -202,33 +203,33 @@ Check REST API interface on [FastAPI docs](http://localhost:8010/docs).
Request body: Request body:
```json ```json
{ {
"player_name": "Pero" "player_name": "Pero"
} }
``` ```
Response body: Response body:
```json ```json
{ {
"board": { "board": {
"width": 101, "width": 101,
"height": 101 "height": 101
}, },
"destination": { "destination": {
"position": { "position": {
"x": 50, "x": 50,
"y": 50 "y": 50
} }
}, },
"player": { "player": {
"id": "75bba7cd-a4c1-4b50-b0b5-6382c2822a25", "id": "75bba7cd-a4c1-4b50-b0b5-6382c2822a25",
"name": "Pero", "name": "Pero",
"position": { "position": {
"x": 0, "x": 0,
"y": 10 "y": 10
}, },
"move_count": 0, "move_count": 0,
"move_attempt_count": 0 "move_attempt_count": 0
} }
} }
``` ```
@ -251,16 +252,16 @@ Response code:
Response body: Response body:
```json ```json
{ {
"player": { "player": {
"id": "string", "id": "string",
"name": "Pero", "name": "Pero",
"position": { "position": {
"x": 50, "x": 50,
"y": 50 "y": 50
}, },
"move_count": 10, "move_count": 10,
"move_attempt_count": 12 "move_attempt_count": 12
} }
} }
``` ```
@ -273,16 +274,16 @@ Request body: None
Response body: Response body:
```json ```json
{ {
"player": { "player": {
"id": "string", "id": "string",
"name": "Pero", "name": "Pero",
"position": { "position": {
"x": 50, "x": 50,
"y": 50 "y": 50
}, },
"move_count": 10, "move_count": 10,
"move_attempt_count": 12 "move_attempt_count": 12
} }
} }
``` ```
@ -293,19 +294,19 @@ GET `/game`
Response body: Response body:
```json ```json
{ {
"playerId": "75bba7cd-a4c1-4b50-b0b5-6382c2822a25", "playerId": "75bba7cd-a4c1-4b50-b0b5-6382c2822a25",
"board": { "board": {
"width": 101, "width": 101,
"height": 101 "height": 101
}, },
"destinationPosition": { "destinationPosition": {
"x": 50, "x": 50,
"y": 50 "y": 50
}, },
"playerPosition": { "playerPosition": {
"x": 0, "x": 0,
"y": 10 "y": 10
} }
} }
``` ```
@ -314,120 +315,222 @@ Response body:
### WS Data format ### WS Data format
- json - json
```json
{
"message": message_type,
"data": ...
}
```
### Game state structure ### Game state structure
URI: `/game-state` Message: `game_dump`
Data: Data:
```json ```json
{ {
"board": { "board": {
"width": 21, "width": 10,
"height": 21 "height": 10
}, },
"destination": { "destination": {
"position": { "position": {
"x": 10, "x": 5,
"y": 10 "y": 5
} }
}, },
"players": [ "players": [
{ {
"id": "test-player-id", "id": "test-player-pero",
"name": "Pero", "name": "Pero",
"active": true, "active": true,
"position": { "position": {
"x": 2, "x": 3,
"y": 2 "y": 3
}, },
"move_count": 3, "move_count": 0,
"move_attempt_count": 3 "move_attempt_count": 0,
}, "state": "CREATED"
{ },
"id": "95962b49-0003-4bf2-b205-71f2590f2318", {
"name": "Mirko", "id": "test-player-mirko",
"active": true, "name": "Mirko",
"position": { "active": true,
"x": 0, "position": {
"y": 0 "x": 4,
}, "y": 4
"move_count": 15, },
"move_attempt_count": 20 "move_count": 0,
} "move_attempt_count": 0,
], "state": "CREATED"
"layers": [ }
{ ],
"name": "obstacles", "layers": [
"objects": [ {
{ "name": "obstacles",
"type": "OBSTACLE", "objects": [
"position": { {
"x": 4, "type": "OBSTACLE",
"y": 2 "position": {
} "x": 0,
}, "y": 6
{ }
"type": "OBSTACLE", },
"position": { {
"x": 4, "type": "OBSTACLE",
"y": 13 "position": {
} "x": 5,
}, "y": 1
{ }
"type": "OBSTACLE", },
"position": { {
"x": 18, "type": "OBSTACLE",
"y": 18 "position": {
} "x": 1,
}, "y": 6
{ }
"type": "OBSTACLE", }
"position": { ]
"x": 5, },
"y": 4 {
} "name": "destination",
}, "objects": [
{ {
"type": "OBSTACLE", "type": "DESTINATION",
"position": { "position": {
"x": 7, "x": 5,
"y": 10 "y": 5
} }
} }
] ]
}, },
{ {
"name": "destination", "name": "players",
"objects": [ "objects": [
{ {
"type": "DESTINATION", "type": "PLAYER",
"position": { "position": {
"x": 10, "x": 3,
"y": 10 "y": 3
} }
} },
] {
}, "type": "PLAYER",
{ "position": {
"name": "players", "x": 4,
"objects": [ "y": 4
{ }
"type": "PLAYER", }
"position": { ]
"x": 2, }
"y": 2 ]
}
},
{
"type": "PLAYER",
"position": {
"x": 0,
"y": 0
}
}
]
}
]
} }
``` ```
### Product purchase start
Message: `product_purchase_start`
Data:
```json
{
"player": {
"id": "test-player-pero",
"name": "Pero",
"active": true,
"position": {
"x": 10,
"y": 10
},
"move_count": 1,
"move_attempt_count": 1,
"state": "ON_DESTINATION"
},
"products": [
{
"name": "CocaCola",
"id": "cocacola-id",
"description": null
},
{
"name": "Pepsi",
"id": "pepsi-id",
"description": null
},
{
"name": "Fanta",
"id": "fanta-id",
"description": null
},
{
"name": "Snickers",
"id": "snickers-id",
"description": null
},
{
"name": "Mars",
"id": "mars-id",
"description": null
},
{
"name": "Burek",
"id": "burek-id",
"description": null
}
],
"timeout": 5
}
```
### Product purchase timer tick
Message: `product_purchase_timer_tick`
Data:
```json
{
"time_left": 4,
"player": {
"id": "test-player-pero",
"name": "Pero",
"active": true,
"position": {
"x": 10,
"y": 10
},
"move_count": 1,
"move_attempt_count": 1,
"state": "ON_DESTINATION"
}
}
```
### Product purchase timer done
Message: `product_purchase_done`
Data:
```json
{
"player": {
"id": "test-player-pero",
"name": "Pero",
"active": true,
"position": {
"x": 10,
"y": 10
},
"move_count": 1,
"move_attempt_count": 1,
"state": "ON_DESTINATION"
},
"product": {
"name": "CocaCola",
"id": "cocacola-id",
"description": null
}
}
```
If product selection timeout occured, product will be null.

View File

@ -45,5 +45,5 @@ 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: Optional[List[Product]] = None products: List[Product] = None
debug: Optional[DebugSettings] = None debug: Optional[DebugSettings] = None