all clients now receive current round
This commit is contained in:
+3
-2
@@ -1,14 +1,15 @@
|
|||||||
class_name CardStack
|
class_name CardStack
|
||||||
extends Node3D
|
extends Node3D
|
||||||
|
|
||||||
var _card_height: float = 0.06
|
var _card_height: float = 0.02
|
||||||
|
|
||||||
@export var playing_card_scene: PackedScene
|
@export var playing_card_scene: PackedScene
|
||||||
|
|
||||||
func add_card(card: PlayingCard) -> void:
|
func add_card(card: PlayingCard) -> void:
|
||||||
var height = self.get_child_count() * _card_height
|
var height = self.get_child_count() * _card_height
|
||||||
self.add_child(card)
|
self.add_child(card)
|
||||||
card.translate(Vector3(0, height, 0))
|
card.rotate(Vector3.FORWARD, randf_range(-0.3, 0.3))
|
||||||
|
card.translate(Vector3.BACK * height)
|
||||||
|
|
||||||
func add_card_by_id(card_id: int) -> void:
|
func add_card_by_id(card_id: int) -> void:
|
||||||
var playing_card: PlayingCard = playing_card_scene.instantiate()
|
var playing_card: PlayingCard = playing_card_scene.instantiate()
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ signal received_expected_bet(client_id: String, expected_bet: int)
|
|||||||
signal new_round_started()
|
signal new_round_started()
|
||||||
signal cards_received(cards: Dictionary)
|
signal cards_received(cards: Dictionary)
|
||||||
signal trump_received(trump_id: int)
|
signal trump_received(trump_id: int)
|
||||||
signal received_bet_request(disallowed_bet: int)
|
signal received_bet_request(disallowed_bet: int, current_round: int)
|
||||||
signal received_win()
|
signal received_win()
|
||||||
signal received_winning_client(client_id: String)
|
signal received_winning_client(client_id: String)
|
||||||
signal notify_play_card_request()
|
signal notify_play_card_request()
|
||||||
@@ -151,7 +151,7 @@ func _handle_response(response: String) -> void:
|
|||||||
data["bet"],
|
data["bet"],
|
||||||
)
|
)
|
||||||
"request_bet":
|
"request_bet":
|
||||||
received_bet_request.emit.call_deferred(data["disallowed_bet"])
|
received_bet_request.emit.call_deferred(data["disallowed_bet"], data["round"])
|
||||||
"begin_playing_cards":
|
"begin_playing_cards":
|
||||||
# all players know it's time to play
|
# all players know it's time to play
|
||||||
print(data)
|
print(data)
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ size_flags_horizontal = 3
|
|||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Send"
|
text = "Send"
|
||||||
|
|
||||||
[node name="GameUI" type="Control" parent="HBoxContainer" node_paths=PackedStringArray("web_client", "start_game_button", "play_card_button", "bet_container", "bet_input")]
|
[node name="GameUI" type="Control" parent="HBoxContainer" node_paths=PackedStringArray("web_client", "start_game_button", "play_card_button", "bet_container", "bet_input", "round_label")]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
mouse_filter = 2
|
mouse_filter = 2
|
||||||
@@ -153,6 +153,7 @@ start_game_button = NodePath("StartGameButton")
|
|||||||
play_card_button = NodePath("PlayCardButton")
|
play_card_button = NodePath("PlayCardButton")
|
||||||
bet_container = NodePath("BetContainer")
|
bet_container = NodePath("BetContainer")
|
||||||
bet_input = NodePath("BetContainer/BetInput")
|
bet_input = NodePath("BetContainer/BetInput")
|
||||||
|
round_label = NodePath("RoundLabel")
|
||||||
|
|
||||||
[node name="StartGameButton" type="Button" parent="HBoxContainer/GameUI"]
|
[node name="StartGameButton" type="Button" parent="HBoxContainer/GameUI"]
|
||||||
visible = false
|
visible = false
|
||||||
@@ -186,6 +187,7 @@ disabled = true
|
|||||||
text = "Play Card"
|
text = "Play Card"
|
||||||
|
|
||||||
[node name="BetContainer" type="VBoxContainer" parent="HBoxContainer/GameUI"]
|
[node name="BetContainer" type="VBoxContainer" parent="HBoxContainer/GameUI"]
|
||||||
|
visible = false
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 2
|
anchors_preset = 2
|
||||||
anchor_top = 1.0
|
anchor_top = 1.0
|
||||||
@@ -247,6 +249,17 @@ offset_bottom = 373.0
|
|||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
text = "YOU WON!!!!!!"
|
text = "YOU WON!!!!!!"
|
||||||
|
|
||||||
|
[node name="RoundLabel" type="Label" parent="HBoxContainer/GameUI"]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 1
|
||||||
|
anchor_left = 1.0
|
||||||
|
anchor_right = 1.0
|
||||||
|
offset_left = -100.0
|
||||||
|
offset_top = 60.0
|
||||||
|
offset_right = -60.0
|
||||||
|
offset_bottom = 83.0
|
||||||
|
grow_horizontal = 0
|
||||||
|
|
||||||
[node name="EnvironmentManager" type="Node3D" parent="." node_paths=PackedStringArray("web_client", "card_stack", "own_player_hand", "hand_markers_3", "hand_markers_4", "hand_markers_5", "hand_markers_6")]
|
[node name="EnvironmentManager" type="Node3D" parent="." node_paths=PackedStringArray("web_client", "card_stack", "own_player_hand", "hand_markers_3", "hand_markers_4", "hand_markers_5", "hand_markers_6")]
|
||||||
script = ExtResource("4_7jktm")
|
script = ExtResource("4_7jktm")
|
||||||
web_client = NodePath("../WebClientTCP")
|
web_client = NodePath("../WebClientTCP")
|
||||||
@@ -292,7 +305,7 @@ transform = Transform3D(-0.5, 0.836516, 0.224144, 0, 0.258819, -0.965925, -0.866
|
|||||||
transform = Transform3D(0.7, 0, 0, 0, 0.7, 0, 0, 0, 0.7, 0, 0, 0.704226)
|
transform = Transform3D(0.7, 0, 0, 0, 0.7, 0, 0, 0, 0.7, 0, 0, 0.704226)
|
||||||
|
|
||||||
[node name="CardStack" type="Marker3D" parent="EnvironmentManager"]
|
[node name="CardStack" type="Marker3D" parent="EnvironmentManager"]
|
||||||
transform = Transform3D(0.957037, -0.289967, -1.26749e-08, 1.48302e-15, -4.37114e-08, 1, -0.289967, -0.957036, -4.18334e-08, -0.0775449, 0.372575, 0.973012)
|
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -0.999999, -4.37114e-08, -0.0775449, 0.372575, 0.973012)
|
||||||
script = ExtResource("8_j5wjh")
|
script = ExtResource("8_j5wjh")
|
||||||
playing_card_scene = ExtResource("6_eow3j")
|
playing_card_scene = ExtResource("6_eow3j")
|
||||||
|
|
||||||
|
|||||||
+8
-1
@@ -6,6 +6,7 @@ extends Node
|
|||||||
@export var play_card_button: Button
|
@export var play_card_button: Button
|
||||||
@export var bet_container: Control
|
@export var bet_container: Control
|
||||||
@export var bet_input: LineEdit
|
@export var bet_input: LineEdit
|
||||||
|
@export var round_label: Label
|
||||||
|
|
||||||
var _is_host: bool = false
|
var _is_host: bool = false
|
||||||
var _current_player_count: int = 0
|
var _current_player_count: int = 0
|
||||||
@@ -63,6 +64,10 @@ func _update_player_count(player_count: int) -> void:
|
|||||||
else:
|
else:
|
||||||
start_game_button.hide()
|
start_game_button.hide()
|
||||||
|
|
||||||
|
func _set_current_round(round: int) -> void:
|
||||||
|
_current_round = round
|
||||||
|
round_label.text = str(_current_round)
|
||||||
|
|
||||||
func _on_web_client_tcp_client_joined_lobby(client_name: String, connected_client_names: Array[String]) -> void:
|
func _on_web_client_tcp_client_joined_lobby(client_name: String, connected_client_names: Array[String]) -> void:
|
||||||
_update_player_count(connected_client_names.size())
|
_update_player_count(connected_client_names.size())
|
||||||
|
|
||||||
@@ -74,11 +79,13 @@ func _on_player_hand_card_selected(card_id: int) -> void:
|
|||||||
|
|
||||||
func _on_submit_bet_button_pressed() -> void:
|
func _on_submit_bet_button_pressed() -> void:
|
||||||
bet_container.hide()
|
bet_container.hide()
|
||||||
|
print("current round! " + str(_current_round))
|
||||||
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:
|
func _on_web_client_tcp_received_bet_request(disallowed_bet: int, current_round: int) -> void:
|
||||||
bet_input.text = ""
|
bet_input.text = ""
|
||||||
bet_container.show()
|
bet_container.show()
|
||||||
|
_set_current_round(current_round)
|
||||||
|
|
||||||
func _on_web_client_tcp_request_next_round() -> void:
|
func _on_web_client_tcp_request_next_round() -> void:
|
||||||
_start_next_round()
|
_start_next_round()
|
||||||
|
|||||||
+1
-1
@@ -30,7 +30,7 @@ func _on_text_changed(new_text: String) -> void:
|
|||||||
submit_button.disabled = false
|
submit_button.disabled = false
|
||||||
error_label.text = ""
|
error_label.text = ""
|
||||||
|
|
||||||
func _on_web_client_tcp_received_bet_request(disallowed_bet: int) -> void:
|
func _on_web_client_tcp_received_bet_request(disallowed_bet: int, current_round: int) -> void:
|
||||||
set_disallowed_bet(disallowed_bet)
|
set_disallowed_bet(disallowed_bet)
|
||||||
if disallowed_bet == -1:
|
if disallowed_bet == -1:
|
||||||
disallowed_bet_label.text = "Bet anything"
|
disallowed_bet_label.text = "Bet anything"
|
||||||
|
|||||||
+10
-1
@@ -24,6 +24,7 @@ class Lobby:
|
|||||||
self.client_playing_order = []
|
self.client_playing_order = []
|
||||||
self.client_bets = {} # client_id: bet
|
self.client_bets = {} # client_id: bet
|
||||||
# self.currently_playing_client = 0 # index of client_playing_order
|
# self.currently_playing_client = 0 # index of client_playing_order
|
||||||
|
self.current_round = 0
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
|
|
||||||
@@ -201,6 +202,7 @@ class LobbyManager:
|
|||||||
json.dumps({
|
json.dumps({
|
||||||
"response": "request_bet",
|
"response": "request_bet",
|
||||||
"disallowed_bet": disallowed_bet,
|
"disallowed_bet": disallowed_bet,
|
||||||
|
"round": self.get_lobby(lobby_id).current_round,
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -409,6 +411,8 @@ async def process_input(message: str, websocket) -> None:
|
|||||||
data_object["cards"],
|
data_object["cards"],
|
||||||
lobby.client_playing_order,
|
lobby.client_playing_order,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
lobby_manager.get_lobby(data_object["lobby_id"]).current_round = 1
|
||||||
|
|
||||||
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}")
|
||||||
|
|
||||||
@@ -434,6 +438,7 @@ async def process_input(message: str, websocket) -> None:
|
|||||||
|
|
||||||
# Reset bets
|
# Reset bets
|
||||||
lobby_manager.get_lobby(lobby_id).client_bets = {}
|
lobby_manager.get_lobby(lobby_id).client_bets = {}
|
||||||
|
lobby_manager.get_lobby(data_object["lobby_id"]).current_round += 1
|
||||||
|
|
||||||
await lobby_manager.spread_cards(
|
await lobby_manager.spread_cards(
|
||||||
lobby_id,
|
lobby_id,
|
||||||
@@ -482,6 +487,7 @@ async def process_input(message: str, websocket) -> None:
|
|||||||
playing_client_id,
|
playing_client_id,
|
||||||
json.dumps({
|
json.dumps({
|
||||||
"response": "request_card",
|
"response": "request_card",
|
||||||
|
"round": lobby_manager.get_lobby(lobby_id).current_round
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -492,7 +498,10 @@ async def process_input(message: str, websocket) -> None:
|
|||||||
if last_client_index == (player_count - 2):
|
if last_client_index == (player_count - 2):
|
||||||
# last client to bet; limit bet options
|
# last client to bet; limit bet options
|
||||||
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 = data_object["round"] - total_bet
|
||||||
|
print(f"bets: {data_object["round"]} / {total_bet}")
|
||||||
|
if disallowed_bet < 0:
|
||||||
|
disallowed_bet = -1
|
||||||
|
|
||||||
await lobby_manager.request_bet(
|
await lobby_manager.request_bet(
|
||||||
lobby_id,
|
lobby_id,
|
||||||
|
|||||||
Reference in New Issue
Block a user