-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.js
44 lines (36 loc) · 938 Bytes
/
Card.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
/**
* Clase Card que representa a una carta del tablero.
*/
class Card {
constructor(tipo, x, y) {
this.tipo = tipo;
this.x = x;
this.y = y;
this.flipped = false;
this.cell = this.findCell();
}
/**
* Método para dar la vuelta a esta carta en concreto.
*/
flip() {
let cell = this.findCell();
cell.setAttribute("src", this.tipo.imagen);
this.flipped = true;
}
/**
* Se encarga de volver a dar la vuelta a la carta.
*/
esconder() {
let cell = this.findCell();
cell.setAttribute("src", "img/carta_dada_la_vuelta.png");
this.flipped = false;
}
/**
* Método que devuelve un elemento div que se corresponde con la celda x,y
* en el tablero HTML.
*/
findCell() {
let id = this.x.toString() + this.y.toString();
return document.getElementById(id);
}
}