-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
246 lines (227 loc) · 6.64 KB
/
index.html
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="/socket.io/socket.io.js"></script>
<style>
#boxy{
display: flex;
flex-direction: row;
}
.masterSquare{
display: flex;
flex-wrap: wrap;
max-width: 288px;
border: solid;
}
a{
border: solid;
border-color: black;
width: 30px;
height: 30px;
}
.basic{
border: solid;
border-color: black;
width: 30px;
height: 30px;
font-size: 0px;
}
.listy {
font-size: larger;
}
.rojoDiv{
align-self: auto;
background-color: red;
min-height: 25px;
min-width: 25px;
border: solid;
font-size: 0px;
}
.negroDiv{
align-self: auto;
background-color: rgb(15, 12, 12);
min-height: 25px;
min-width: 25px;
border: solid;
font-size: 0px;
}
.verdeDiv{
align-self: auto;
background-color: rgb(37, 148, 43);
min-height: 25px;
min-width: 25px;
border: solid;
font-size: 0px;
}
.azulDiv{
align-self: auto;
background-color: rgb(64, 32, 211);
min-height: 25px;
min-width: 25px;
border: solid;
font-size: 0px;
}
.rosaDiv{
align-self: auto;
background-color: rgb(247, 0, 255);
min-height: 25px;
min-width: 25px;
border: solid;
font-size: 0px;
}
.blancoDiv{
align-self: auto;
background-color: rgb(255, 255, 255);
min-height: 25px;
min-width: 25px;
border: solid;
font-size: 0px;
}
</style>
</head>
<body>
<div id="boxy" onclick="recorrer()">
<div class="masterSquare">
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
<a></a>
</div>
<div class="listy">
<ol>Verde - <input id="verde" type="checkbox"></ol>
<ol>Rojo - <input id="rojo" type="checkbox"></ol>
<ol>Azul - <input id="azul" type="checkbox"></ol>
<ol>Negro - <input id="negro" type="checkbox"></ol>
<ol>Rosa - <input id="rosa" type="checkbox"></ol>
<ol>Blanco - <input id="blanco" type="checkbox"></ol>
</div>
<button value="reset" id="reseti"></button>
</div>
<script>
//once the page is loaded we listen for a click in the table
document.addEventListener("DOMContentLoaded",() =>{
let modelando = document.querySelectorAll("a");
modelando.forEach(function(h){h.addEventListener("click", loco);}) //we take all the "a", our squares, and if one is clicked on our function starts
var color= null; //selfexplanatory, is the color we choose for the square. Right now is empty
//Taking the value of the color we are gonna use later when a square is clicked on
function select(){
var verde = document.getElementById("verde");
var rojo = document.getElementById("rojo");
var azul = document.getElementById("azul");
var negro = document.getElementById("negro");
var rosa = document.getElementById("rosa");
var blanco = document.getElementById("blanco");
if(verde.checked){color="verdeDiv";rosa.checked=false; rojo.checked=false; azul.checked=false; negro.checked=false; blanco.checked=false;}
if(rojo.checked){color="rojoDiv"; rosa.checked=false; verde.checked=false; azul.checked=false; negro.checked=false; blanco.checked=false;}
if(azul.checked){color="azulDiv"; rosa.checked=false; rojo.checked=false; verde.checked=false; negro.checked=false; blanco.checked=false;}
if(negro.checked){color="negroDiv"; rosa.checked=false; rojo.checked=false; azul.checked=false; verde.checked=false; blanco.checked=false;}
if(rosa.checked){color="rosaDiv"; verde.checked=false; rojo.checked=false; azul.checked=false; negro.checked=false; blanco.checked=false;}
if(blanco.checked){color="blancoDiv"; verde.checked=false; rojo.checked=false; azul.checked=false; negro.checked=false; rosa.checked=false;}
}
var lista = ["rojoDiv", "verdeDiv", "azulDiv", "negroDiv", "rosaDiv", "blancoDiv"];
//When a square is clicked on we remove it's class if any, add "basic" class just because, take the color value from the html, add that color as class to the square and a name
function loco(){
for(var i=0; i<6; i++){this.classList.remove(lista[i]);}
select();
this.classList.add(color);
this.innerHTML = color;
}
});
//Once we finish our operation, we send the new values to the server, read the new values from there and apply the changes
var socket = io();
var cambiolor = null;
var cuadrados = Array.from(document.querySelectorAll("a"));
var i;
function recorrer(){
for(i=0; i<cuadrados.length; i++){
if (cuadrados[i].innerHTML === "verdeDiv"){
socket.emit("repintado", [i, "verdeDiv"]);
cuadrados[i].innerHTML = "";}
if (cuadrados[i].innerHTML === "rojoDiv"){
socket.emit("repintado", [i, "rojoDiv"]);
cuadrados[i].innerHTML = "";}
if (cuadrados[i].innerHTML === "azulDiv"){
socket.emit("repintado", [i, "azulDiv"]);
cuadrados[i].innerHTML = "";}
if (cuadrados[i].innerHTML === "negroDiv"){
socket.emit("repintado", [i, "negroDiv"]);
cuadrados[i].innerHTML = "";}
if (cuadrados[i].innerHTML === "blancoDiv"){
socket.emit("repintado", [i, "blancoDiv"]);
cuadrados[i].innerHTML = "";}
if (cuadrados[i].innerHTML === "rosaDiv"){
socket.emit("repintado", [i, "rosaDiv"]);
cuadrados[i].innerHTML = "";}
};
}
socket.on("repintado", function(valores){
var numero = valores[0];
var coloro = valores[1];
console.log(valores[1]);
var lista = ["rojoDiv", "verdeDiv", "azulDiv", "negroDiv", "rosaDiv", "blancoDiv"];
for(var i=0; i<6; i++){cuadrados[numero].classList.remove(lista[i]);}
cuadrados[numero].classList.add(coloro);
});
</script>
</body>