Prevent opponent from sending move out of phase

This commit is contained in:
Rob Kelly 2025-01-13 18:41:22 -07:00
parent b36baa8081
commit 76ffac3b2c

View File

@ -28,6 +28,8 @@ var opponent_wins := 0:
var player_move: Move
var opponent_move: Move
var _awaiting_opponent_move := false
@onready var player_name_label: Label = %PlayerName
@onready var opponent_name: Label = %OpponentName
@ -69,6 +71,7 @@ func set_opponent_name(opp_name: String) -> void:
@rpc("any_peer", "call_remote", "reliable", 0)
func set_opponent_move(move: Move) -> void:
if _awaiting_opponent_move:
print("Got move from opponent")
opponent_move = move
opponent_move_label.text = Move.keys()[opponent_move]
@ -79,12 +82,15 @@ func set_opponent_move(move: Move) -> void:
opponent_choosing_move.hide()
opponent_ready.show()
_check_play_condition()
else:
print("Got opponent move out of sequence!")
func start_round() -> void:
move_select.show()
opponent_ready.hide()
opponent_choosing_move.show()
_awaiting_opponent_move = true
func finish_round() -> void:
@ -133,6 +139,7 @@ func _set_player_move(value: Move) -> void:
func _check_play_condition() -> void:
if player_move and opponent_move:
_awaiting_opponent_move = false
_set_outcome_label(get_outcome())
move_select.hide()
opponent_ready.hide()