Added draw game option for non hotseat games
This commit is contained in:
parent
0385858d4f
commit
416c48891d
4 changed files with 241 additions and 74 deletions
|
|
@ -5,22 +5,24 @@ const RULES = preload("res://UI/Rules/Rules.tscn")
|
|||
|
||||
@onready var surrender_button = $VBoxContainer/SurrenderButton
|
||||
@onready var pass_round_button = $VBoxContainer/PassRoundButton
|
||||
@onready var offer_draw_button = $VBoxContainer/OfferDrawButton
|
||||
|
||||
var is_blacks_turn: bool = false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
GameEvents.draw_answer_sent.connect(_on_draw_answer_sent)
|
||||
|
||||
GameEvents.turn_started.connect(_on_turn_started)
|
||||
|
||||
if GameData.is_hot_seat:
|
||||
offer_draw_button.disabled = true
|
||||
offer_draw_button.visible = false
|
||||
|
||||
func _on_turn_started(round_num: int, map: HexGrid, _is_blacks_turn: bool) -> void:
|
||||
is_blacks_turn = _is_blacks_turn
|
||||
surrender_button.disabled = GameData.is_player_black != _is_blacks_turn and not GameData.is_hot_seat
|
||||
pass_round_button.disabled = GameData.is_player_black != _is_blacks_turn and not GameData.is_hot_seat
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
pass
|
||||
|
||||
|
||||
func _on_rules_button_pressed():
|
||||
var rules = RULES.instantiate()
|
||||
|
|
@ -48,3 +50,35 @@ func _on_surrender_button_pressed():
|
|||
|
||||
func _on_pass_round_button_pressed():
|
||||
GameEvents.pass_round.emit()
|
||||
|
||||
|
||||
@rpc("any_peer", "call_remote")
|
||||
func receive_draw_offer() -> void:
|
||||
offer_draw_button.disabled = true
|
||||
GameEvents.draw_offer_received.emit()
|
||||
# other player wants to draw the game, show yes/no popup
|
||||
pass
|
||||
|
||||
@rpc("any_peer", "call_remote")
|
||||
func receive_draw_answer(accepted: bool) -> void:
|
||||
GameEvents.draw_answer_received.emit(accepted)
|
||||
offer_draw_button.disabled = false
|
||||
pass
|
||||
|
||||
@rpc("any_peer", "call_local")
|
||||
func _end_game() -> void:
|
||||
GameEvents.game_over.emit(true, true)
|
||||
pass
|
||||
|
||||
func _on_draw_answer_sent(accepted: bool) -> void:
|
||||
receive_draw_answer.rpc(accepted)
|
||||
|
||||
if accepted:
|
||||
_end_game.rpc()
|
||||
else:
|
||||
offer_draw_button.disabled = false
|
||||
|
||||
func _on_offer_draw_button_pressed():
|
||||
offer_draw_button.disabled = true
|
||||
GameEvents.draw_offer_sent.emit()
|
||||
receive_draw_offer.rpc()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue