-
Notifications
You must be signed in to change notification settings - Fork 0
/
Preguntas.gd
170 lines (162 loc) · 7.38 KB
/
Preguntas.gd
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
extends VBoxContainer
var ButtonModel = preload("res://button.tscn")
var tablero = load("res://Tablero.tres")
@onready var distribCartas = get_node("../../CenterContainer/GridContainer")
@onready var winScreen = get_node("../../WinScreen")
var analisisInfo = load("res://AnalisisInfo.tres")
func _ready():
tablero.cartaElegidaRival = tablero.cartasRivales[randi()%tablero.cartasRivales.size()]
updatePreguntas()
func updatePreguntas():
if (tablero.cartaElegida==null):
get_node("../../JugadaRival").visible = true
get_node("../../JugadaRival").position.y = get_viewport().size.y/4
get_node("../../JugadaRival/FondoVerde/Label").text = "¡Escoge tu carta!"
get_parent().visible = false
tablero.posiblesAtributos.clear()
for i in range(tablero.cartas[0].atributos.size()):
tablero.posiblesAtributos.append([])
for j in tablero.cartas:
if !tablero.posiblesAtributos[i].has(j.atributos[i]) and !j.girada:
tablero.posiblesAtributos[i].append(j.atributos[i])
for child in get_children():
if!(child is ColorRect or child.name=="VerRival"):
child.queue_free()
if !tablero.viendoRival:
for indexTipoAtributo in range(tablero.tiposAtributos.size()):
if tablero.posiblesAtributos[indexTipoAtributo].size() >1:
var nuevaLabel = Button.new()
nuevaLabel.theme = load("res://Texturas/theme2.tres")
nuevaLabel.disabled = true
nuevaLabel.text = "Para el atributo \"" + tablero.tiposAtributos[indexTipoAtributo] + "\"..."
add_child(nuevaLabel)
for atributo in tablero.posiblesAtributos[indexTipoAtributo]:
var nuevoBoton = ButtonModel.instantiate()
nuevoBoton.text = "¿Tiene tipo \""+ atributo+"\"?"
nuevoBoton.pressed.connect(self._button_pressed.bind(indexTipoAtributo, atributo))
nuevoBoton.pressed.connect(distribCartas._button_pressed)
nuevoBoton.mouse_entered.connect(distribCartas._button_hover.bind(indexTipoAtributo, atributo))
nuevoBoton.mouse_exited.connect(distribCartas._button_unhover)
nuevoBoton.pressed.connect(winScreen.check_winner)
add_child(nuevoBoton)
func _button_pressed(index, valor):
tablero.cartasRecienGiradas.clear()
distribCartas._button_unhover()
var noGiradaCounter = 0
var noGiradaCounterRival = 0
for cartaIndex in range(tablero.cartas.size()):
if !tablero.cartas[cartaIndex].girada: noGiradaCounter +=1
if !tablero.cartasRivales[cartaIndex].girada: noGiradaCounterRival +=1
if (tablero.cartaElegida and noGiradaCounter!=1 and noGiradaCounterRival!=1):
var acierto =tablero.cartaElegidaRival.atributos[index]==valor
for carta in tablero.cartas:
if ((!carta.atributos[index]== valor and acierto) or (carta.atributos[index]==valor and !acierto)) and !carta.girada:
carta.girada = true
tablero.cartasRecienGiradas.append(carta)
updatePreguntas()
get_parent().get_parent().get_node("Marcador").updateMarcador()
noGiradaCounter = 0
for carta in tablero.cartas:
if !carta.girada: noGiradaCounter +=1
if noGiradaCounter>1: break
if noGiradaCounter!=1:
jugadaRival()
func sort_ascending(a, b):
if abs(a[2]-0.5) < abs(b[2]-0.5):
return true
if abs(a[2]-0.5) == abs(b[2]-0.5):
if a[1] < b[1]:
return true
return false
func jugadaRival():
cambioDeTablero(true)
await get_tree().create_timer(3).timeout
tablero.rivalPosiblesAtributos.clear()
for i in range(tablero.cartasRivales[0].atributos.size()):
tablero.rivalPosiblesAtributos.append([])
for j in tablero.cartasRivales:
if !tablero.rivalPosiblesAtributos[i].has(j.atributos[i]) and !j.girada:
tablero.rivalPosiblesAtributos[i].append(j.atributos[i])
var dificultad = tablero.dificultadElegida
var listaOpciones = []
for tipoAtributoIndex in range(tablero.tiposAtributos.size()):
for posibleAtributo in tablero.rivalPosiblesAtributos[tipoAtributoIndex]:
var counter = 0
var cartasNoGiradas = 0
for carta in tablero.cartasRivales:
if !carta.girada:
cartasNoGiradas += 1
if carta.atributos[tipoAtributoIndex]==posibleAtributo:
counter += 1
if (abs(float(counter)/float(cartasNoGiradas))!=0 and abs(float(counter)/float(cartasNoGiradas))!=1):
listaOpciones.append([tipoAtributoIndex, posibleAtributo, abs(float(counter)/float(cartasNoGiradas))])
listaOpciones.sort_custom(sort_ascending)
#El tope de dificultad debe ser el mayor número de opciones a lo largo del juego
#(el primer estado).
var difIndex = 0
if dificultad=="Novato":
difIndex = listaOpciones.size()-1;
if dificultad=="Intermedio":
difIndex = floor(float(2)*(listaOpciones.size()-1)/3);
if dificultad=="Dificil":
difIndex = floor(float(listaOpciones.size()-1)/3);
if dificultad=="Optimo":
difIndex = 0
var mejorOpcion = listaOpciones[difIndex]
#Tras cálculo y elección, toca hacer el movimiento
var acierto =tablero.cartaElegida.atributos[mejorOpcion[0]]==mejorOpcion[1]
tablero.cartasRecienGiradasRivales.clear()
var counterRival = 0
for carta in tablero.cartasRivales:
if ((!carta.atributos[mejorOpcion[0]]== mejorOpcion[1] and acierto) or (carta.atributos[mejorOpcion[0]]==mejorOpcion[1] and !acierto) )and !carta.girada:
tablero.cartasRecienGiradasRivales.append(carta)
carta.girada = true
if !carta.girada: counterRival +=1
get_parent().get_parent().get_node("JugadaRival/FondoVerde/Label").text = "El rival ha preguntado: \n\n¿Tiene tipo \""+ mejorOpcion[1]+"\" en el atributo \"" + tablero.tiposAtributos[mejorOpcion[0]] + "\"?\n\n Y ha tumbado "+ str(tablero.cartasRecienGiradasRivales.size())+ " cartas"
await get_tree().create_timer(3.5).timeout
get_parent().get_parent().get_node("CenterContainer/GridContainer")._on_ver_rival_pressed()
if counterRival ==1:
await get_tree().create_timer(1).timeout
winScreen.check_winner()
else:
cambioDeTablero(false)
func _on_ver_rival_pressed():
tablero.viendoRival = !tablero.viendoRival
updatePreguntas()
get_parent().get_parent().get_node("CenterContainer/GridContainer")._on_ver_rival_pressed()
func cambioDeTablero(verRival, comesFromWinScreen = false):
get_parent().get_parent().get_node("Marcador").updateMarcador()
var jugadaRivalScn = get_parent().get_parent().get_node("JugadaRival")
var infoTurno = get_parent().get_parent().get_node("InfoTurno")
if verRival:
jugadaRivalScn.position.y = -jugadaRivalScn.size.y
visible = false
get_parent().get_parent().get_node("InfoTurno/Label").text = "Turno del Rival"
else:
visible = true
get_parent().get_parent().get_node("InfoTurno/Label").text = "Tu turno"
if !comesFromWinScreen: await get_tree().create_timer(2).timeout
var tween = get_tree().create_tween()
tween.tween_property(infoTurno, "modulate:a", 1, 0.5)
tween.tween_property(infoTurno, "modulate:a", 1, 2)
tween.tween_property(infoTurno, "modulate:a", 0, 0.5)
var tween2 = 0
if verRival:
tween2 = get_tree().create_tween()
tween2.tween_property(jugadaRivalScn, "position:y", -jugadaRivalScn.size.y, 2.5)
tween2.tween_property(jugadaRivalScn, "position:y", get_viewport().size.y/4, 1)
await get_tree().create_timer(0.5).timeout
if !verRival: jugadaRivalScn.position.y = -jugadaRivalScn.size.y
jugadaRivalScn.visible = true
infoTurno.set_mouse_filter(Control.MOUSE_FILTER_STOP)
_on_ver_rival_pressed()
if verRival:
get_parent().get_parent().texture = load("res://Texturas/TableroRival.png")
else:
get_parent().get_parent().texture = load("res://Texturas/Tablero.png")
await get_tree().create_timer(2.5).timeout
infoTurno.set_mouse_filter(Control.MOUSE_FILTER_IGNORE)
tween.kill()
if verRival:
await get_tree().create_timer(1).timeout
tween2.kill()