This repository has been archived on 2026-05-26. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
magician/game_client.gd
T

67 lines
1.8 KiB
GDScript
Raw Normal View History

class_name GameClient
extends Node
@export var web_client: WebClientTCP
@export var start_game_button: Button
@export var play_card_button: Button
@export var bet_container: Control
@export var bet_input: LineEdit
var _is_host: bool = false
var _current_player_count: int = 0
var _current_round: int = 0
var _max_rounds: int = 0
func _set_host(is_host: bool) -> void:
_is_host = is_host
func _start_next_round() -> void:
_current_round += 1
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
web_client.start_game()
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 _on_web_client_tcp_client_joined_lobby(client_name: String, connected_client_names: Array[String]) -> void:
_update_player_count(connected_client_names.size())
func _on_web_client_tcp_client_left_lobby(client_name: String, connected_client_names: Array[String]) -> void:
_update_player_count(connected_client_names.size())
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()
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()