+
{% endfor %}
@@ -25,9 +25,33 @@
{% block script %}
const gridSize = {{ level + 3 }};
+ updateLights();
+
+ function updateLights() {
+ document.querySelectorAll('.light').forEach(light => {
+ const [x, y] = light.id.split('-').slice(1).map(Number);
+ const checkbox = document.querySelector(`#checkbox-${x}-${y}`);
+
+ if(checkbox.checked) {
+ light.classList.add('bg-danger-subtle');
+ } else {
+ light.classList.remove('bg-danger-subtle');
+ }
+ });
+ }
+
+ document.querySelectorAll('.light').forEach(light => {
+ light.addEventListener('click', function() {
+ const [x, y] = this.id.split('-').slice(1).map(Number);
+ const checkbox = document.querySelector(`#checkbox-${x}-${y}`);
+
+ checkbox.click();
+ updateLights();
+ });
+ });
+
document.querySelectorAll('.form-check-input').forEach(checkbox => {
checkbox.addEventListener('change', function() {
- checkbox.classList.toggle('clicked');
const [x, y] = this.id.split('-').slice(1).map(Number);
const neighbors = [
[x - 1, y],