|
@@ -1,19 +1,24 @@
|
|
|
+class_name ConteneurDeBriques
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
|
-signal partie_gagnee
|
|
|
+signal plus_de_briques
|
|
|
|
|
|
-@onready var nombre_briques: int = get_children().size()
|
|
|
+@onready var nombre_enfants: int = get_children().size()
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
for node: Node in get_children():
|
|
|
- assert(node is Brique, "Ce conteneur ne peut contenir que des briques")
|
|
|
- var brique: Brique = node as Brique
|
|
|
- brique.eclatee.connect(_quand_brique_eclatee)
|
|
|
+ assert(node is Brique or node is ConteneurDeBriques, "Ne peut contenir que des briques")
|
|
|
+ if node is Brique:
|
|
|
+ var brique: Brique = node as Brique
|
|
|
+ brique.eclatee.connect(_quand_enfant_detruit)
|
|
|
+ elif node is ConteneurDeBriques:
|
|
|
+ var contenant: ConteneurDeBriques = node as ConteneurDeBriques
|
|
|
+ contenant.plus_de_briques.connect(_quand_enfant_detruit)
|
|
|
|
|
|
|
|
|
-func _quand_brique_eclatee() -> void:
|
|
|
- nombre_briques -= 1
|
|
|
- if nombre_briques <= 0:
|
|
|
- partie_gagnee.emit()
|
|
|
+func _quand_enfant_detruit() -> void:
|
|
|
+ nombre_enfants -= 1
|
|
|
+ if nombre_enfants <= 0:
|
|
|
+ plus_de_briques.emit()
|