class_name GameClient extends Node @export var web_client: WebClient @export var start_game_button: Button @export var play_card_button: Button @export var bet_container: Control @export var bet_input: LineEdit @export var round_label: Label @export var player_hand: PlayerHand var _is_host: bool = false var _current_player_count: int = 0 var _current_round: int = 0 var _cards_left: int = 0 var _max_rounds: int = 0 func _set_host(is_host: bool) -> void: _is_host = is_host func _start_next_play() -> void: _cards_left -= 1 if _cards_left == 0: _start_next_round() else: web_client.start_next_play() func _start_next_round() -> void: if _current_round == _max_rounds: web_client.end_game() # end game else: _current_round += 1 _cards_left = _current_round web_client.start_next_round(_current_round) func _get_max_rounds(player_count: int) -> int: match player_count: 3: return 20 4: return 15 5: return 12 _: # 6 return 10 func _on_start_game_button_pressed() -> void: _current_round = 1 _cards_left = _current_round web_client.start_game() start_game_button.hide() func _on_create_lobby_button_pressed() -> void: _set_host(true) func _on_join_lobby_button_pressed() -> void: _set_host(false) func _update_player_count(player_count: int) -> void: _current_player_count = player_count _max_rounds = _get_max_rounds(player_count) if _is_host and player_count >= 3: start_game_button.show() else: start_game_button.hide() func _set_current_round(round: int) -> void: _current_round = round round_label.text = str(_current_round) func _on_player_hand_card_selected(card_id: int) -> void: play_card_button.disabled = card_id == -1 func _on_submit_bet_button_pressed() -> void: bet_container.hide() print("current round! " + str(_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, current_round: int) -> void: bet_input.text = "" bet_container.show() _set_current_round(current_round) func _on_web_client_tcp_request_next_round() -> void: _start_next_round() func _on_player_hand_0_card_played(card_id: int) -> void: web_client.play_card(card_id) $Label.hide() func _on_web_client_tcp_notify_play_card_request() -> void: $Label.show() player_hand.allow_clicking_cards() func _on_web_client_tcp_received_win() -> void: $WinLabel.show() await get_tree().create_timer(1.0).timeout $WinLabel.hide() func _on_web_client_tcp_request_next_play() -> void: _start_next_play() func _on_web_client_connected_clients_changed(connected_client_names: Array[String]) -> void: _update_player_count(connected_client_names.size())