server: added more gameplay commands and determine playing order on start_game command
This commit is contained in:
+33
-4
@@ -5,15 +5,30 @@ extends Node
|
||||
@export var start_game_button: Button
|
||||
|
||||
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
|
||||
if is_host:
|
||||
start_game_button.show()
|
||||
else:
|
||||
start_game_button.hide()
|
||||
|
||||
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:
|
||||
@@ -21,3 +36,17 @@ func _on_create_lobby_button_pressed() -> void:
|
||||
|
||||
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())
|
||||
|
||||
Reference in New Issue
Block a user