-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.gd
More file actions
102 lines (88 loc) · 2.35 KB
/
Copy pathMain.gd
File metadata and controls
102 lines (88 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
extends Node2D
onready var file = 'res://Questions.csv'
var question_list = []
var answer
var timer
var previous_highlighted_answer = -1
var past_questions = []
var state = State.Title
enum State {
Title,
Question,
Answer
}
# Called when the node enters the scene tree for the first time.
func _ready():
randomize()
load_questions()
$Timer.connect("timeout", self, "_on_timer")
$Question.hide()
func new_round():
_clear_colors()
_set_animations(true)
var question_data = rand_question()
var q_text = question_data[0]
$Question.text = q_text
$Antwort1.text = question_data[1]
$Antwort2.text = question_data[2]
$Antwort3.text = question_data[3]
answer = question_data[4]
$Timer.start()
func load_questions():
var f = File.new()
f.open(file, File.READ)
while !f.eof_reached(): # iterate through all lines until the end of file is reached
var question_set = Array(f.get_csv_line())
if question_set.size() == 5:
question_list.append(question_set)
f.close()
print(question_list)
return question_list
func rand_question():
var rand_i = randi() % question_list.size()
if past_questions.size() == question_list.size():
# End Game screen?
past_questions = []
while past_questions.has(rand_i):
rand_i = randi() % question_list.size()
var question = question_list[rand_i]
past_questions.append(rand_i)
return question
func show_answer():
$Timer.stop()
_clear_colors()
_set_animations(false)
var answer_node
if answer == "1":
answer_node = $Antwort1
if answer == "2":
answer_node = $Antwort2
if answer == "3":
answer_node = $Antwort3
$DMXControl.call_alarm()
answer_node.set_highlight(true)
answer_node.animate = true
func _on_Button2_pressed():
if state == State.Title:
$Question.show()
if state == State.Question:
show_answer()
state = State.Answer
else:
new_round()
state = State.Question
func _on_timer():
_clear_colors()
var answer_index = previous_highlighted_answer
while answer_index == previous_highlighted_answer:
answer_index = randi() % 3
_get_answer_by_index(answer_index).set_highlight(true)
previous_highlighted_answer = answer_index
func _get_answer_by_index(index):
return get_node("Antwort%s" % (index + 1))
func _clear_colors():
for i in range(0, 3):
_get_answer_by_index(i).set_highlight(false)
func _set_animations(animate: bool):
for i in range(0, 3):
_get_answer_by_index(i).animate = animate