generated from krampus/template-godot4
Prevent opponent from sending move out of phase
This commit is contained in:
parent
b36baa8081
commit
76ffac3b2c
@ -28,6 +28,8 @@ var opponent_wins := 0:
|
|||||||
var player_move: Move
|
var player_move: Move
|
||||||
var opponent_move: Move
|
var opponent_move: Move
|
||||||
|
|
||||||
|
var _awaiting_opponent_move := false
|
||||||
|
|
||||||
@onready var player_name_label: Label = %PlayerName
|
@onready var player_name_label: Label = %PlayerName
|
||||||
@onready var opponent_name: Label = %OpponentName
|
@onready var opponent_name: Label = %OpponentName
|
||||||
|
|
||||||
@ -69,22 +71,26 @@ func set_opponent_name(opp_name: String) -> void:
|
|||||||
|
|
||||||
@rpc("any_peer", "call_remote", "reliable", 0)
|
@rpc("any_peer", "call_remote", "reliable", 0)
|
||||||
func set_opponent_move(move: Move) -> void:
|
func set_opponent_move(move: Move) -> void:
|
||||||
print("Got move from opponent")
|
if _awaiting_opponent_move:
|
||||||
opponent_move = move
|
print("Got move from opponent")
|
||||||
opponent_move_label.text = Move.keys()[opponent_move]
|
opponent_move = move
|
||||||
if move == Move.NONE:
|
opponent_move_label.text = Move.keys()[opponent_move]
|
||||||
opponent_ready.hide()
|
if move == Move.NONE:
|
||||||
opponent_choosing_move.show()
|
opponent_ready.hide()
|
||||||
|
opponent_choosing_move.show()
|
||||||
|
else:
|
||||||
|
opponent_choosing_move.hide()
|
||||||
|
opponent_ready.show()
|
||||||
|
_check_play_condition()
|
||||||
else:
|
else:
|
||||||
opponent_choosing_move.hide()
|
print("Got opponent move out of sequence!")
|
||||||
opponent_ready.show()
|
|
||||||
_check_play_condition()
|
|
||||||
|
|
||||||
|
|
||||||
func start_round() -> void:
|
func start_round() -> void:
|
||||||
move_select.show()
|
move_select.show()
|
||||||
opponent_ready.hide()
|
opponent_ready.hide()
|
||||||
opponent_choosing_move.show()
|
opponent_choosing_move.show()
|
||||||
|
_awaiting_opponent_move = true
|
||||||
|
|
||||||
|
|
||||||
func finish_round() -> void:
|
func finish_round() -> void:
|
||||||
@ -133,6 +139,7 @@ func _set_player_move(value: Move) -> void:
|
|||||||
|
|
||||||
func _check_play_condition() -> void:
|
func _check_play_condition() -> void:
|
||||||
if player_move and opponent_move:
|
if player_move and opponent_move:
|
||||||
|
_awaiting_opponent_move = false
|
||||||
_set_outcome_label(get_outcome())
|
_set_outcome_label(get_outcome())
|
||||||
move_select.hide()
|
move_select.hide()
|
||||||
opponent_ready.hide()
|
opponent_ready.hide()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user