-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL5T1-T2.js
More file actions
61 lines (55 loc) · 2.38 KB
/
L5T1-T2.js
File metadata and controls
61 lines (55 loc) · 2.38 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
'use strict';
const settings = {
rowCount: 9,
colCount: 9,
blackCellColor: '#AA3333',
whiteCellColor: '#eee',
letters: ['', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'],
numbers: [8, 7, 6, 5, 4, 3, 2, 1, ''],
chessPieces:
[['L5/br.png', 'L5/bn.png', 'L5/bb.png', 'L5/bq.png', 'L5/bk.png', 'L5/bb.png', 'L5/bn.png', 'L5/br.png'],
['L5/bp.png', 'L5/bp.png', 'L5/bp.png', 'L5/bp.png', 'L5/bp.png', 'L5/bp.png', 'L5/bp.png', 'L5/bp.png'],
['', '', '', '', '', '', '', ''],
['', '', '', '', '', '', '', ''],
['', '', '', '', '', '', '', ''],
['', '', '', '', '', '', '', ''],
['L5/wp.png', 'L5/wp.png', 'L5/wp.png', 'L5/wp.png', 'L5/wp.png', 'L5/wp.png', 'L5/wp.png', 'L5/wp.png'],
['L5/wr.png', 'L5/wn.png', 'L5/wb.png', 'L5/wq.png', 'L5/wk.png', 'L5/wb.png', 'L5/wn.png', 'L5/wr.png']]
};
const game = {
settings,
containerElement: null,
cellElements: [],
run() {
this.initChessBoard();
},
initChessBoard() {
this.containerElement = document.querySelector('#chessgame');
for (let row = 0; row < this.settings.rowCount; row++) {
const trElem = document.createElement('tr');
this.containerElement.appendChild(trElem);
for (let col = 0; col < this.settings.colCount; col++) {
const cell = document.createElement('td');
trElem.appendChild(cell);
if ((col != 0) && (row != 8)) {
cell.style.backgroundImage = `url(${this.settings.chessPieces[row][col - 1]})`;
cell.style.backgroundSize = "50px 50px";
cell.style.backgroundRepeat = 'no-repeat';
if ((row + col) % 2 != 1) {
cell.style.backgroundColor = this.settings.blackCellColor;
} else {
cell.style.backgroundColor = this.settings.whiteCellColor;
}
this.cellElements.push(cell);
} else {
cell.style.backgroundColor = '#FFFFFF';
cell.style.textAlign = 'center';
cell.style.border = '0px';
if (row == 8) cell.innerText = this.settings.letters[col];
if (col == 0) cell.innerText = this.settings.numbers[row];
}
}
}
},
};
game.run();