extends Control
enum Choice {ROCK, PAPER, SCISSORS} # исправил опечатку SCISSARS -> SCISSORS
@onready var computer_chose_pik = $Sprite2D # если хочешь оставить для фона или чего-то ещё
@onready var sound_win = $sound_win
@onready var sound_lus = $sound_lus
@export var countdown_label: Label
@export var result_label: Label
@export var player_texture: TextureRect
@export var computer_texture: TextureRect
var rock_texture = preload("res://rock.png")
var paper_texture = preload("res://paper.png")
var scissors_texture = preload("res://scissors.png")
var countdown_words = ["камень", "ножницы", "бумага", "раз", "два", "три"]
var current_word_index = 0
var is_counting = false
var player_choice = -1
var computer_choice = -1
func _ready() -> void:
randomize() # для случайности
# Запуск считалки
func start_countdown(p_choice: int, c_choice: int):
result_label.text = ""
computer_texture.texture = null
if is_counting:
return
is_counting = true
player_choice = p_choice
computer_choice = c_choice
current_word_index = 0
countdown_label.text = countdown_words[current_word_index]
$CountdownTimer.start()
# Сигнал таймера (имя должно быть таким, как создалось при подключении)
func _on_countdown_timer_timeout():
current_word_index += 1
if current_word_index < countdown_words.size():
countdown_label.text = countdown_words[current_word_index]
else:
$CountdownTimer.stop()
is_counting = false
show_result()
# Установка текстуры для TextureRect
func set_choice_texture(texture_rect: TextureRect, choice: int):
match choice:
0:
texture_rect.texture = rock_texture
1:
texture_rect.texture = paper_texture
2:
texture_rect.texture = scissors_texture
# Показ результата после считалки
func show_result():
# Устанавливаем картинки
set_choice_texture(player_texture, player_choice)
set_choice_texture(computer_texture, computer_choice)
# Определяем победителя и выводим текст
if player_choice == computer_choice:
result_label.text = "Ничья!"
elif (player_choice == 0 and computer_choice == 2) or \
(player_choice == 2 and computer_choice == 1) or \
(player_choice == 1 and computer_choice == 0):
result_label.text = "Вы выиграли!"
sound_win.play() # звук победы
else:
result_label.text = "Вы проиграли!"
sound_lus.play() # звук поражения
# Обработчики кнопок (теперь запускают считалку)
func _on_b_rock_pressed() -> void:
computer_choice = randi_range(0, 2) # случайный выбор компьютера
start_countdown(Choice.ROCK, computer_choice)
func _on_b_paper_pressed() -> void:
computer_choice = randi_range(0, 2)
start_countdown(Choice.PAPER, computer_choice)
func _on_b_scissors_pressed() -> void:
computer_choice = randi_range(0, 2)
start_countdown(Choice.SCISSORS, computer_choice)