-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
100 lines (93 loc) · 3.97 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chess board</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<span style="color:rgb(255, 255, 255); font-family:sans-serif; font-size:30px;">
Knight Attack
</span>
<br><br>
<div class="container">
<table width="350px" cellspacing="0">
<tr>
<th>0</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
<th>7</th>
</tr>
</table>
</div>
<span id="txt" style="color:rgb(255, 255, 255); font-family:sans-serif; font-size:15px;">Console to see Raw Data in
MxN</span>
<script type="text/javascript">
var chessTable = document.getElementsByTagName('table')[0];
let axisX = 0, axisY = 0;
for (var i = 0; i < 8; i++) {
var tr = document.createElement('tr');
for (var j = 0; j < 8; j++) {
// Create a cell
var td = document.createElement('td');
if ((i + j) % 2 == 0) { //if even
const td = `<td class="cell whitecell" id = "${i} ${j}" onclick = "possibleMoves(${i},${j})"></td> `;
tr.innerHTML += td;
}
else {
const td = `<td class="cell blackcell" id = "${i} ${j}" onclick = "possibleMoves(${i},${j})" ></ td>`;
tr.innerHTML += td;
}
var possibleMoves = (n, m) => {
document.getElementById(`${n} ${m}`).innerHTML += `<img src="https://img.icons8.com/external-nawicon-flat-nawicon/64/null/external-chess-business-nawicon-flat-nawicon.png" width="25px" class="knight"/>`
// let squares = [[0, 1, 0, 1, 0, 1, 0, 1],
// [1, 0, 1, 0, 1, 0, 1, 0],
// [0, 1, 0, 1, 0, 1, 1, 0],
// [1, 0, 1, 0, 1, 0, 1, 0],
// [0, 1, 0, 1, 0, 1, 0, 1]
// [1, 0, 1, 0, 1, 0, 1, 0],
// [0, 1, 0, 1, 0, 1, 0, 1],
// [1, 0, 1, 0, 1, 0, 1, 0]]
// All possible moves of a knight
let X = [2, 1, -1, -2, -2, -1, 1, 2];
let Y = [1, 2, 2, 1, -1, -2, -2, -1];
let arraysss = [];
for (let k = 0; k < 8; k++) {
axisX = n + X[k];
axisY = m + Y[k];
if (axisX >= 0 && axisY >= 0 && axisX < 8 && axisY < 8) {
arraysss.push([axisX, axisY]);
}
}
const span = document.getElementById('txt');
for (z of arraysss) {
z.forEach((element, index) => {
console.log(z[0], z[1])
var newTd = document.getElementById(`${z[0]} ${z[1]}`);
newTd.style.background = "green"
setTimeout(function () {
newTd.style.removeProperty("background-color");
document.getElementsByTagName('img')[0].style.display = 'none'
}, 2000);
});
}
}
}
var ff = document.getElementsByTagName('table')[0];
ff.insertAdjacentElement('beforeend', tr)
}
</script>
</body>
<footer style="position:fixed;bottom: 0;left: 0;width: 100%;">
<div style="background-color: grey; font-family:sans-serif;">
Made By
<a style="color:rgb(255, 255, 255); font-family:sans-serif;" href="https://github.com/S4nfs">SV</a>
</div>
</footer>
</html>