-
Notifications
You must be signed in to change notification settings - Fork 0
/
script copy.js
146 lines (115 loc) · 4.85 KB
/
script copy.js
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
// Axel Cotón Gutiérrez Copyright 2024
let totalFormasGeneradas = 0;
function allowDrop(e) {
e.preventDefault();
}
function dragStart(e) {
e.dataTransfer.setData("text", e.target.id);
}
function drop(e) {
e.preventDefault();
var data = e.dataTransfer.getData("text");
var figura = document.getElementById(data);
e.target.appendChild(figura);
}
function generarFormas() {
const colores = ['white', 'black', 'pink', 'brown', 'green', 'red', 'yellow', 'blue', 'orange', 'violet'];
const formas = ['square', 'circle', 'rombus'];
const todasLasFormas = [];
const color1 = seleccionarColorAleatorio();
let color2;
do {
color2 = seleccionarColorAleatorio();
} while (color1 === color2);
const totalFormas = Math.floor(Math.random() * 5) + 2;
let formasColor1 = 1;
let formasColor2 = 1;
for (let i = 0; i < totalFormas - 2; i++) {
Math.random() < 0.5 ? formasColor1++ : formasColor2++;
}
formasColor1 = Math.min(formasColor1, 3);
formasColor2 = Math.min(formasColor2, 3);
agregarFormas(todasLasFormas, color1, formasColor1, 'color1');
agregarFormas(todasLasFormas, color2, formasColor2, 'color2');
totalFormasGeneradas = totalFormas;
mezclarFormas(todasLasFormas);
todasLasFormas.forEach(forma => {
document.getElementById('shapes-container').appendChild(forma);
});
document.getElementById('color-indicator-1').style.backgroundColor = color1;
document.getElementById('color-indicator-2').style.backgroundColor = color2;
}
function seleccionarColorAleatorio() {
const colores = ['white', 'black', 'pink', 'brown', 'green', 'red', 'yellow', 'blue', 'orange', 'violet'];
return colores[Math.floor(Math.random() * colores.length)];
}
function agregarFormas(arr, color, num, colorClass) {
const formas = ['square', 'circle', 'rombus'];
for (let i = 0; i < num; i++) {
const forma = formas[Math.floor(Math.random() * formas.length)];
const formaDiv = document.createElement('div');
formaDiv.id = 'forma-' + color + '-' + i;
formaDiv.className = 'shape ' + forma + ' ' + color;
formaDiv.classList.add(colorClass);
formaDiv.draggable = true;
formaDiv.addEventListener('dragstart', dragStart);
arr.push(formaDiv);
}
}
function mezclarFormas(arr) {
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
}
function comprobarResultados() {
const contenedor1 = document.getElementById('color-container-1');
const contenedor2 = document.getElementById('color-container-2');
const resultDisplay = document.getElementById('result');
if (contenedor1.children.length + contenedor2.children.length < totalFormasGeneradas) {
resultDisplay.textContent = 'Antes de comprobar, introduce todos los elementos en los contenedores.';
resultDisplay.style.color = 'orange';
return;
}
const esCorrectoContenedor1 = Array.from(contenedor1.children).every(elem => elem.classList.contains('color1'));
const esCorrectoContenedor2 = Array.from(contenedor2.children).every(elem => elem.classList.contains('color2'));
if (esCorrectoContenedor1 && esCorrectoContenedor2) {
resultDisplay.textContent = '¡Correcto! Los contenedores tienen las figuras geométricas del color adecuado.';
resultDisplay.style.color = 'green';
} else {
resultDisplay.textContent = 'Algunas figuras geométricas están mal colocadas. Vuelve a intentarlo';
resultDisplay.style.color = 'red';
}
}
function reiniciarJuego() {
const contenedor1 = document.getElementById('color-container-1');
const contenedor2 = document.getElementById('color-container-2');
const shapesContainer = document.getElementById('shapes-container');
const resultDisplay = document.getElementById('result');
contenedor1.innerHTML = '';
contenedor2.innerHTML = '';
shapesContainer.innerHTML = '';
resultDisplay.textContent = '';
// Volver a generar y mezclar las formas
generarFormas();
}
document.addEventListener('DOMContentLoaded', function() {
generarFormas();
const botonReiniciar = document.querySelector('.guess-button[onclick="nextQuestion()"]');
if (botonReiniciar) {
botonReiniciar.addEventListener('click', reiniciarJuego);
}
var menuToggle = document.querySelector('.menu-toggle');
var menu = document.querySelector('.menu');
menuToggle.addEventListener('click', function() {
menu.classList.toggle('active');
});
});
// Navegación
document.addEventListener('DOMContentLoaded', function() {
var menuToggle = document.querySelector('.menu-toggle');
var menu = document.querySelector('.menu');
menuToggle.addEventListener('click', function() {
menu.classList.toggle('active');
});
});