-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDado.js
More file actions
62 lines (40 loc) · 1.43 KB
/
Dado.js
File metadata and controls
62 lines (40 loc) · 1.43 KB
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
class Dado {
constructor(numeroMaxDado) {
this._numeroActual = "?";
this._numeros = new Array();
this._numeroMaxDado = numeroMaxDado;
this._activo = false;
this._divDado = document.createElement("div");
this._divDado.classList.add("dado");
this._divDado.textContent = this.numeroActual;
for (let i = 0; i < numeroMaxDado; i++) {
this._numeros.push(i + 1);
}
}
get activo() { return this._activo; }
get numeroMaxDado() { return this._numeroMaxDado; }
get numeroActual() { return this._numeroActual; }
get numeros() { return this._numeros; }
get divDado() { return this._divDado; }
set numeroActual(numero) {
this._numeroActual = numero;
this.divDado.textContent = numero
}
set activo(bool) { this._activo = bool; }
tirar() {
this.numeroActual = this.numeros[Math.floor(Math.random() * this.numeroMaxDado)];
}
colorear(resultado) {
switch (resultado) {
case "victoria":
this.divDado.style.backgroundColor = "#4caf50";
break;
case "derrota":
this.divDado.style.backgroundColor = "#f44336";
break;
default:
this.divDado.style.backgroundColor = "#fafafa";
break;
}
}
}