added bet mechanism (currently without checks for invalid bets)
This commit is contained in:
@@ -39,6 +39,8 @@ signal connection_status_changed(new_status: ConnectionStatus)
|
|||||||
signal client_order_received(client_ids: Array[String])
|
signal client_order_received(client_ids: Array[String])
|
||||||
signal cards_received(cards: Dictionary)
|
signal cards_received(cards: Dictionary)
|
||||||
|
|
||||||
|
signal received_bet_request(disallowed_bet: int)
|
||||||
|
|
||||||
enum ConnectionStatus {
|
enum ConnectionStatus {
|
||||||
DISCONNECTED,
|
DISCONNECTED,
|
||||||
ATTEMPTING_CONNECTION,
|
ATTEMPTING_CONNECTION,
|
||||||
@@ -133,7 +135,7 @@ func _handle_response(response: String) -> void:
|
|||||||
"client_submitted_bet":
|
"client_submitted_bet":
|
||||||
print(data)
|
print(data)
|
||||||
"request_bet":
|
"request_bet":
|
||||||
print(data)
|
received_bet_request.emit.call_deferred(data["disallowed_bet"])
|
||||||
"begin_playing_cards":
|
"begin_playing_cards":
|
||||||
print(data)
|
print(data)
|
||||||
"request_card":
|
"request_card":
|
||||||
|
|||||||
@@ -183,11 +183,15 @@ disabled = true
|
|||||||
text = "Play Card"
|
text = "Play Card"
|
||||||
|
|
||||||
[node name="BetContainer" type="VBoxContainer" parent="HBoxContainer/GameUI"]
|
[node name="BetContainer" type="VBoxContainer" parent="HBoxContainer/GameUI"]
|
||||||
layout_mode = 0
|
layout_mode = 1
|
||||||
offset_left = 218.0
|
anchors_preset = 2
|
||||||
offset_top = 833.0
|
anchor_top = 1.0
|
||||||
offset_right = 445.0
|
anchor_bottom = 1.0
|
||||||
offset_bottom = 899.0
|
offset_left = 100.0
|
||||||
|
offset_top = -180.0
|
||||||
|
offset_right = 327.0
|
||||||
|
offset_bottom = -114.0
|
||||||
|
grow_vertical = 0
|
||||||
|
|
||||||
[node name="BetInput" type="LineEdit" parent="HBoxContainer/GameUI/BetContainer"]
|
[node name="BetInput" type="LineEdit" parent="HBoxContainer/GameUI/BetContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
@@ -247,6 +251,7 @@ transform = Transform3D(-0.5, 0, 0.866025, 0, 1, 0, -0.866025, 0, -0.5, 3.2, 0.4
|
|||||||
[connection signal="connection_status_changed" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_connection_status_changed"]
|
[connection signal="connection_status_changed" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_connection_status_changed"]
|
||||||
[connection signal="disconnected_from_lobby" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_disconnected_from_lobby"]
|
[connection signal="disconnected_from_lobby" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_disconnected_from_lobby"]
|
||||||
[connection signal="disconnected_from_server" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_disconnected_from_server"]
|
[connection signal="disconnected_from_server" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_disconnected_from_server"]
|
||||||
|
[connection signal="received_bet_request" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_received_bet_request"]
|
||||||
[connection signal="received_chat_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_chat_message"]
|
[connection signal="received_chat_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_chat_message"]
|
||||||
[connection signal="received_client_id" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_client_id"]
|
[connection signal="received_client_id" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_client_id"]
|
||||||
[connection signal="received_connection_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_connection_message"]
|
[connection signal="received_connection_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_connection_message"]
|
||||||
|
|||||||
@@ -58,4 +58,9 @@ func _on_player_hand_card_selected(card_id: int) -> void:
|
|||||||
play_card_button.disabled = card_id == -1
|
play_card_button.disabled = card_id == -1
|
||||||
|
|
||||||
func _on_submit_bet_button_pressed() -> void:
|
func _on_submit_bet_button_pressed() -> void:
|
||||||
|
bet_container.hide()
|
||||||
web_client.submit_bet(int(bet_input.text.strip_edges()), _current_round)
|
web_client.submit_bet(int(bet_input.text.strip_edges()), _current_round)
|
||||||
|
|
||||||
|
func _on_web_client_tcp_received_bet_request(disallowed_bet: int) -> void:
|
||||||
|
bet_input.text = ""
|
||||||
|
bet_container.show()
|
||||||
|
|||||||
+24
-7
@@ -182,8 +182,6 @@ class LobbyManager:
|
|||||||
cards.pop("trump")
|
cards.pop("trump")
|
||||||
|
|
||||||
for client_id in client_ids:
|
for client_id in client_ids:
|
||||||
# client_cards = cards[client_id]
|
|
||||||
print(cards)
|
|
||||||
await self.send_message(
|
await self.send_message(
|
||||||
lobby_id,
|
lobby_id,
|
||||||
client_id,
|
client_id,
|
||||||
@@ -196,6 +194,16 @@ class LobbyManager:
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def request_bet(self, lobby_id, client_id, disallowed_bet) -> None:
|
||||||
|
await self.send_message(
|
||||||
|
lobby_id,
|
||||||
|
client_id,
|
||||||
|
json.dumps({
|
||||||
|
"response": "request_bet",
|
||||||
|
"disallowed_bet": disallowed_bet,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
async def spread_bet(self, lobby_id, client_id, bet) -> None:
|
async def spread_bet(self, lobby_id, client_id, bet) -> None:
|
||||||
await self.broadcast_message(
|
await self.broadcast_message(
|
||||||
lobby_id,
|
lobby_id,
|
||||||
@@ -398,6 +406,12 @@ async def process_input(message: str, websocket) -> None:
|
|||||||
|
|
||||||
print(f"Lobby {lobby_id} is starting the game, playing order is: {lobby.client_playing_order}")
|
print(f"Lobby {lobby_id} is starting the game, playing order is: {lobby.client_playing_order}")
|
||||||
|
|
||||||
|
await lobby_manager.request_bet(
|
||||||
|
lobby_id,
|
||||||
|
lobby_manager.get_lobby(lobby_id).client_playing_order[0],
|
||||||
|
-1,
|
||||||
|
)
|
||||||
|
|
||||||
# Start next round (host only)
|
# Start next round (host only)
|
||||||
elif data_object["response"] == "start_next_round":
|
elif data_object["response"] == "start_next_round":
|
||||||
lobby_id = data_object["lobby_id"]
|
lobby_id = data_object["lobby_id"]
|
||||||
@@ -412,6 +426,12 @@ async def process_input(message: str, websocket) -> None:
|
|||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await lobby_manager.request_bet(
|
||||||
|
lobby_id,
|
||||||
|
lobby_manager.get_lobby(lobby_id).client_playing_order[0],
|
||||||
|
-1,
|
||||||
|
)
|
||||||
|
|
||||||
elif data_object["response"] == "submit_bet":
|
elif data_object["response"] == "submit_bet":
|
||||||
lobby_id = data_object["lobby_id"]
|
lobby_id = data_object["lobby_id"]
|
||||||
client_id = data_object["client_id"]
|
client_id = data_object["client_id"]
|
||||||
@@ -454,13 +474,10 @@ async def process_input(message: str, websocket) -> None:
|
|||||||
total_bet = sum(lobby_manager.get_lobby(lobby_id).client_bets.values())
|
total_bet = sum(lobby_manager.get_lobby(lobby_id).client_bets.values())
|
||||||
disallowed_bet = total_bet - data_object["round"]
|
disallowed_bet = total_bet - data_object["round"]
|
||||||
|
|
||||||
await lobby_manager.send_message(
|
await lobby_manager.request_bet(
|
||||||
lobby_id,
|
lobby_id,
|
||||||
lobby_manager.get_lobby(lobby_id).client_playing_order[last_client_index + 1],
|
lobby_manager.get_lobby(lobby_id).client_playing_order[last_client_index + 1],
|
||||||
json.dumps({
|
disallowed_bet,
|
||||||
"response": "request_bet",
|
|
||||||
"disallowed_bet": disallowed_bet,
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
elif data_object["response"] == "play_card":
|
elif data_object["response"] == "play_card":
|
||||||
|
|||||||
Reference in New Issue
Block a user