-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.js
108 lines (87 loc) · 2.46 KB
/
object.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
class Cell {
constructor(element, row, column) {
this.element = element;
this.row = row;
this.column = column;
this.occupied = false;
this.team = null;
this.bgc = null;
this.piece = null;
this.piecediv = null;
this.element.dataset.row = row ;
this.element.dataset.column = column;
this.element.className = 'cell';
}
setRow(newRow) {
this.row = newRow;
this.element.dataset.row = newRow;
}
setColumn(newColumn) {
this.column = newColumn;
this.element.dataset.row = newColumn;
}
setBgc(newBgc) {
this.bgc = newBgc;
this.element.style.backgroundColor = newBgc;
}
setBorder(){
this.element.style.border = '1px solid #333';
}
removeBorder(){
this.element.style.border = null;
}
setTeam(newTeam) {
this.team = newTeam;
}
removeTeam() {
this.team = null;
}
setPiece(newPiece) {
this.piece = newPiece.id;
this.toggleOccupied();
this.piecediv = newPiece;
this.team = this.piece.includes('_w')?'w':'b';
newPiece.style.opacity = 0;
setTimeout(() => {
this.element.appendChild(newPiece);
}, 150);
setTimeout(() => {
newPiece.style.transition = 'opacity 0.3s ease-in-out';
newPiece.style.opacity = 1;
}, 300);
}
removePiece() {
this.occupied = false;
if (this.piecediv) {
const pieceToRemove = this.piecediv;
if (pieceToRemove && this.element.contains(pieceToRemove)) {
pieceToRemove.style.transition = 'opacity 0.3s ease-in-out';
pieceToRemove.style.opacity = 0;
setTimeout(() => {
if (this.element.contains(pieceToRemove)) {
this.element.removeChild(pieceToRemove);
}
}, 150);
}
this.piece = null;
this.piecediv = null;
this.team = null;
}
}
setBullet(turn) {
if(turn){
this.element.appendChild(bullet_b);
}else{
this.element.appendChild(bullet_w);
}
}
removeBullet(){
const bullet = this.element.querySelector('.bullet');
if (bullet) {
this.element.removeChild(bullet);
}
}
toggleOccupied() {
this.occupied = !this.occupied;
}
}